Skip to content

Commit

Permalink
fix: Added "Delete filtered creatures" button to Bestiary in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Apr 15, 2024
1 parent 7cc3e4b commit ea238e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/settings/creatures/Creatures.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import type { Monster } from "index";
import { derived, writable } from "svelte/store";
import { onDestroy } from "svelte";
import { confirmWithModal } from "src/view/statblock";
export let plugin: StatBlockPlugin;
Expand Down Expand Up @@ -59,6 +60,18 @@
}
);
const remove = async () => {
if (!$filtered.length) return;
if (
await confirmWithModal(
plugin.app,
`Are you sure you want to delete ${$filtered.length} creature${$filtered.length === 1 ? "" : "s"}?`
)
) {
Bestiary.removeCreatures(...$filtered.map((f) => f.name));
}
};
const pages = derived([slice, filtered], ([slice, filtered]) =>
Math.ceil(filtered.length / slice)
);
Expand All @@ -75,7 +88,7 @@
class="filters-container"
style="background-color: {backgroundColor}; top: -{paddingTop};"
>
<Filters />
<Filters on:remove={() => remove()} />
<div class="setting-item-description">
{$filtered.length ? $filtered.length : "No"} creature{$filtered.length ===
1
Expand Down
11 changes: 11 additions & 0 deletions src/settings/creatures/filters/Filters.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import { linear } from "svelte/easing";
import { Bestiary } from "src/bestiary/bestiary";
import { writable } from "svelte/store";
import { createEventDispatcher } from "svelte";
const sources = writable([...Bestiary.getIndex("source").keys()]);
const dispatch = createEventDispatcher<{ remove: void }>();
Bestiary.onIndexUpdated(
"source",
() => ($sources = [...Bestiary.getIndex("source").keys()])
Expand All @@ -18,6 +21,9 @@
const resetIcon = (node: HTMLElement) => {
new ExtraButtonComponent(node).setIcon("reset");
};
const deleteIcon = (node: HTMLElement) => {
new ExtraButtonComponent(node).setIcon("trash");
};
const filter = (node: HTMLElement) => {
new ExtraButtonComponent(node).setIcon("filter");
};
Expand All @@ -36,6 +42,11 @@
</div>

<div use:resetIcon on:click={() => reset()} />
<div
use:deleteIcon
on:click={() => dispatch("remove")}
aria-label="Delete filtered creatures"
/>
</div>
{#if open}
<div class="filters" transition:slide={{ easing: linear }}>
Expand Down

0 comments on commit ea238e3

Please sign in to comment.