✨ Added basic quiztivity editor
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<!--
|
||||
- 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 type { Data } from '../../../lib/quiztivity/types';
|
||||
import Editor from '../../../lib/quiztivity/editor.svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
let data: Data = { pages: [], id: undefined, title: '' };
|
||||
let saving = false;
|
||||
|
||||
const save_quiztivity = async () => {
|
||||
saving = true;
|
||||
console.log(data);
|
||||
const stringification = JSON.stringify(data);
|
||||
console.log(stringification);
|
||||
|
||||
const res = await fetch('/api/v1/quiztivity/create', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: stringification
|
||||
});
|
||||
if (res.ok) {
|
||||
// await goto("/dashboard")
|
||||
} else {
|
||||
alert("Couldn't save");
|
||||
}
|
||||
saving = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<div class="h-full">
|
||||
<Editor bind:data on:save={save_quiztivity} bind:saving />
|
||||
</div>
|
||||
@@ -0,0 +1,40 @@
|
||||
<!--
|
||||
- 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 type { PageData } from './$types';
|
||||
import type { Data } from '../../../lib/quiztivity/types';
|
||||
import Editor from '../../../lib/quiztivity/editor.svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
let saving = false;
|
||||
|
||||
let quiztivity = data.quiztivity;
|
||||
|
||||
const save_quiztivity = async () => {
|
||||
saving = true;
|
||||
const stringification = JSON.stringify(quiztivity);
|
||||
|
||||
const res = await fetch(`/api/v1/quiztivity/${quiztivity.id}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: stringification
|
||||
});
|
||||
if (res.ok) {
|
||||
// await goto("/dashboard")
|
||||
} else {
|
||||
alert("Couldn't save");
|
||||
}
|
||||
saving = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<div class="h-full">
|
||||
<Editor bind:data={quiztivity} on:save={save_quiztivity} bind:saving />
|
||||
</div>
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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 type { PageLoad } from './$types';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type { Data } from '../../../lib/quiztivity/types';
|
||||
|
||||
export const load = (async ({ url, fetch }) => {
|
||||
const id = url.searchParams.get('id');
|
||||
if (!id) {
|
||||
throw error(400, 'id missing');
|
||||
}
|
||||
const resp = await fetch(`/api/v1/quiztivity/${id}`);
|
||||
if (!resp.ok) {
|
||||
throw error(404, 'quiztivity not found');
|
||||
}
|
||||
const data: Data = await resp.json();
|
||||
return {
|
||||
quiztivity: data
|
||||
};
|
||||
}) satisfies PageLoad;
|
||||
Reference in New Issue
Block a user