🥅 Added error-catching to user-view
This commit is contained in:
@@ -34,12 +34,15 @@
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>ClassQuiz - @{data.user.username}</title>
|
||||
<title>ClassQuiz - {data.user.username ? `@${data.user.username}` : 'User not found'}</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="h-full">
|
||||
<div class="grid grid-cols-6 h-full">
|
||||
<div class="pl-2">
|
||||
{#if data.user.username === undefined}
|
||||
<h2 class="text-4xl text-center p-4">User not found</h2>
|
||||
{:else}
|
||||
<div class="flex justify-center">
|
||||
<img src={`/api/v1/users/avatar/${data.user.id}`} alt="profile" />
|
||||
</div>
|
||||
@@ -49,10 +52,14 @@
|
||||
<p class="italic text-center">
|
||||
Joined on {new Date(data.user.created_at).toLocaleDateString()}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
<div
|
||||
class="col-start-2 col-end-7 border-l border-black h-full p-4 overflow-y-scroll flex flex-col gap-4"
|
||||
>
|
||||
{#if data.quizzes.length === 0}
|
||||
<p class="text-center text-4xl">No original quizzes found...</p>
|
||||
{:else}
|
||||
{#each data.quizzes as quiz}
|
||||
<div
|
||||
class="rounded-lg border-2 border-black hover:outline transition-all outline-[#B07156] -outline-offset-2 outline-8"
|
||||
@@ -93,7 +100,9 @@
|
||||
</div>-->
|
||||
</div>
|
||||
<div class="flex justify-center">
|
||||
<a href="/view/{quiz.id}" class="action-button w-1/6">{$t('words.view')}</a>
|
||||
<a href="/view/{quiz.id}" class="action-button w-1/6"
|
||||
>{$t('words.view')}</a
|
||||
>
|
||||
</div>
|
||||
<div class="flex justify-center pb-10 pt-8">
|
||||
<div class="grid grid-cols-2 gap-3 w-1/3">
|
||||
@@ -174,6 +183,7 @@
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -16,7 +16,12 @@ export const load = async ({ params, fetch }) => {
|
||||
};
|
||||
}
|
||||
const quiz_req = await fetch(`/api/v1/community/quizzes/${params.user_id}?imported=false`);
|
||||
const quizzes = await quiz_req.json();
|
||||
let quizzes;
|
||||
if (quiz_req.status === 404) {
|
||||
quizzes = [];
|
||||
} else {
|
||||
quizzes = await quiz_req.json();
|
||||
}
|
||||
return {
|
||||
user,
|
||||
quizzes
|
||||
|
||||
Reference in New Issue
Block a user