Removed pow, alertModal and fixed storage

This commit is contained in:
Mawoka
2023-05-28 13:03:20 +02:00
parent 0a73c3a811
commit c0bb8ce599
14 changed files with 60 additions and 130 deletions
+6 -4
View File
@@ -54,14 +54,16 @@
);
}
if (res.status !== 200) {
alertModal.set({
/* alertModal.set({
open: true,
title: 'Start failed',
body: `Failed to start game, ${await res.text()}`
});
alertModal.subscribe((_) => {
});*/
/*alertModal.subscribe((_) => {
window.location.assign('/account/login?returnTo=/dashboard');
});
});*/
alert('Starting game failed');
window.location.assign('/account/login?returnTo=/dashboard');
} else {
const data = await res.json();
// eslint-disable-next-line no-undef
+2 -33
View File
@@ -22,22 +22,6 @@
export let quiz_id: string | null;
let selected_question = -1;
let imgur_links_valid = false;
let pow_salt;
const computePOW = async (salt: string) => {
if (pow_salt === undefined) {
return;
}
console.log('Computing POW');
pow_data = await mint(salt, 16, '', 8, false);
pow_salt = undefined;
return;
};
$: {
pow_salt;
computePOW(pow_salt);
}
const validateInput = async (data: EditorData) => {
// console.log("input", data)
@@ -72,7 +56,6 @@
$: imgur_links_valid = checkIfAllQuestionImagesComplyWithRegex(data.questions);
let edit_id;
let confirm_to_leave = true;
let pow_data;
const getEditID = async () => {
let res;
@@ -88,7 +71,6 @@
if (res.status === 200) {
const json = await res.json();
edit_id = json.token;
setPOWdata();
} else {
alert('Error!');
}
@@ -123,13 +105,6 @@
alert('Error');
}
};
const setPOWdata = async () => {
const res = await fetch(`/api/v1/editor/pow?edit_id=${edit_id}`);
const data = (await res.json()).data;
console.log(data);
pow_data = await mint(data, 16);
console.log(pow_data);
};
</script>
<svelte:window on:beforeunload={confirmUnload} />
@@ -177,15 +152,9 @@
</div>
<div class="w-full h-full">
{#if selected_question === -1}
<SettingsCard bind:data bind:pow_salt bind:edit_id bind:pow_data />
<SettingsCard bind:data bind:edit_id />
{:else}
<QuizCard
bind:data
bind:selected_question
bind:edit_id
bind:pow_data
bind:pow_salt
/>
<QuizCard bind:data bind:selected_question bind:edit_id />
{/if}
</div>
</div>
-13
View File
@@ -24,8 +24,6 @@
export let data: EditorData;
export let selected_question: number;
export let edit_id: string;
export let pow_data;
export let pow_salt: string;
let uppyOpen = false;
let unique = {};
@@ -136,15 +134,6 @@
/>
</div>
</div>
{:else if pow_data === undefined}
<a
href="/docs/pow"
target="_blank"
use:tippy={{ content: "Click to learn why it's loading so long." }}
class="cursor-help"
>
<Spinner my_20={false} />
</a>
{:else}
{#await import('$lib/editor/uploader.svelte')}
<Spinner my_20={false} />
@@ -155,8 +144,6 @@
bind:edit_id
bind:data
bind:selected_question
bind:pow_data
bind:pow_salt
/>
{/await}
{/if}
@@ -8,9 +8,6 @@
import { getLocalization } from '$lib/i18n';
import Spinner from '$lib/Spinner.svelte';
export let pow_data;
export let pow_salt;
const { t } = getLocalization();
let uppyOpen = false;
@@ -76,10 +73,6 @@
}}
/>
</div>
{:else if pow_data === undefined}
<a href="/docs/pow" target="_blank" class="cursor-help">
<Spinner my_20={false} />
</a>
{:else}
{#await import('$lib/editor/uploader.svelte')}
<Spinner my_20={false} />
@@ -89,8 +82,6 @@
bind:modalOpen={uppyOpen}
bind:edit_id
bind:data
bind:pow_data
bind:pow_salt
/>
{/await}
{/if}
@@ -191,10 +182,6 @@
class="mt-10 bg-red-500 p-2 rounded-lg border-2 border-black transition hover:bg-red-400"
>Remove Background-Image</button
>
{:else if pow_data === undefined}
<a href="/docs/pow" target="_blank" class="cursor-help pt-10">
<Spinner my_20={false} />
</a>
{:else}
{#await import('$lib/editor/uploader.svelte')}
<div class="pt-10">
@@ -207,8 +194,6 @@
bind:edit_id
bind:data
selected_question={-1}
bind:pow_data
bind:pow_salt
/>
{/await}
{/if}
-5
View File
@@ -28,10 +28,7 @@
export let edit_id: string;
export let data: EditorData;
export let selected_question: number;
export let pow_data;
export let pow_salt: string;
console.log(pow_data);
const uppy = new Uppy()
.use(DropTarget, {
target: document.body
@@ -58,10 +55,8 @@
let image_id;
uppy.on('upload-success', (file, response) => {
image_id = response.body.id;
pow_data = undefined;
});
uppy.on('complete', (_) => {
console.log(pow_data);
if (selected_question === undefined) {
data.cover_image = image_id;
} else if (selected_question === -1) {
+10 -11
View File
@@ -72,20 +72,22 @@
custom_field = json.custom_field;
}
if (res.status === 404) {
alertModal.set({
/* alertModal.set({
open: true,
title: 'Game not found',
body: 'The game pin you entered seems invalid.'
});
});*/
alert('Game not found');
game_pin = '';
return;
}
if (res.status !== 200) {
alertModal.set({
/* alertModal.set({
open: true,
body: `Unknown error with response-code ${res.status}`,
title: 'Unknown Error'
});
});*/
alert('Unknown error');
return;
}
};
@@ -122,16 +124,13 @@
if (import.meta.env.VITE_SENTRY !== null) {
Sentry.captureException(e);
}
alertModal.set({
/* alertModal.set({
open: true,
body: "The captcha failed, which is normal, but most of the time it's fixed by reloading!",
title: 'Captcha failed'
});
alertModal.subscribe((data) => {
if (!data.open) {
window.location.reload();
}
});
});*/
alert('Captcha failed!');
window.location.reload();
}
} else if (import.meta.env.VITE_RECAPTCHA) {
// eslint-disable-next-line no-undef
+3 -2
View File
@@ -91,7 +91,8 @@
{:else}
<slot />
{/if}
{#if $alertModal.open ?? false}
<!--{#if $alertModal.open ?? false}
<div
class="fixed inset-0 h-screen w-screen bg-black z-30 bg-opacity-60 items-center justify-center content-center"
class:hidden={!$alertModal.open}
@@ -104,7 +105,7 @@
bind:open={$alertModal.open}
/>
</div>
{/if}
{/if}-->
<style lang="scss">
:global(html:not(.dark)) {
@@ -37,19 +37,16 @@
try {
data = await res.json();
} catch {
alertModal.set({
open: true,
body: "This shouldn't happen. Please try again.",
title: 'Unknown error'
});
alert("This shouldn't happen");
window.location.reload();
}
if (data.detail === 'wrong credentials') {
alertModal.set({
/* alertModal.set({
open: true,
body: 'Please try again. Your email and or password were incorrect.',
title: 'Wrong Credentials'
});
});*/
alert('Wrong credentials');
}
}
};
@@ -44,19 +44,21 @@
try {
data = await res.json();
} catch {
alertModal.set({
/* alertModal.set({
open: true,
body: "This shouldn't happen. Please try again.",
title: 'Unknown error'
});
});*/
alert('Unknown error');
window.location.reload();
}
if (data.detail === 'totp wrong') {
alertModal.set({
/* alertModal.set({
open: true,
body: 'Wrong Totp-Code. please try again.',
title: 'Totp Error'
});
});*/
alert('TOTP code was incorrect');
totp = '';
}
}
@@ -24,11 +24,12 @@
asseResp = await startAuthentication(data);
} catch (e) {
console.error(e);
alertModal.set({
/* alertModal.set({
open: true,
body: e,
title: 'Unknown error'
});
});*/
alert('Unknown error');
isLoading = false;
}
const res = await fetch(
@@ -51,19 +52,21 @@
try {
data = await res.json();
} catch {
alertModal.set({
/* alertModal.set({
open: true,
body: "This shouldn't happen. Please try again.",
title: 'Unknown error'
});
});*/
alert('Unknown error');
window.location.reload();
}
if (data.detail === 'webauthn failed') {
alertModal.set({
/* alertModal.set({
open: true,
body: 'Webauthn failed. Please try again.',
title: 'Webauthn Error'
});
});*/
alert('Webauthn failed');
}
}
isLoading = false;
+9 -6
View File
@@ -35,17 +35,19 @@
if (res.status === 200) {
window.location.href = '/dashboard';
} else if (res.status === 400) {
alertModal.set({
/* alertModal.set({
open: true,
title: 'Import failed',
body: "This quiz isn't (yet) supported!"
});
});*/
alert("This quiz isn't (yet) supported!");
} else {
alertModal.set({
/* alertModal.set({
open: true,
title: 'Import failed',
body: 'Unknown error while importing the quiz!'
});
});*/
alert('Import failed with unknown reason');
}
is_loading = false;
};
@@ -61,11 +63,12 @@
if (res.status === 200) {
window.location.href = '/dashboard';
} else {
alertModal.set({
/* alertModal.set({
open: true,
title: 'Import failed',
body: 'Something went wrong!'
});
});*/
alert('Something went wrong!');
}
is_loading = false;
};