Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions apps/web/src/routes/app/lists/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
const canEditList = $derived(role === "OWNER" || role === "EDITOR");
const isOwner = $derived(role === "OWNER");
let removingId = $state<string | null>(null);
let reordering = $state(false);

Check warning on line 93 in apps/web/src/routes/app/lists/[id]/+page.svelte

View check run for this annotation

Codecov / codecov/patch

apps/web/src/routes/app/lists/[id]/+page.svelte#L93

Added line #L93 was not covered by tests

// Local, reorderable copy of the items — svelte-dnd-action mutates this
// directly during a drag; resets to the query's own items whenever those
Expand Down Expand Up @@ -150,23 +151,27 @@

async function handleDndFinalize(e: CustomEvent<{ items: ListItemDto[] }>) {
dragItems = e.detail.items;
if (!list) return;
if (!list || reordering) return;
const listId = list.id;
const expectedUpdatedAt = list.updatedAt;
reordering = true;

Check warning on line 157 in apps/web/src/routes/app/lists/[id]/+page.svelte

View check run for this annotation

Codecov / codecov/patch

apps/web/src/routes/app/lists/[id]/+page.svelte#L157

Added line #L157 was not covered by tests
patchList({ items: dragItems });
try {
await reorderListItems(
listId,
dragItems.map((i) => i.id),
expectedUpdatedAt,
);
await queryClient.refetchQueries({ queryKey: detailKey });

Check warning on line 165 in apps/web/src/routes/app/lists/[id]/+page.svelte

View check run for this annotation

Codecov / codecov/patch

apps/web/src/routes/app/lists/[id]/+page.svelte#L165

Added line #L165 was not covered by tests
} catch (err) {
if (err instanceof ApiError && err.status === 409) {
conflictNotice = true;
void queryClient.refetchQueries({ queryKey: detailKey });
await queryClient.refetchQueries({ queryKey: detailKey });

Check warning on line 169 in apps/web/src/routes/app/lists/[id]/+page.svelte

View check run for this annotation

Codecov / codecov/patch

apps/web/src/routes/app/lists/[id]/+page.svelte#L169

Added line #L169 was not covered by tests
return;
}
throw err;
} finally {
reordering = false;

Check warning on line 174 in apps/web/src/routes/app/lists/[id]/+page.svelte

View check run for this annotation

Codecov / codecov/patch

apps/web/src/routes/app/lists/[id]/+page.svelte#L174

Added line #L174 was not covered by tests
}
}

Expand Down Expand Up @@ -300,7 +305,7 @@
class="mt-6 flex flex-col gap-2"
use:dndzone={{
items: dragItems,
dragDisabled: !canEditList,
dragDisabled: !canEditList || reordering,
flipDurationMs: 150,
}}
onconsider={handleDndConsider}
Expand Down
15 changes: 15 additions & 0 deletions apps/web/src/routes/app/lists/lists.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";

const source = readFileSync(
new URL("./[id]/+page.svelte", import.meta.url),
"utf8",
);

describe("list reordering", () => {
it("refreshes the optimistic-lock timestamp after a successful reorder", () => {
expect(source).toMatch(
/await reorderListItems\([\s\S]*?\);\s*await queryClient\.refetchQueries\(\{ queryKey: detailKey \}\);/,
);
});
});
Loading