Shares Menu nearly feature complete

This commit is contained in:
Mawoka
2023-05-24 19:00:30 +02:00
parent 4b8358176b
commit d5cb5b1ff5
9 changed files with 167 additions and 19 deletions
+1 -1
View File
@@ -29,7 +29,7 @@
{$t('error_page.404_text')}
</p>
{:else}
<p>
<p class="text-center">
{$t('error_page.unknown_error_text')}
</p>
{/if}
@@ -0,0 +1,53 @@
<!--
- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at https://mozilla.org/MPL/2.0/.
-->
<script lang="ts">
import { navbarVisible } from '$lib/stores';
import { page } from '$app/stores';
import { getLocalization } from '$lib/i18n';
navbarVisible.set(true);
let status = $page.status;
const { t } = getLocalization();
</script>
<!--
- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at https://mozilla.org/MPL/2.0/.
-->
<!--
- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at https://mozilla.org/MPL/2.0/.
-->
<svelte:head>
<title>{$t('words.error')} - {status}</title>
</svelte:head>
<h1 class="text-6xl text-center">{status}</h1>
{#if status === 404}
<p class="text-center">
{$t('error_page.404_text')}
</p>
{:else if status === 410}
<p class="text-center">
{$t('quiztivity.share_expired')}
</p>
{:else}
<p class="text-center">
{$t('error_page.unknown_error_text')}
</p>
{/if}
<div class="flex justify-center mt-8">
<img
class="rounded-lg"
src="https://http.cat/{status}"
alt="Cat representing the {status}-http error code"
/>
</div>
+8 -2
View File
@@ -10,12 +10,18 @@ import type { Data } from '$lib/quiztivity/types';
export const load = (async ({ url, fetch }) => {
const id = url.searchParams.get('id');
const share = url.searchParams.get('share') === 'true';
if (!id) {
throw error(400, 'id missing');
}
const resp = await fetch(`/api/v1/quiztivity/${id}`);
let resp: Response;
if (share) {
resp = await fetch(`/api/v1/quiztivity/shares/${id}`);
} else {
resp = await fetch(`/api/v1/quiztivity/${id}`);
}
if (!resp.ok) {
throw error(404, 'quiztivity not found');
throw error(resp.status);
}
const data: Data = await resp.json();
return {
@@ -0,0 +1,14 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
export const load = (({ params }) => {
const quiz_id = params.share_id;
throw redirect(301, `/quiztivity/play?id=${quiz_id}&share=true`);
}) satisfies PageServerLoad;