diff --git a/Foxnouns.Frontend/src/lib/components/ClientPaginator.svelte b/Foxnouns.Frontend/src/lib/components/ClientPaginator.svelte index 7f72ca2..7b08026 100644 --- a/Foxnouns.Frontend/src/lib/components/ClientPaginator.svelte +++ b/Foxnouns.Frontend/src/lib/components/ClientPaginator.svelte @@ -5,8 +5,11 @@ currentPage: number; pageCount: number; center?: boolean; + listAllPages?: boolean; }; - let { currentPage = $bindable(), pageCount, center }: Props = $props(); + let { currentPage = $bindable(), pageCount, center, listAllPages }: Props = $props(); + + let allPages = $derived(listAllPages === undefined || listAllPages); let prevPage = $derived(currentPage > 0 ? currentPage - 1 : 0); let nextPage = $derived(currentPage < pageCount - 1 ? currentPage + 1 : pageCount - 1); @@ -21,11 +24,27 @@ (currentPage = prevPage)} /> - {#each new Array(pageCount) as _, page} - - (currentPage = page)}>{page + 1} + {#if allPages} + {#each new Array(pageCount) as _, page} + + (currentPage = page)}>{page + 1} + + {/each} + {:else} + {#if currentPage !== 0} + (currentPage = prevPage)}> + {currentPage} + + {/if} + + {currentPage + 1} - {/each} + {#if currentPage !== pageCount - 1} + (currentPage = nextPage)}> + {currentPage + 2} + + {/if} + {/if} (currentPage = nextPage)} /> diff --git a/Foxnouns.Frontend/src/lib/components/editor/FlagSearch.svelte b/Foxnouns.Frontend/src/lib/components/editor/FlagSearch.svelte index 78a6c0f..bf7c1f0 100644 --- a/Foxnouns.Frontend/src/lib/components/editor/FlagSearch.svelte +++ b/Foxnouns.Frontend/src/lib/components/editor/FlagSearch.svelte @@ -4,23 +4,35 @@ import Search from "svelte-bootstrap-icons/lib/Search.svelte"; import FlagButton from "./FlagButton.svelte"; import { t } from "$lib/i18n"; + import paginate from "$lib/paginate"; + import ClientPaginator from "$components/ClientPaginator.svelte"; type Props = { flags: PrideFlag[]; select(flag: PrideFlag): void }; let { flags, select }: Props = $props(); + const FLAGS_PER_PAGE = 5; let query = $state(""); let filteredFlags = $derived(search(query)); + let arr: PrideFlag[] = $state([]); + let currentPage = $state(0); + let pageCount = $state(0); + + $effect(() => { + const pages = paginate(filteredFlags, currentPage, FLAGS_PER_PAGE); + arr = pages.data; + pageCount = pages.pageCount; + }); + function search(q: string) { - if (!q) return flags.slice(0, 20); - return flags.filter((f) => f.name.toLowerCase().indexOf(q.toLowerCase()) !== -1).slice(0, 20); + return flags.filter((f) => f.name.toLowerCase().indexOf(q.toLowerCase()) !== -1); }
- {#each filteredFlags as flag (flag.id)} + {#each arr as flag (flag.id)} select(flag)} padding /> {:else}
@@ -36,6 +48,7 @@

{/each} + {#if flags.length > 0}

diff --git a/Foxnouns.Frontend/src/routes/settings/flags/+page.svelte b/Foxnouns.Frontend/src/routes/settings/flags/+page.svelte index 155d014..1b15927 100644 --- a/Foxnouns.Frontend/src/routes/settings/flags/+page.svelte +++ b/Foxnouns.Frontend/src/routes/settings/flags/+page.svelte @@ -13,6 +13,7 @@ import ApiError from "$api/error"; import log from "$lib/log"; import FormStatusMarker from "$components/editor/FormStatusMarker.svelte"; + import Search from "svelte-bootstrap-icons/lib/Search.svelte"; type Props = { data: PageData; form: ActionData }; let { data, form }: Props = $props(); @@ -26,13 +27,17 @@ const FLAGS_PER_PAGE = 50; $effect(() => { - const pages = paginate(flags, currentPage, FLAGS_PER_PAGE); + const filteredFlags = search + ? flags.filter((f) => f.name.toLocaleLowerCase().indexOf(search.toLocaleLowerCase()) !== -1) + : flags; + const pages = paginate(filteredFlags, currentPage, FLAGS_PER_PAGE); arr = pages.data; pageCount = pages.pageCount; }); let lastEditedFlag: string | null = $state(null); let ok: { ok: boolean; error: RawApiError | null } | null = $state(null); + let search: string = $state(""); const update = async ( id: string, @@ -109,20 +114,44 @@ })} - - - - {#each arr as flag (flag.id)} - - - - {flag.name} - - - {#if lastEditedFlag === flag.id}{/if} - - - {/each} - +

+ +
+ + + +{#if arr.length === 0} +
+

+ +

+

+ {#if search} + {$t("editor.flag-search-no-flags")} + {:else} + {$t("editor.flag-search-no-account-flags")} + {/if} +

+
+{:else} + + {#each arr as flag (flag.id)} + + + + {flag.name} + + + {#if lastEditedFlag === flag.id}{/if} + + + {/each} + +{/if}