diff --git a/src/settings/creator/Containers/dates/years/YearContainer.svelte b/src/settings/creator/Containers/dates/years/YearContainer.svelte index 7816d83..6157aed 100644 --- a/src/settings/creator/Containers/dates/years/YearContainer.svelte +++ b/src/settings/creator/Containers/dates/years/YearContainer.svelte @@ -20,7 +20,7 @@ const calendar = getContext("store"); const plugin = getContext("plugin"); - const { yearStore, staticStore } = calendar; + const { yearStore, staticStore, currentStore } = calendar; const { customYears } = yearStore; const grip = (node: HTMLElement) => { @@ -28,9 +28,18 @@ }; const trash = (node: HTMLElement, item: Year) => { - new ExtraButtonComponent(node) - .setIcon(TRASH) - .onClick(() => yearStore.delete(item.id)); + new ExtraButtonComponent(node).setIcon(TRASH).onClick(() => { + const index = + $yearStore?.findIndex((year) => year.id === item.id) ?? 0; + yearStore.delete(item.id); + if ($yearStore?.length) { + if (index > 0) { + $currentStore.year = index; + } else { + $currentStore.year = 1; + } + } + }); }; const name = (node: HTMLElement, item: Year) => { @@ -150,6 +159,9 @@ { yearStore.add(evt.detail); + if ($yearStore?.length === 1) { + $currentStore.year = 1; + } }} /> {/if} diff --git a/src/settings/creator/Utilities/DateWithValidation.svelte b/src/settings/creator/Utilities/DateWithValidation.svelte index b3d4937..b3af460 100644 --- a/src/settings/creator/Utilities/DateWithValidation.svelte +++ b/src/settings/creator/Utilities/DateWithValidation.svelte @@ -75,7 +75,7 @@ bind:value={$currentStore.year} class:invalid={!$validYear} > - {#each $yearStore?.filter((m) => m && m.name) ?? [] as year, index} + {#each $yearStore?.filter((m) => m && m.name) ?? [] as year, index (year.id)} {/each}