aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/hooks.ts
diff options
context:
space:
mode:
authorAnurag <anurag4884@gmail.com>2024-02-28 21:13:25 +0530
committerGitHub <noreply@github.com>2024-02-28 10:43:25 -0500
commit2f991e680bea37d1f97ea77df2343200f3899817 (patch)
tree2f043e4aafaa99340b8fac6153f1741d9dbb7ab2 /src/lib/hooks.ts
parent2af066038351ab0634c359a688fe712a539992b4 (diff)
feat: initialise a new totals tab with basic UI (#94)
* feat: initialise a new totals tab with basic UI * fix: update group tabs and add stats page * fix: styling within the new elements * Prettier * Display active user expenses only if active user is set --------- Co-authored-by: Sebastien Castiel <sebastien@castiel.me>
Diffstat (limited to 'src/lib/hooks.ts')
-rw-r--r--src/lib/hooks.ts14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/lib/hooks.ts b/src/lib/hooks.ts
index 4d3ad08..490eccf 100644
--- a/src/lib/hooks.ts
+++ b/src/lib/hooks.ts
@@ -48,3 +48,17 @@ export function useBaseUrl() {
}, [])
return baseUrl
}
+
+/**
+ * @returns The active user, or `null` until it is fetched from local storage
+ */
+export function useActiveUser(groupId: string) {
+ const [activeUser, setActiveUser] = useState<string | null>(null)
+
+ useEffect(() => {
+ const activeUser = localStorage.getItem(`${groupId}-activeUser`)
+ if (activeUser) setActiveUser(activeUser)
+ }, [groupId])
+
+ return activeUser
+}