diff --git a/src/lib/components/chat/Placeholder/FolderStatusesModal.svelte b/src/lib/components/chat/Placeholder/FolderStatusesModal.svelte index 2d653ae924..ee434dcf28 100644 --- a/src/lib/components/chat/Placeholder/FolderStatusesModal.svelte +++ b/src/lib/components/chat/Placeholder/FolderStatusesModal.svelte @@ -2,11 +2,13 @@ import { getContext, tick } from 'svelte'; import { toast } from 'svelte-sonner'; import { + NO_STATUS, newStatusId, statusGlyphs, suggestedStatuses, type CustomStatus, - type StatusDef + type StatusDef, + type StatusEntry } from '$lib/utils/folders'; import { colorDot, tagColors } from '$lib/utils/tags'; import Modal from '$lib/components/common/Modal.svelte'; @@ -22,8 +24,9 @@ const i18n = getContext('i18n'); export let show = false; + /** In board order, "No status" included. */ export let statuses: StatusDef[] = []; - export let onSave: (statuses: CustomStatus[]) => Promise; + export let onSave: (statuses: StatusEntry[]) => Promise; let draft: CustomStatus[] = []; let saving = false; @@ -39,20 +42,31 @@ done: 'Done' }; - // Start a fresh draft each time the modal opens. + // Start a fresh draft each time the modal opens. "No status" rides along so it can be moved. $: { if (show && !wasOpen) - draft = statuses - .filter((item) => item.custom) - .map(({ id, name, glyph, color, icon }) => ({ id, name, glyph, color, icon })); + draft = statuses.map(({ id, name, glyph, color, icon }) => ({ + id, + name, + glyph, + color, + icon + })); wasOpen = show; } const update = (id: string, patch: Partial) => (draft = draft.map((item) => (item.id === id ? { ...item, ...patch } : item))); + // New statuses go before a trailing "No status", where they'd land without a saved position. + const append = (item: CustomStatus) => + (draft = + draft.at(-1)?.id === NO_STATUS + ? [...draft.slice(0, -1), item, draft.at(-1)!] + : [...draft, item]); + async function add() { - draft = [...draft, { id: newStatusId(), name: '', glyph: 'todo', color: 'gray' }]; + append({ id: newStatusId(), name: '', glyph: 'todo', color: 'gray' }); await tick(); [...(list?.querySelectorAll('input[data-status-name]') ?? [])] .at(-1) @@ -69,8 +83,7 @@ !draft.some((entry) => entry.name.trim().toLowerCase() === item.name.toLowerCase()) ); - const addSuggestion = (item: CustomStatus) => - (draft = [...draft, { ...item, id: newStatusId() }]); + const addSuggestion = (item: CustomStatus) => append({ ...item, id: newStatusId() }); function reorder(overId: string) { if (!dragId || dragId === overId) return; @@ -86,7 +99,9 @@ const cleaned = draft .map((item) => ({ ...item, name: item.name.trim() })) .filter((item) => item.name); - const names = cleaned.map((item) => item.name.toLowerCase()); + const names = cleaned + .filter((item) => item.id !== NO_STATUS) + .map((item) => item.name.toLowerCase()); if ( new Set(names).size !== names.length || names.includes($i18n.t('No status').toLowerCase()) @@ -96,7 +111,7 @@ } saving = true; try { - await onSave(cleaned); + await onSave(cleaned.map((item) => (item.id === NO_STATUS ? { id: NO_STATUS } : item))); show = false; } catch (error) { toast.error(String(error)); @@ -119,13 +134,6 @@
-
- - - {$i18n.t('No status')} - {$i18n.t('Default')} -
- {#each draft as item (item.id)}
- + {#if item.id === NO_STATUS} + + {item.name} + {$i18n.t('Default')} + {:else} + + + +
+ {$i18n.t('Icon')} +
+
+ {#each statusGlyphs as glyph} + + {/each} +
+
+ {$i18n.t('Color')} +
+
+ {#each tagColors as color} + + {/each} +
+
+ update(item.id, { icon: icon ?? undefined })} + > + + +
+
+ + update(item.id, { name: event.currentTarget.value })} + /> - - - -
- {$i18n.t('Icon')} -
-
- {#each statusGlyphs as glyph} - - {/each} -
-
- {$i18n.t('Color')} -
-
- {#each tagColors as color} - - {/each} -
-
- update(item.id, { icon: icon ?? undefined })} - > - - -
-
- - update(item.id, { name: event.currentTarget.value })} - /> - + {/if}
{/each}