Skip to content

Commit 16af636

Browse files
authored
Merge pull request #43 from primev/leaderboard
Swap Leaderboard
2 parents 6b39182 + 6f2770d commit 16af636

43 files changed

Lines changed: 3558 additions & 1108 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"use client"
2+
3+
import { createContext, useContext, useState, useEffect, ReactNode } from "react"
4+
import { useSearchParams, useRouter } from "next/navigation"
5+
6+
interface DashboardTabContextType {
7+
activeTab: string
8+
setActiveTab: (value: string) => void
9+
}
10+
11+
const DashboardTabContext = createContext<DashboardTabContextType | undefined>(undefined)
12+
13+
export function DashboardTabProvider({ children }: { children: ReactNode }) {
14+
const searchParams = useSearchParams()
15+
const router = useRouter()
16+
const [activeTab, setActiveTabState] = useState("genesis")
17+
18+
// Read from URL on mount
19+
useEffect(() => {
20+
const tab = searchParams.get("tab")
21+
if (tab && ["genesis", "points"].includes(tab)) {
22+
setActiveTabState(tab)
23+
}
24+
}, [searchParams])
25+
26+
const setActiveTab = (value: string) => {
27+
setActiveTabState(value)
28+
router.push(`/dashboard?tab=${value}`)
29+
}
30+
31+
return (
32+
<DashboardTabContext.Provider value={{ activeTab, setActiveTab }}>
33+
{children}
34+
</DashboardTabContext.Provider>
35+
)
36+
}
37+
38+
export function useDashboardTab() {
39+
const context = useContext(DashboardTabContext)
40+
// Return default values if not in provider (for non-dashboard pages)
41+
if (context === undefined) {
42+
return { activeTab: "genesis", setActiveTab: () => {} }
43+
}
44+
return context
45+
}

0 commit comments

Comments
 (0)