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
32 changes: 29 additions & 3 deletions apps/admin_dashboard/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type View =
| "audit"
| "configuration"
type SortDirection = "asc" | "desc"
type GigTab = "gigs" | "leads"

type User = {
subject: string
Expand Down Expand Up @@ -666,6 +667,19 @@ function detailIdFromPath(expectedView: "gigs" | "projects" = "gigs") {
}
}

function gigTabFromHash(hash = window.location.hash): GigTab {
return hash.replace(/^#/, "") === "leads" ? "leads" : "gigs"
}

function updateGigTabHash(tab: GigTab) {
const hash = tab === "leads" ? "#leads" : "#gigs"
window.history.replaceState(
window.history.state,
"",
`${window.location.pathname}${window.location.search}${hash}`,
)
}

async function requestJson<T>(url: string, options: RequestInit = {}): Promise<T> {
const method = String(options.method || "GET").toUpperCase()
const headers = new Headers(options.headers)
Expand Down Expand Up @@ -908,7 +922,7 @@ function App() {
const [gigQuery, setGigQuery] = useState("")
const [gigIncludeHistorical, setGigIncludeHistorical] = useState(false)
const [gigLimit, setGigLimit] = useState(100)
const [activeGigTab, setActiveGigTab] = useState<"gigs" | "leads">("gigs")
const [activeGigTab, setActiveGigTab] = useState<GigTab>(gigTabFromHash)
const [gigLeadStatus, setGigLeadStatus] = useState("pending")
const [projectQuery, setProjectQuery] = useState("")
const [projectStatus, setProjectStatus] = useState(initialProjectDetailId ? "" : "Open")
Expand Down Expand Up @@ -975,6 +989,7 @@ function App() {
if (normalized !== "projects") setSelectedProjectId("")
if (normalized === "gigs" && push) setSelectedGigId("")
if (normalized === "projects" && push) setSelectedProjectId("")
if (normalized === "gigs") setActiveGigTab(push ? "gigs" : gigTabFromHash())
setViewState(normalized)
if (push) {
window.history.pushState({ view: normalized }, "", routes[normalized])
Expand All @@ -984,6 +999,11 @@ function App() {
}
navigateRef.current = navigate

function selectGigTab(tab: GigTab) {
setActiveGigTab(tab)
updateGigTabHash(tab)
}

function crmContactUrl(contactId?: string) {
if (!crmBaseUrl || !contactId) return ""
return `${crmBaseUrl}/#Contact/view/${encodeURIComponent(contactId)}`
Expand Down Expand Up @@ -1717,7 +1737,7 @@ function App() {
},
)
showToast("Posted lead to Discord", "ok")
setActiveGigTab("gigs")
selectGigTab("gigs")
setGigStatus("")
setGigQuery("")
await loadGigLeads()
Expand Down Expand Up @@ -2344,6 +2364,12 @@ function App() {
return () => window.removeEventListener("popstate", onPopState)
}, [])

useEffect(() => {
const onHashChange = () => setActiveGigTab(gigTabFromHash())
window.addEventListener("hashchange", onHashChange)
Comment on lines +2368 to +2369

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep tab state in sync when routes clear the hash

When a user is on /dashboard/gigs#leads, navigates to another dashboard view, and then returns to Gigs via the sidebar, navigate() clears the hash with history.pushState(...); pushState does not dispatch a hashchange event, so this listener never resets activeGigTab. The page can therefore render the Leads tab at /dashboard/gigs, and refreshing or sharing that visible URL flips back to the Gigs tab instead of preserving the current state.

Useful? React with 👍 / 👎.

return () => window.removeEventListener("hashchange", onHashChange)
}, [])

useEffect(() => {
if (!toast.message) return undefined
const timeout = window.setTimeout(() => setToast({ message: "" }), 4500)
Expand Down Expand Up @@ -2776,7 +2802,7 @@ function App() {
canIncludeHistorical={can("people:read")}
crmContactUrl={crmContactUrl}
crmAttachmentUrl={crmAttachmentUrl}
setActiveTab={setActiveGigTab}
setActiveTab={selectGigTab}
setStatus={setGigStatus}
setQuery={setGigQuery}
setLeadStatus={setGigLeadStatus}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"index.html": {
"file": "assets/index-LL0oAOC_.js",
"file": "assets/index-_nigGMGP.js",
"name": "index",
"src": "index.html",
"isEntry": true,
Expand Down

This file was deleted.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/api/src/five08/backend/static/dashboard/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>508 Operations Dashboard</title>
<script type="module" crossorigin src="/dashboard/assets/index-LL0oAOC_.js"></script>
<script type="module" crossorigin src="/dashboard/assets/index-_nigGMGP.js"></script>
<link rel="stylesheet" crossorigin href="/dashboard/assets/index-2UypYUrJ.css">
</head>
<body>
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/test_dashboard_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,15 @@ def sync_route(route: Any) -> None:
"status=" not in urlparse(url).query for url in gig_list_requests
)
page.locator("#gigLeadsTab").click()
expect(page).to_have_url(f"{dashboard_server}/dashboard/gigs#leads")
page.reload()
page.get_by_text("Contract React Build").wait_for()
page.get_by_role("link", name="People").click()
expect(page).to_have_url(f"{dashboard_server}/dashboard/people")
page.get_by_role("link", name="Gigs").click()
expect(page).to_have_url(f"{dashboard_server}/dashboard/gigs")
expect(page.locator("#gigsTab")).to_have_attribute("aria-pressed", "true")
page.locator("#gigLeadsTab").click()
expect(
page.get_by_text("Full-time or part-time / contract · LLM")
).to_be_visible()
Expand Down