// The Files page's address-bar keys: the folder shown (`?folder=`, its encoding in // modules/files/filesContext), the file it turns to once (`?item=`), the name search (`?fq=`) and the // sort (`?fsort=`, always written, lib/columnSort's `none` for the list's own order). Here, beside the // other pages' codecs (lib/UrlState), where the URL contract test reads them all. export const FILES_FOLDER_KEY = "folder"; export const FILES_ITEM_KEY = "item"; export const FILES_SEARCH_KEY = "fq"; export const FILES_SORT_KEY = "fsort"; // The file open over the list: in the viewer, or in the player. Each dialog names itself in its own // history entry (ui/Modal's `url`), so Back lands on the list's address without it. export const FILES_VIEW_KEY = "fview"; export const FILES_PLAY_KEY = "fplay"; export const FILES_KEYS = [ FILES_FOLDER_KEY, FILES_ITEM_KEY, FILES_SEARCH_KEY, FILES_SORT_KEY, FILES_VIEW_KEY, FILES_PLAY_KEY, ] as const; export type FilesOpenFile = { open: "view" | "play"; id: number }; /** The address-bar delta for the list (the page's store): its search, folder and the file it turns to * — each null when not named (`null`: the page is not what the address shows). */ export function filesListParams( list: { search: string; folder: string | null; item: number | null } | null, ): Record { return { [FILES_SEARCH_KEY]: list?.search || null, [FILES_FOLDER_KEY]: list?.folder ?? null, [FILES_ITEM_KEY]: list?.item != null ? String(list.item) : null, }; } /** The address-bar delta for the list's sort (lib/columnSort's encoding, `none` included). */ export function filesSortParams(sort: string | null): Record { return { [FILES_SORT_KEY]: sort }; } /** What a file open over the list names in its own entry: the viewer's, or the player's. */ export function filesOpenParams(file: FilesOpenFile): Record { return { [file.open === "play" ? FILES_PLAY_KEY : FILES_VIEW_KEY]: String(file.id) }; } /** The file an address opens over the list (a reload, a bookmark), or null. */ export function openFileFrom(params: URLSearchParams): FilesOpenFile | null { for (const [open, key] of [ ["play", FILES_PLAY_KEY], ["view", FILES_VIEW_KEY], ] as const) { const id = Number(params.get(key)); if (Number.isInteger(id) && id > 0) return { open, id }; } return null; }