From 9e6531a7d30000b0b0f8f71b8c9bf82d43d420e7 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 1 Feb 2024 05:34:07 -0800 Subject: feat(user): error alert --- src/routes/user/[user]/+page.svelte | 166 +++++++++++++++++++++--------------- 1 file changed, 95 insertions(+), 71 deletions(-) (limited to 'src/routes') diff --git a/src/routes/user/[user]/+page.svelte b/src/routes/user/[user]/+page.svelte index 761ba1ee..5ac09aa6 100644 --- a/src/routes/user/[user]/+page.svelte +++ b/src/routes/user/[user]/+page.svelte @@ -13,6 +13,7 @@ export let data; let userData: User | undefined = undefined; + let error = false; $: displayBadges = (username: string, badges: number | string) => $locale({ @@ -23,9 +24,9 @@ }).user.profile.badges; onMount(() => { - user(data.username).then((profile) => { - userData = profile; - }); + user(data.username) + .then((profile) => (userData = profile)) + .catch(() => (error = true)); }); // 8.5827814569536423841e0 @@ -33,87 +34,110 @@ -
- {#if userData === null} - Could not load user profile for @{data.username}. - -

- - Does this user exist? - {:else if userData === undefined} - - - - {:else} -

- {#if userData} - - {/if} - -
-
- - - -
- -
-

+{#if error} +

+{:else} +
+ {#if userData === null} + Could not load user profile for @{data.username}. + +

+ + Does this user exist? + {:else if userData === undefined} + + + + {:else} +

+ {#if userData} + + {/if} + +
+
- @{userData.name} + - {#if userData && authorisedUsers.includes(userData.id)} - ‌ - - {/if} - - Badge Wall -

- - {$locale({ - values: { - username: data.username, - anime: (userData.statistics.anime.minutesWatched / 60 / 24).toFixed(1), - manga: estimatedDayReading(userData.statistics.manga.chaptersRead).toFixed(1) - } - }).user.profile.statistics} - -

- - {#await fetch(root(`/api/badges?id=${userData.id}`))} - {displayBadges(userData.name, '...')} - {:then badges} - {#await badges.json()} +

+ +
+

+ + @{userData.name} + + {#if userData && authorisedUsers.includes(userData.id)} + ‌ + + {/if} + + Badge Wall +

+ + {$locale({ + values: { + username: data.username, + anime: (userData.statistics.anime.minutesWatched / 60 / 24).toFixed(1), + manga: estimatedDayReading(userData.statistics.manga.chaptersRead).toFixed(1) + } + }).user.profile.statistics} + +

+ + {#await fetch(root(`/api/badges?id=${userData.id}`))} {displayBadges(userData.name, '...')} {:then badges} - {displayBadges(userData.name, badges.length)} + {#await badges.json()} + {displayBadges(userData.name, '...')} + {:then badges} + {displayBadges(userData.name, badges.length)} + {:catch} + {displayBadges(userData.name, '?')} + {/await} {:catch} {displayBadges(userData.name, '?')} {/await} - {:catch} - {displayBadges(userData.name, '?')} - {/await} +

-
- {/if} -
+ {/if} +
+{/if}