Fix tag deletion and views update

This commit is contained in:
Brieuc Dubois 2024-01-02 22:33:09 +01:00
parent 29ab752170
commit 9d38545179
5 changed files with 36 additions and 23 deletions

View File

@ -10,10 +10,12 @@
let tagType = getTagTypeFromId(projectTag.type); let tagType = getTagTypeFromId(projectTag.type);
</script> </script>
<td> {#if tagType}
{#if tagType?.hasOptions} <td>
<SelectTags multiple={false} {projectTag} {card} bind:tagValue /> {#if tagType?.hasOptions}
{:else if !tagType?.hasOptions} <SelectTags multiple={false} {projectTag} {card} bind:tagValue />
<input /> {:else if !tagType?.hasOptions}
{/if} <input />
</td> {/if}
</td>
{/if}

View File

@ -79,6 +79,10 @@
} }
tagValue = undefined; tagValue = undefined;
card.tags = card.tags.filter((t) => t.tag_id !== projectTag.id);
cards.reload();
} }
function createOption() { function createOption() {

View File

@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import { get } from 'svelte/store'; import { get } from 'svelte/store';
import type { Project, TagValue, View } from '../../stores/interfaces'; import type { Project, TagValue, View } from '../../stores/interfaces';
import { cards, currentView } from '../../stores/smallStore'; import { cards, currentView, views } from '../../stores/smallStore';
import projectTags from '../../stores/projectTags'; import projectTags from '../../stores/projectTags';
import GroupMenu from './groupMenu.svelte'; import GroupMenu from './groupMenu.svelte';
@ -25,10 +25,16 @@
async function setGroup(id: number): Promise<boolean> { async function setGroup(id: number): Promise<boolean> {
if ($currentView == null) return false; if ($currentView == null) return false;
return await currentView.update({ const view = {
...$currentView, ...$currentView,
primary_tag_id: id primary_tag_id: id
}); };
const res = await views.edit(view);
if (res) currentView.set(view);
return res;
} }
</script> </script>

View File

@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { onMount } from 'svelte'; import { onMount, tick } from 'svelte';
import api, { processError } from '../utils/api'; import api, { processError } from '../utils/api';
import type { Project, View } from '../stores/interfaces'; import type { Project, View } from '../stores/interfaces';
import { currentView, views } from '../stores/smallStore'; import { currentView, views } from '../stores/smallStore';
@ -35,9 +35,10 @@
} }
async function saveView(view: View) { async function saveView(view: View) {
await tick();
if (!view || !$views.includes(view)) return; if (!view || !$views.includes(view)) return;
if (viewEditId === view.id && viewEditValue !== view.title) { if (viewEditId === view.id && viewEditValue !== view.title) {
if (!(await views.update(view))) return; if (!(await views.edit(view))) return;
} }
viewEditId = -1; viewEditId = -1;

View File

@ -10,19 +10,19 @@ export const currentView = (() => {
return { return {
subscribe, subscribe,
set, set
update: async (view: View): Promise<boolean> => { // update: async (view: View): Promise<boolean> => {
const response = await api.put(`/v1/views/${view.id}`, view); // const response = await api.put(`/v1/views/${view.id}`, view);
if (response.status !== status.NoContent) { // if (response.status !== status.NoContent) {
processError(response, 'Failed to update view'); // processError(response, 'Failed to update view');
return false; // return false;
} // }
set(view); // set(view);
return true; // return true;
} // }
}; };
})(); })();
@ -136,6 +136,6 @@ export const views = (() => {
init, init,
add, add,
remove, remove,
update: edit edit
}; };
})(); })();