fix: improve loaded site consistency
This commit is contained in:
1 parent
7484d46d6c
commit
3a965e617d
1 file changed
+14
-7
+14
-7
@@ -91,7 +91,10 @@ export let profileData = writable<ProfileData>(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
let fetchingUser = false
|
let fetchUser = {
|
||||||
|
loading: false,
|
||||||
|
prevProfile: -1
|
||||||
|
}
|
||||||
|
|
||||||
export let profile = derived<Writable<ProfileData>, Profile>(
|
export let profile = derived<Writable<ProfileData>, Profile>(
|
||||||
profileData,
|
profileData,
|
||||||
@@ -100,10 +103,10 @@ 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 && !fetchingUser) {
|
if ((profile.id != fetchUser.prevProfile) && !fetchUser.loading) {
|
||||||
site.set(undefined)
|
site.set(undefined)
|
||||||
|
|
||||||
fetchingUser = true
|
fetchUser.loading = true
|
||||||
|
|
||||||
notifications.set({ applications: 0, inbox: 0, reports: 0 })
|
notifications.set({ applications: 0, inbox: 0, reports: 0 })
|
||||||
|
|
||||||
@@ -120,21 +123,23 @@ export let profile = derived<Writable<ProfileData>, Profile>(
|
|||||||
profile.user = res?.user
|
profile.user = res?.user
|
||||||
profile.avatar = res?.user?.local_user_view.person.avatar
|
profile.avatar = res?.user?.local_user_view.person.avatar
|
||||||
|
|
||||||
|
fetchUser.loading = false
|
||||||
|
fetchUser.prevProfile = profile.id
|
||||||
checkInbox()
|
checkInbox()
|
||||||
|
|
||||||
fetchingUser = false
|
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
fetchingUser = false
|
fetchUser.loading = false
|
||||||
toast({ content: e, type: 'error' })
|
toast({ content: e, type: 'error' })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (browser) {
|
if (browser && !fetchUser.loading) {
|
||||||
site.set(undefined)
|
site.set(undefined)
|
||||||
client({ instanceURL: profile.instance })
|
client({ instanceURL: profile.instance })
|
||||||
.getSite()
|
.getSite()
|
||||||
.then((res) => site.set(res))
|
.then((res) => site.set(res))
|
||||||
|
fetchUser.loading = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,7 +269,9 @@ async function userFromJwt(
|
|||||||
const site = await sitePromise.then((r) => {
|
const site = await sitePromise.then((r) => {
|
||||||
clearTimeout(timer)
|
clearTimeout(timer)
|
||||||
return r
|
return r
|
||||||
})
|
}).catch((e) => { toast({ content: `Failed to load user data. ${e}` }) })
|
||||||
|
|
||||||
|
if (!site) return
|
||||||
|
|
||||||
if (!versionIsSupported(site.version, MINIMUM_VERSION)) {
|
if (!versionIsSupported(site.version, MINIMUM_VERSION)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|||||||
Reference in new issue
Block a user