⬆️ Finished upgrading SvelteKit

This commit is contained in:
Mawoka
2022-08-18 16:22:44 +02:00
parent a3b015ffca
commit cacd727c0e
21 changed files with 60 additions and 268 deletions
-4
View File
@@ -14,10 +14,6 @@ declare namespace App {
} }
// interface Platform {} // interface Platform {}
interface Session {
authenticated: boolean;
email: string | null;
}
// interface Stuff {} // interface Stuff {}
} }
+3 -3
View File
@@ -5,7 +5,7 @@
*/ */
import * as cookie from 'cookie'; import * as cookie from 'cookie';
import type { Handle, GetSession } from '@sveltejs/kit'; import type { Handle } from '@sveltejs/kit';
/** @type {import('@sveltejs/kit').Handle} */ /** @type {import('@sveltejs/kit').Handle} */
export const handle: Handle = async ({ event, resolve }) => { export const handle: Handle = async ({ event, resolve }) => {
@@ -54,9 +54,9 @@ export const handle: Handle = async ({ event, resolve }) => {
} }
}; };
export const getSession: GetSession = async (event) => { /*export const getSession: GetSession = async (event) => {
return { return {
email: event.locals.email, email: event.locals.email,
authenticated: Boolean(event.locals.email) authenticated: Boolean(event.locals.email)
}; };
}; };*/
+3 -17
View File
@@ -3,26 +3,12 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this - 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/. - file, You can obtain one at https://mozilla.org/MPL/2.0/.
--> -->
<script context="module">
throw new Error(
'@migration task: Replace error load function (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3293209)'
);
// /** @type {import('@sveltejs/kit').Load} */ export function load({ error, status }) {
// return {
// props: {
// status,
// message: error.message
// }
// };
// }
</script>
<script lang="ts"> <script lang="ts">
import { navbarVisible } from '$lib/stores'; import { navbarVisible } from '$lib/stores';
import { page } from '$app/stores';
navbarVisible.set(true); navbarVisible.set(true);
export let status: number; let status = $page.status;
export let message: string;
</script> </script>
<!-- <!--
+13
View File
@@ -0,0 +1,13 @@
import { signedIn } from '$lib/stores';
import type { LayoutLoad } from './$types';
export const load: LayoutLoad = async ({ locals }) => {
if (locals.email) {
signedIn.set(true);
} else {
signedIn.set(false);
}
return {
email: locals.email
};
};
-15
View File
@@ -3,21 +3,6 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this - 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/. - file, You can obtain one at https://mozilla.org/MPL/2.0/.
--> -->
<script context="module" lang="ts">
throw new Error(
'@migration task: Check code was safely removed (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292722)'
);
// import { signedIn } from '$lib/stores';
// export async function load({ session }) {
// if (session.authenticated) {
// signedIn.set(true);
// }
// return {};
// }
</script>
<script> <script>
import '../app.css'; import '../app.css';
import Navbar from '$lib/navbar.svelte'; import Navbar from '$lib/navbar.svelte';
+7 -3
View File
@@ -1,10 +1,14 @@
// import { redirect } from '@sveltejs/kit';
import { signedIn } from '$lib/stores'; import { signedIn } from '$lib/stores';
import type { LayoutLoad } from './$types';
export async function load({ session }) { export const load: LayoutLoad = async ({ data }) => {
if (session.authenticated) { const { email } = data;
if (email) {
signedIn.set(true); signedIn.set(true);
// throw redirect(302, '/dashboard');
} else { } else {
signedIn.set(false); signedIn.set(false);
} }
return {}; return {};
} };
-12
View File
@@ -1,12 +0,0 @@
// import { redirect } from '@sveltejs/kit';
import { signedIn } from '$lib/stores';
export async function load({ session }) {
if (session.authenticated) {
signedIn.set(true);
// throw redirect(302, '/dashboard');
} else {
signedIn.set(false);
}
return {};
}
@@ -3,21 +3,6 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this - 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/. - file, You can obtain one at https://mozilla.org/MPL/2.0/.
--> -->
<script lang="ts" context="module">
throw new Error(
'@migration task: Check code was safely removed (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292722)'
);
// import { signedIn } from '$lib/stores';
// export async function load({ session }) {
// if (session.authenticated) {
// signedIn.set(true);
// }
// return {};
// }
</script>
<script lang="ts"> <script lang="ts">
import { navbarVisible } from '$lib/stores'; import { navbarVisible } from '$lib/stores';
@@ -4,10 +4,6 @@
- file, You can obtain one at https://mozilla.org/MPL/2.0/. - file, You can obtain one at https://mozilla.org/MPL/2.0/.
--> -->
<script lang="ts"> <script lang="ts">
throw new Error(
'@migration task: Add data prop (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292707)'
);
import * as Sentry from '@sentry/browser'; import * as Sentry from '@sentry/browser';
import { navbarVisible } from '$lib/stores'; import { navbarVisible } from '$lib/stores';
import { browser } from '$app/env'; import { browser } from '$app/env';
@@ -20,7 +16,8 @@
navbarVisible.set(true); navbarVisible.set(true);
export let verified: boolean; export let data;
const { verified }: boolean = data;
let loginData = { let loginData = {
email: '', email: '',
+4 -2
View File
@@ -1,10 +1,12 @@
import { redirect } from '@sveltejs/kit'; import { redirect } from '@sveltejs/kit';
export async function load({ session, url }) { export async function load({ parent, url }) {
const verified = url.searchParams.get('verified'); const verified = url.searchParams.get('verified');
const returnTo = const returnTo =
url.searchParams.get('returnTo') !== null ? url.searchParams.get('returnTo') : '/dashboard'; url.searchParams.get('returnTo') !== null ? url.searchParams.get('returnTo') : '/dashboard';
if (session.authenticated) {
const { email } = await parent();
if (email) {
throw redirect(302, returnTo); throw redirect(302, returnTo);
} }
return { return {
@@ -4,11 +4,8 @@
- file, You can obtain one at https://mozilla.org/MPL/2.0/. - file, You can obtain one at https://mozilla.org/MPL/2.0/.
--> -->
<script lang="ts"> <script lang="ts">
throw new Error( export let data;
'@migration task: Add data prop (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292707)' const { error } = data;
);
export let error: string;
</script> </script>
<div> <div>
@@ -4,14 +4,11 @@
- file, You can obtain one at https://mozilla.org/MPL/2.0/. - file, You can obtain one at https://mozilla.org/MPL/2.0/.
--> -->
<script lang="ts"> <script lang="ts">
throw new Error( import { getLocalization } from '$lib/i18n';
'@migration task: Add data prop (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292707)'
);
import { getLocalization } from '../../../lib/i18n';
const { t } = getLocalization(); const { t } = getLocalization();
export let token: string; export let data;
let { token }: string = data;
let isSubmitting = false; let isSubmitting = false;
interface PasswordData { interface PasswordData {
password1: string; password1: string;
+9 -14
View File
@@ -4,10 +4,6 @@
- file, You can obtain one at https://mozilla.org/MPL/2.0/. - file, You can obtain one at https://mozilla.org/MPL/2.0/.
--> -->
<script lang="ts"> <script lang="ts">
throw new Error(
'@migration task: Add data prop (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292707)'
);
import type { QuizData } from '$lib/quiz_types'; import type { QuizData } from '$lib/quiz_types';
import { socket } from '$lib/socket'; import { socket } from '$lib/socket';
@@ -24,9 +20,8 @@
// game_id: 'a7ddb6af-79ab-45e0-b996-6254c1ad9818', // game_id: 'a7ddb6af-79ab-45e0-b996-6254c1ad9818',
// game_pin: '66190765' // game_pin: '66190765'
// }; // };
export let game_pin: string; export let data;
export let auto_connect: boolean; let { game_pin, auto_connect, game_token } = data;
export let game_token: string;
let players: Array<Player> = []; let players: Array<Player> = [];
let errorMessage = ''; let errorMessage = '';
@@ -53,25 +48,25 @@
console.log(quiz_data); console.log(quiz_data);
success = true; success = true;
}); });
socket.on('player_joined', (data) => { socket.on('player_joined', (int_data) => {
players = [...players, data]; players = [...players, int_data];
}); });
socket.on('already_registered_as_admin', () => { socket.on('already_registered_as_admin', () => {
errorMessage = $t('admin_page.already_registered_as_admin'); errorMessage = $t('admin_page.already_registered_as_admin');
}); });
socket.on('question_results', (data) => { socket.on('question_results', (int_data) => {
try { try {
data = JSON.parse(data); int_data = JSON.parse(int_data);
} catch (e) { } catch (e) {
console.error('Failed to parse question results'); console.error('Failed to parse question results');
return; return;
} }
question_results = data; question_results = int_data;
}); });
socket.on('export_token', (data) => { socket.on('export_token', (int_data) => {
warnToLeave = false; warnToLeave = false;
dataexport_download_a.href = `/api/v1/quiz/export_data/${data}?ts=${new Date().getTime()}&game_pin=${game_pin}`; dataexport_download_a.href = `/api/v1/quiz/export_data/${int_data}?ts=${new Date().getTime()}&game_pin=${game_pin}`;
dataexport_download_a.click(); dataexport_download_a.click();
warnToLeave = true; warnToLeave = true;
}); });
-21
View File
@@ -3,27 +3,6 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this - 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/. - file, You can obtain one at https://mozilla.org/MPL/2.0/.
--> -->
<script context="module" lang="ts">
throw new Error(
'@migration task: Check code was safely removed (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292722)'
);
// import { signedIn } from '$lib/stores';
// export async function load({ session }) {
// if (!session.authenticated) {
// return {
// status: 302,
// redirect: '/account/login?returnTo=/create'
// };
// }
// if (session.authenticated) {
// signedIn.set(true);
// }
// return {};
// }
</script>
<script lang="ts"> <script lang="ts">
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import Editor from '$lib/editor.svelte'; import Editor from '$lib/editor.svelte';
-15
View File
@@ -3,21 +3,6 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this - 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/. - file, You can obtain one at https://mozilla.org/MPL/2.0/.
--> -->
<script lang="ts" context="module">
throw new Error(
'@migration task: Check code was safely removed (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292722)'
);
// import { signedIn } from '$lib/stores';
// export async function load({ session }) {
// if (session.authenticated) {
// signedIn.set(true);
// }
// return {};
// }
</script>
<script lang="ts"> <script lang="ts">
import Footer from '$lib/footer.svelte'; import Footer from '$lib/footer.svelte';
import { navbarVisible } from '$lib/stores'; import { navbarVisible } from '$lib/stores';
+6 -42
View File
@@ -3,44 +3,7 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this - 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/. - file, You can obtain one at https://mozilla.org/MPL/2.0/.
--> -->
<script lang="ts" context="module">
throw new Error(
'@migration task: Check code was safely removed (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292722)'
);
// import { signedIn } from '$lib/stores';
// export async function load({ url, session }) {
// const quiz_id = url.searchParams.get('quiz_id');
// if (!session.authenticated) {
// return {
// status: 302,
// redirect: `/account/login?returnTo=/edit?quiz_id=${quiz_id}`
// };
// }
// if (session.authenticated) {
// signedIn.set(true);
// }
// if (quiz_id === null) {
// return {
// status: 404
// };
// }
// return {
// props: {
// quiz_id
// }
// };
// }
</script>
<script lang="ts"> <script lang="ts">
throw new Error(
'@migration task: Add data prop (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292707)'
);
import Editor from '$lib/editor.svelte'; import Editor from '$lib/editor.svelte';
import { getLocalization } from '$lib/i18n'; import { getLocalization } from '$lib/i18n';
import { navbarVisible } from '$lib/stores'; import { navbarVisible } from '$lib/stores';
@@ -73,8 +36,9 @@
answer: string; answer: string;
} }
export let quiz_id: string; export let data;
let data: Data; let { quiz_id } = data;
let quiz_data: Data;
const get_quiz = async (): Promise<void> => { const get_quiz = async (): Promise<void> => {
const response = await fetch(`/api/v1/quiz/get/${quiz_id}`); const response = await fetch(`/api/v1/quiz/get/${quiz_id}`);
@@ -90,7 +54,7 @@
temp_data.questions[i].type = QuizQuestionType[question.type]; temp_data.questions[i].type = QuizQuestionType[question.type];
} }
} }
data = temp_data; quiz_data = temp_data;
return; return;
} }
}; };
@@ -111,8 +75,8 @@
/> />
</svg> </svg>
{:then _} {:then _}
{#if data !== undefined} {#if quiz_data !== undefined}
<Editor bind:data submit_button_text={$t('words.save')} bind:quiz_id /> <Editor bind:quiz_data submit_button_text={$t('words.save')} bind:quiz_id />
{/if} {/if}
{:catch err} {:catch err}
<div class="text-center"> <div class="text-center">
-15
View File
@@ -3,21 +3,6 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this - 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/. - file, You can obtain one at https://mozilla.org/MPL/2.0/.
--> -->
<script context="module" lang="ts">
throw new Error(
'@migration task: Check code was safely removed (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292722)'
);
// import { signedIn } from '$lib/stores';
// export async function load({ session }) {
// if (session.authenticated) {
// signedIn.set(true);
// }
// return {};
// }
</script>
<script lang="ts"> <script lang="ts">
import { navbarVisible } from '$lib/stores'; import { navbarVisible } from '$lib/stores';
navbarVisible.set(true); navbarVisible.set(true);
-25
View File
@@ -3,31 +3,6 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this - 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/. - file, You can obtain one at https://mozilla.org/MPL/2.0/.
--> -->
<script context="module" lang="ts">
throw new Error(
'@migration task: Check code was safely removed (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292722)'
);
// import { signedIn } from '$lib/stores';
// export async function load({ session }) {
// if (!session.authenticated) {
// return {
// status: 302,
// redirect: '/account/login?returnTo=/import'
// };
// } else {
// if (session.authenticated) {
// signedIn.set(true);
// }
// }
// return {
// props: {
// email: session.email
// }
// };
// }
</script>
<script lang="ts"> <script lang="ts">
import { getLocalization } from '$lib/i18n'; import { getLocalization } from '$lib/i18n';
import { navbarVisible, alertModal } from '$lib/stores'; import { navbarVisible, alertModal } from '$lib/stores';
+2 -25
View File
@@ -3,31 +3,7 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this - 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/. - file, You can obtain one at https://mozilla.org/MPL/2.0/.
--> -->
<script context="module" lang="ts">
throw new Error(
'@migration task: Check code was safely removed (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292722)'
);
// import { signedIn } from '$lib/stores';
// export async function load({ url, session }) {
// if (session.authenticated) {
// signedIn.set(true);
// }
// const token = url.searchParams.get('pin');
// return {
// props: {
// game_pin: token === null ? '' : token
// }
// };
// }
</script>
<script lang="ts"> <script lang="ts">
throw new Error(
'@migration task: Add data prop (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292707)'
);
import { socket } from '$lib/socket'; import { socket } from '$lib/socket';
import JoinGame from '$lib/play/join.svelte'; import JoinGame from '$lib/play/join.svelte';
import type { Answer, QuizData } from '$lib/quiz_types'; import type { Answer, QuizData } from '$lib/quiz_types';
@@ -39,7 +15,8 @@
import { QuizQuestionType } from '$lib/quiz_types'; import { QuizQuestionType } from '$lib/quiz_types';
// Exports // Exports
export let game_pin: string; export let data;
let { game_pin } = data;
// Types // Types
interface GameMeta { interface GameMeta {
-15
View File
@@ -3,21 +3,6 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this - 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/. - file, You can obtain one at https://mozilla.org/MPL/2.0/.
--> -->
<script context="module" lang="ts">
throw new Error(
'@migration task: Check code was safely removed (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292722)'
);
// import { signedIn } from '$lib/stores';
// export async function load({ session }) {
// if (session.authenticated) {
// signedIn.set(true);
// }
// return {};
// }
</script>
<script lang="ts"> <script lang="ts">
import { getLocalization } from '$lib/i18n'; import { getLocalization } from '$lib/i18n';
const { t } = getLocalization(); const { t } = getLocalization();
@@ -4,10 +4,6 @@
- file, You can obtain one at https://mozilla.org/MPL/2.0/. - file, You can obtain one at https://mozilla.org/MPL/2.0/.
--> -->
<script lang="ts"> <script lang="ts">
throw new Error(
'@migration task: Add data prop (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292707)'
);
import { getLocalization } from '$lib/i18n'; import { getLocalization } from '$lib/i18n';
import CollapsSection from '$lib/collapsible.svelte'; import CollapsSection from '$lib/collapsible.svelte';
import { createTippy } from 'svelte-tippy'; import { createTippy } from 'svelte-tippy';
@@ -21,8 +17,8 @@
}); });
const { t } = getLocalization(); const { t } = getLocalization();
export let logged_in: boolean; export let data;
export let quiz: QuizData; let { quiz, logged_in }: { quiz: QuizData; logged_in: boolean } = data;
interface Question { interface Question {
time: string; time: string;
@@ -133,13 +129,14 @@
stroke="currentColor" stroke="currentColor"
viewBox="0 0 24 24" viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
><path >
<path
stroke-linecap="round" stroke-linecap="round"
stroke-linejoin="round" stroke-linejoin="round"
stroke-width="2" stroke-width="2"
d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"
/></svg />
> </svg>
<span class="text-lg">{question.time}s</span> <span class="text-lg">{question.time}s</span>
</p> </p>
{#if question.type === QuizQuestionType.ABCD || question.type === undefined} {#if question.type === QuizQuestionType.ABCD || question.type === undefined}