From ca2e4c87e9d76df51f66850ca597148305b5bda0 Mon Sep 17 00:00:00 2001 From: Ota Prokopec Date: Fri, 3 Mar 2023 20:59:50 +0100 Subject: [PATCH] second-first time answer --- src/App.svelte | 6 +++++- .../Layouts/NavigationBarLayout.svelte | 3 ++- src/lib/utils/database/game.ts | 2 +- src/routes/game/Components/Layout.svelte | 16 +++++++++------- src/routes/game/Forms/MultiChoiceForm.svelte | 9 +++++++-- src/routes/game/Forms/NumberForm.svelte | 9 +++++++-- src/routes/game/Forms/Renderer.svelte | 4 ++-- src/routes/game/Forms/SingleChoiceForm.svelte | 13 ++++++++----- src/routes/game/Forms/TextForm.svelte | 9 +++++++-- src/routes/log_in.svelte | 6 +++--- src/routes/profile/profile.svelte | 5 ++++- 11 files changed, 55 insertions(+), 27 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 1c37889..651c3f3 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -11,8 +11,12 @@ let isMounted = false $: isReady = $localeLoading === false && $authLoading === false && isMounted + $: console.log($user) + $: if (isReady && !$user) { - if (!(location.pathname.startsWith('/login') || location.pathname.startsWith('/register'))) { + console.log('change') + + if (!location.pathname.startsWith('/login') && !location.pathname.startsWith('/register')) { navigate('/login') } } diff --git a/src/lib/components/Layouts/NavigationBarLayout.svelte b/src/lib/components/Layouts/NavigationBarLayout.svelte index 663c7d4..2240d86 100644 --- a/src/lib/components/Layouts/NavigationBarLayout.svelte +++ b/src/lib/components/Layouts/NavigationBarLayout.svelte @@ -5,7 +5,8 @@ import { navigate } from 'svelte-routing' import FooterItem from '../Common/NavBar_Item.svelte' - $: [userInfo] = collections.users.getDocument([Query.equal('userId', $user.$id)]) + $: [userInfo] = collections.users.getDocument([Query.equal('userId', $user?.$id || '')]) + $: console.log($user) $: items = [ { diff --git a/src/lib/utils/database/game.ts b/src/lib/utils/database/game.ts index 9b7f7af..d0a7542 100644 --- a/src/lib/utils/database/game.ts +++ b/src/lib/utils/database/game.ts @@ -37,7 +37,7 @@ export const answer = async (checkPointId: string, answer: any) => { } export const getExpiriences = async () => { - const expiriences = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888')).documents + const expiriences = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpApproved', true)])).documents let items: Array<{ location: string; name: string; link: string }> = [] for (const expirience of expiriences) { items.push({ diff --git a/src/routes/game/Components/Layout.svelte b/src/routes/game/Components/Layout.svelte index 6068ff7..e0e53b4 100644 --- a/src/routes/game/Components/Layout.svelte +++ b/src/routes/game/Components/Layout.svelte @@ -3,7 +3,7 @@ import Button from '../../../lib/components/Buttons/Button.svelte' import Image from '../../../lib/components/Common/Image.svelte' - export let control: null | false | true | 'not-control' + export let control: 'wrong-firstTime' | 'wrong-secondTime' | 'correct' | 'not-control' | null export let nextQuestion export let imgSrc @@ -24,19 +24,21 @@
- {#if control !== null || control === 'not-control'} - - {:else} - + {#if control === 'not-control' || control === 'correct' || control === 'wrong-secondTime'} + + {:else if control === 'wrong-firstTime' || control === null} + {/if}
{#if control === 'not-control' || control === null} - {:else if control === true} + {:else if control === 'correct'} správně - {:else if control === false} + {:else if control === 'wrong-firstTime'} + druhypokus + {:else if control === 'wrong-secondTime'} špatně {/if}
diff --git a/src/routes/game/Forms/MultiChoiceForm.svelte b/src/routes/game/Forms/MultiChoiceForm.svelte index 5451362..e95fe3f 100644 --- a/src/routes/game/Forms/MultiChoiceForm.svelte +++ b/src/routes/game/Forms/MultiChoiceForm.svelte @@ -8,14 +8,19 @@ const { checkPoint, name } = data let myAnswers = new Array(checkPoint.CPOptions.length).fill(false) - export let control = null + export let control: 'wrong-firstTime' | 'wrong-secondTime' | 'correct' | 'not-control' | null export let nextQuestion + export let attempt: 1 | 2 = 1 const answerCheckBox = async () => { const arr = checkPoint.CPOptions.filter((item, i) => { if (myAnswers[i] === true) return item }) - control = await answer(checkPoint.$id, arr) + const res = await answer(checkPoint.$id, arr) + if (res) control = 'correct' + else if (attempt === 1) control = 'wrong-firstTime' + else control = 'wrong-secondTime' + attempt++ } diff --git a/src/routes/game/Forms/NumberForm.svelte b/src/routes/game/Forms/NumberForm.svelte index d2323ed..483ef21 100644 --- a/src/routes/game/Forms/NumberForm.svelte +++ b/src/routes/game/Forms/NumberForm.svelte @@ -8,11 +8,16 @@ const { checkPoint, name } = data let myAnswer = '' - export let control = null + export let control: 'wrong-firstTime' | 'wrong-secondTime' | 'correct' | 'not-control' | null export let nextQuestion + export let attempt: 1 | 2 = 1 const answer_ = async () => { - control = await answer(checkPoint.$id, myAnswer) + const res = await answer(checkPoint.$id, myAnswer) + if (res) control = 'correct' + else if (attempt === 1) control = 'wrong-firstTime' + else control = 'wrong-secondTime' + attempt++ } diff --git a/src/routes/game/Forms/Renderer.svelte b/src/routes/game/Forms/Renderer.svelte index 7466c55..78719ce 100644 --- a/src/routes/game/Forms/Renderer.svelte +++ b/src/routes/game/Forms/Renderer.svelte @@ -22,7 +22,7 @@ INFO: Info, } - let control = null // if true => spravne if false spatne + export let control: 'wrong-firstTime' | 'wrong-secondTime' | 'correct' | 'not-control' | null = null let view: 'question' | 'map' | 'end' = 'map' export let gameData: any = {} //data @@ -37,7 +37,7 @@ $: console.log(clientAnswers.pos === clientAnswers.end + 1) - $: if (control === true) clientAnswers.points += 2 //body bodování + $: if (control === 'correct') clientAnswers.points += 2 //body bodování const nextQuestion = () => { //další otázka diff --git a/src/routes/game/Forms/SingleChoiceForm.svelte b/src/routes/game/Forms/SingleChoiceForm.svelte index 2412f5d..151c4da 100644 --- a/src/routes/game/Forms/SingleChoiceForm.svelte +++ b/src/routes/game/Forms/SingleChoiceForm.svelte @@ -8,13 +8,16 @@ const { checkPoint, name } = data let myAnswer = '' - $: console.log(data) - - export let control = null + export let control: 'wrong-firstTime' | 'wrong-secondTime' | 'correct' | 'not-control' | null export let nextQuestion + export let attempt: 1 | 2 = 1 const answer_ = async () => { - control = await answer(checkPoint.$id, myAnswer) + const res = await answer(checkPoint.$id, myAnswer) + if (res) control = 'correct' + else if (attempt === 1) control = 'wrong-firstTime' + else control = 'wrong-secondTime' + attempt++ } @@ -25,7 +28,7 @@ nextQuestion() myAnswer = '' }} - on:submit={() => (control = myAnswer !== '' ? answer_() : null)} + on:submit={() => (myAnswer !== '' ? answer_() : null)} > {name} {@html checkPoint.CPText} diff --git a/src/routes/game/Forms/TextForm.svelte b/src/routes/game/Forms/TextForm.svelte index 4d0edb9..857f73d 100644 --- a/src/routes/game/Forms/TextForm.svelte +++ b/src/routes/game/Forms/TextForm.svelte @@ -8,11 +8,16 @@ const { checkPoint, name } = data let myAnswer = '' - export let control = null + export let control: 'wrong-firstTime' | 'wrong-secondTime' | 'correct' | 'not-control' | null export let nextQuestion + export let attempt: 1 | 2 = 1 const answer_ = async () => { - control = await answer(checkPoint.$id, myAnswer) + const res = await answer(checkPoint.$id, myAnswer) + if (res) control = 'correct' + else if (attempt === 1) control = 'wrong-firstTime' + else control = 'wrong-secondTime' + attempt++ } diff --git a/src/routes/log_in.svelte b/src/routes/log_in.svelte index b9de8a2..e1da614 100644 --- a/src/routes/log_in.svelte +++ b/src/routes/log_in.svelte @@ -7,14 +7,14 @@ export let purpose = 'login' //possible values login, register - let email = '' - let password = '' + let email = 'aaahoj@ahoj.ahoj' + let password = 'ahojahoj' $: console.log($user) const emailLogin = async () => { await account.createEmailSession(email, password) - if (navigation.canGoBack) navigation.back() + //if (navigation.canGoBack) navigation.back() navigate('/') } diff --git a/src/routes/profile/profile.svelte b/src/routes/profile/profile.svelte index 434ef74..1594fdd 100644 --- a/src/routes/profile/profile.svelte +++ b/src/routes/profile/profile.svelte @@ -17,8 +17,11 @@ import { Query } from 'appwrite' export let params: { erantId: string } + // $: [userInfo] = collections.users.getDocument([Query.equal('erantId', params.erantId)]) + $: console.log($user) + const items = [ { title: 'Account', @@ -64,7 +67,7 @@ {#if typeof link === 'function'} - + {:else}