feat: persist sort param in URL for bookmarkability

- Re-added useEffect to ensure sort param is always in URL
- Updated to use lastExecuted as default
- Updated signin tests to expect ?sort=lastExecuted
This commit is contained in:
Nick Tindle
2026-02-01 16:27:38 -06:00
parent b7968a560d
commit c8a267f10d
2 changed files with 9 additions and 3 deletions

View File

@@ -2,7 +2,7 @@
import { LibraryAgentSort } from "@/app/api/__generated__/models/libraryAgentSort";
import { parseAsStringEnum, useQueryState } from "nuqs";
import { useCallback, useMemo, useState } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";
const sortParser = parseAsStringEnum(Object.values(LibraryAgentSort));
@@ -11,6 +11,12 @@ export function useLibraryListPage() {
const [uploadedFile, setUploadedFile] = useState<File | null>(null);
const [librarySortRaw, setLibrarySortRaw] = useQueryState("sort", sortParser);
useEffect(() => {
if (!librarySortRaw) {
setLibrarySortRaw(LibraryAgentSort.lastExecuted, { shallow: false });
}
}, [librarySortRaw, setLibrarySortRaw]);
const librarySort = librarySortRaw || LibraryAgentSort.lastExecuted;
const setLibrarySort = useCallback(

View File

@@ -182,7 +182,7 @@ test("logged in user is redirected from /login to /library", async ({
await hasUrl(page, "/marketplace");
await page.goto("/login");
await hasUrl(page, "/library");
await hasUrl(page, "/library?sort=lastExecuted");
});
test("logged in user is redirected from /signup to /library", async ({
@@ -195,5 +195,5 @@ test("logged in user is redirected from /signup to /library", async ({
await hasUrl(page, "/marketplace");
await page.goto("/signup");
await hasUrl(page, "/library");
await hasUrl(page, "/library?sort=lastExecuted");
});