diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 0105f0ce..7c29dbc0 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -58,12 +58,12 @@ interface ProfileData { defaultInstance?: string } -interface PersonData extends MyUserInfo { - notifications: { - inbox: number - reports: number - applications: number - } +interface PersonData extends MyUserInfo {} + +interface Notifications { + inbox: number + reports: number + applications: number } const getCookie = (key: string): string | undefined => { @@ -99,7 +99,7 @@ export let profile = derived, Profile>( pd.profiles.find((p) => p.id == pd.profile) ?? getDefaultProfile() if (profile?.jwt) { - if (profile.user) { + if (!profile.user) { site.set(undefined) userFromJwt(profile.jwt, profile.instance).then((res) => { @@ -127,6 +127,12 @@ export let profile = derived, Profile>( } ) +export let notifications = writable({ + applications: 0, + inbox: 0, + reports: 0, +}) + profileData.subscribe(async (pd) => { const serialized: ProfileData = { ...pd, @@ -254,14 +260,7 @@ async function userFromJwt( if (!myUser) return undefined return { - user: { - notifications: { - applications: 0, - inbox: 0, - reports: 0, - }, - ...myUser, - }, + user: myUser, site: site, } } @@ -373,11 +372,11 @@ async function checkInbox() { isAdmin(user) ) - user.notifications = { + notifications.set({ inbox: notifs.unreads, applications: notifs.applications, reports: notifs.reports, - } + }) } setInterval(checkInbox, 4 * 60 * 1000) diff --git a/src/lib/components/ui/navbar/Navbar.svelte b/src/lib/components/ui/navbar/Navbar.svelte index 8f3a3ed8..ff59e52c 100644 --- a/src/lib/components/ui/navbar/Navbar.svelte +++ b/src/lib/components/ui/navbar/Navbar.svelte @@ -1,5 +1,5 @@ -{#if ($profile?.user?.notifications.applications ?? 0) > 0} +{#if $notifications.applications > 0} - {$profile?.user?.notifications.applications} + {$notifications.applications} unread applications {/if} diff --git a/src/routes/admin/applications/Application.svelte b/src/routes/admin/applications/Application.svelte index 23fe63f3..63be6a36 100644 --- a/src/routes/admin/applications/Application.svelte +++ b/src/routes/admin/applications/Application.svelte @@ -1,5 +1,5 @@