fix: double load
This commit is contained in:
1 parent
1376549652
commit
09eb3b80c2
1 file changed
+15
-2
+15
-2
@@ -92,6 +92,8 @@ export let profileData = writable<ProfileData>(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let fetchingUser = false
|
||||||
|
|
||||||
export let profile = derived<Writable<ProfileData>, Profile>(
|
export let profile = derived<Writable<ProfileData>, Profile>(
|
||||||
profileData,
|
profileData,
|
||||||
(pd) => {
|
(pd) => {
|
||||||
@@ -99,10 +101,15 @@ export let profile = derived<Writable<ProfileData>, Profile>(
|
|||||||
pd.profiles.find((p) => p.id == pd.profile) ?? getDefaultProfile()
|
pd.profiles.find((p) => p.id == pd.profile) ?? getDefaultProfile()
|
||||||
|
|
||||||
if (profile?.jwt) {
|
if (profile?.jwt) {
|
||||||
if (!profile.user) {
|
if (!profile.user && !fetchingUser) {
|
||||||
site.set(undefined)
|
site.set(undefined)
|
||||||
|
|
||||||
userFromJwt(profile.jwt, profile.instance).then((res) => {
|
fetchingUser = true
|
||||||
|
|
||||||
|
notifications.set({ applications: 0, inbox: 0, reports: 0 })
|
||||||
|
|
||||||
|
userFromJwt(profile.jwt, profile.instance)
|
||||||
|
.then((res) => {
|
||||||
if (!res?.user)
|
if (!res?.user)
|
||||||
toast({
|
toast({
|
||||||
content: 'Your login has expired. Re-login to fix this issue.',
|
content: 'Your login has expired. Re-login to fix this issue.',
|
||||||
@@ -115,6 +122,12 @@ export let profile = derived<Writable<ProfileData>, Profile>(
|
|||||||
profile.avatar = res?.user.local_user_view.person.avatar
|
profile.avatar = res?.user.local_user_view.person.avatar
|
||||||
|
|
||||||
checkInbox()
|
checkInbox()
|
||||||
|
|
||||||
|
fetchingUser = false
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
fetchingUser = false
|
||||||
|
toast({ content: e, type: 'error' })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in new issue
Block a user