/** * @file settingsLink — where a Settings link opens. On a workspace (the * Workspace page with `?lane=`) it is that page's Settings tab * (`?settings=
`, keeping `lane` and `run`), so the terminals and chats * stay mounted behind it; anywhere else it is the Settings page * (`/settings/
`). A path is what the page takes after `/settings/`: * `
[?query][#anchor]`, `""` for the default section. * @author Nguyễn Ngọc Trí Vĩ */ import { useLocation } from "react-router-dom"; export function settingsHref(path: string, at: { pathname: string; search: string }): string { const [rest = "", anchor = ""] = path.split("#"); const [section = "", query = ""] = rest.split("?"); const hash = anchor ? `#${anchor}` : ""; const here = new URLSearchParams(at.search); const lane = here.get("lane"); if (at.pathname !== "/workspace" || !lane) { return `/settings${section ? `/${section}` : ""}${query ? `?${query}` : ""}${hash}`; } // A section's own query (a sub-tab) and the session replay do not carry over. const next = new URLSearchParams({ lane }); const run = here.get("run"); if (run) next.set("run", run); next.set("settings", section); for (const [k, v] of new URLSearchParams(query)) next.set(k, v); return `/workspace?${next}${hash}`; } /** `settingsHref` from the current location. */ export function useSettingsHref(): (path: string) => string { const location = useLocation(); return (path) => settingsHref(path, location); }