1
0
mirror of https://github.com/pocket-id/pocket-id.git synced 2026-02-15 17:30:04 +00:00

fix: list items on previous page get unselected if other items selected on next page

This commit is contained in:
Elias Schneider
2025-09-09 10:02:43 +02:00
parent 42155238b7
commit 6c696b46c8

View File

@@ -5,13 +5,13 @@
import * as Select from '$lib/components/ui/select'; import * as Select from '$lib/components/ui/select';
import * as Table from '$lib/components/ui/table/index.js'; import * as Table from '$lib/components/ui/table/index.js';
import Empty from '$lib/icons/empty.svelte'; import Empty from '$lib/icons/empty.svelte';
import { m } from '$lib/paraglide/messages';
import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type'; import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type';
import { debounced } from '$lib/utils/debounce-util'; import { debounced } from '$lib/utils/debounce-util';
import { cn } from '$lib/utils/style'; import { cn } from '$lib/utils/style';
import { ChevronDown } from '@lucide/svelte'; import { ChevronDown } from '@lucide/svelte';
import type { Snippet } from 'svelte'; import type { Snippet } from 'svelte';
import Button from './ui/button/button.svelte'; import Button from './ui/button/button.svelte';
import { m } from '$lib/paraglide/messages';
let { let {
items, items,
@@ -53,19 +53,22 @@
}, 300); }, 300);
async function onAllCheck(checked: boolean) { async function onAllCheck(checked: boolean) {
const pageIds = items.data.map((item) => item.id);
const current = selectedIds ?? [];
if (checked) { if (checked) {
selectedIds = items.data.map((item) => item.id); selectedIds = Array.from(new Set([...current, ...pageIds]));
} else { } else {
selectedIds = []; selectedIds = current.filter((id) => !pageIds.includes(id));
} }
} }
async function onCheck(checked: boolean, id: string) { async function onCheck(checked: boolean, id: string) {
if (!selectedIds) return; const current = selectedIds ?? [];
if (checked) { if (checked) {
selectedIds = [...selectedIds, id]; selectedIds = Array.from(new Set([...current, id]));
} else { } else {
selectedIds = selectedIds.filter((selectedId) => selectedId !== id); selectedIds = current.filter((selectedId) => selectedId !== id);
} }
} }