Skip to content

Commit

Permalink
fix: Improves user experience around custom years
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Mar 15, 2024
1 parent 4c38479 commit fb6fa21
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/settings/creator/Containers/dates/years/YearContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,26 @@
const calendar = getContext("store");
const plugin = getContext("plugin");
const { yearStore, staticStore } = calendar;
const { yearStore, staticStore, currentStore } = calendar;
const { customYears } = yearStore;
const grip = (node: HTMLElement) => {
setIcon(node, GRIP);
};
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) => {
Expand Down Expand Up @@ -150,6 +159,9 @@
<AddNew
on:add={(evt) => {
yearStore.add(evt.detail);
if ($yearStore?.length === 1) {
$currentStore.year = 1;
}
}}
/>
{/if}
Expand Down
2 changes: 1 addition & 1 deletion src/settings/creator/Utilities/DateWithValidation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
<option value={index + 1}>{year.name}</option>
{/each}
</select>
Expand Down

0 comments on commit fb6fa21

Please sign in to comment.