bug fix repeat
This commit is contained in:
parent
7cf0eb0eb4
commit
48e4f4d000
|
@ -75,10 +75,10 @@
|
|||
path: '/scanner',
|
||||
component: () => import('$routes/qrscanner/qrscanner.svelte'),
|
||||
},
|
||||
{
|
||||
/*{
|
||||
path: '/test',
|
||||
component: () => import('$routes/test.svelte'),
|
||||
},
|
||||
},*/
|
||||
{
|
||||
path: '/map',
|
||||
component: () => import('$root/src/routes/map/map.svelte'),
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
export let center = null
|
||||
|
||||
export let mapComponent = null
|
||||
export let user = { lat: 0, lng: 0 }
|
||||
export let userLocation = { lat: 0, lng: 0 }
|
||||
|
||||
$: console.log(user, center)
|
||||
$: console.log(userLocation, center)
|
||||
|
||||
let className = ''
|
||||
export { className as class }
|
||||
|
@ -25,11 +25,11 @@
|
|||
})()*/
|
||||
|
||||
navigator.geolocation.getCurrentPosition((position: GeolocationPosition) => {
|
||||
if (!user) user = { lat: position.coords.latitude, lng: position.coords.longitude }
|
||||
if (!userLocation) userLocation = { lat: position.coords.latitude, lng: position.coords.longitude }
|
||||
if (!center) center = { lat: position.coords.latitude, lng: position.coords.longitude }
|
||||
}) //at mapbox this is required dont know why
|
||||
|
||||
$: if (!center) center = user
|
||||
$: if (!center) center = userLocation
|
||||
/* if (navigator.geolocation) {
|
||||
navigator.geolocation.watchPosition(showPosition, () => dispatch('locationFailed'))
|
||||
} else {
|
||||
|
@ -59,7 +59,7 @@
|
|||
on:geolocate={(e) => {
|
||||
// @ts-ignore
|
||||
const { latitude, longitude } = e.detail.coords
|
||||
user = { lat: latitude, lng: longitude }
|
||||
userLocation = { lat: latitude, lng: longitude }
|
||||
}}
|
||||
/>
|
||||
</Map>
|
||||
|
|
|
@ -6,15 +6,15 @@
|
|||
|
||||
export let lat = 0
|
||||
export let lng = 0
|
||||
export let user = { lat: 0, lng: 0 }
|
||||
export let userLocation = { lat: 0, lng: 0 }
|
||||
export let popup: string | null = null
|
||||
|
||||
export let round = (1 / 110.574 / 1000) * 12 //cca 12m nutno pozměnit!!!!!!!!!! tento komentář nemazat
|
||||
let Mlat = [lat - round, lat + round]
|
||||
let Mlng = [lng - round, lng + round]
|
||||
$: isIn = user ? user.lat > Mlat[0] && user.lat < Mlat[1] && user.lng > Mlng[0] && user.lng < Mlng[1] : null
|
||||
$: isIn = userLocation ? userLocation.lat > Mlat[0] && userLocation.lat < Mlat[1] && userLocation.lng > Mlng[0] && userLocation.lng < Mlng[1] : null
|
||||
|
||||
$: isIn && dispatch('enter', { lat, lng, user })
|
||||
$: isIn && dispatch('enter', { lat, lng, userLocation })
|
||||
</script>
|
||||
|
||||
<Marker popup={false} {lat} {lng}>
|
||||
|
|
|
@ -6,6 +6,8 @@ import { writable } from 'svelte/store'
|
|||
import { CheckPoint, Experience } from '$lib/TStypes/experiences'
|
||||
import collections from '$lib/collections'
|
||||
|
||||
export type AnswerState = 'wrong-firstTime' | 'wrong-secondTime' | 'correct' | 'not-control' | null
|
||||
|
||||
let user: { $id: string }
|
||||
userStore.subscribe((res) => (user = res))
|
||||
|
||||
|
@ -41,6 +43,7 @@ const getRating = async (expId: string) => {
|
|||
const sum = documents.reduce((accumulator, rating) => accumulator + rating.ExpUserRating, 0)
|
||||
return sum / total || 0
|
||||
}
|
||||
|
||||
// Fetch of answers to the checkpoints
|
||||
export const answer = async (experienceId: string, checkPointId: string, answer: any) => {
|
||||
try {
|
||||
|
@ -54,17 +57,43 @@ export const answer = async (experienceId: string, checkPointId: string, answer:
|
|||
if (CPType === 'CHECKBOX') correct = JSON.stringify(answer) === JSON.stringify(correctAnswer)
|
||||
if (CPType === 'RADIO' || CPType === 'NUMBER' || CPType === 'TEXT') correct = answer === correctAnswer[0]
|
||||
|
||||
collections.usersAnswers.createDocument({
|
||||
userId: user.$id,
|
||||
checkPoint: checkPointId,
|
||||
answer,
|
||||
experience: experienceId,
|
||||
}, [Permission.read(Role.user(user.$id))])
|
||||
//await saveAnswerIntoDatabase(experienceId, checkPointId, correct)
|
||||
|
||||
return correct
|
||||
} catch (error) {
|
||||
//operation only for sveltekit 401, 500, 403
|
||||
}
|
||||
}
|
||||
|
||||
const saveAnswerIntoDatabase = async (experienceId: string, checkPointId: string, correct: boolean) => {
|
||||
const previousAttemptDocument = await getUserAnswer(user.$id, checkPointId)
|
||||
console.log(previousAttemptDocument)
|
||||
|
||||
if (!(previousAttemptDocument?.attemptCount === 2)) {
|
||||
if (previousAttemptDocument) {
|
||||
collections.usersAnswers.updateDocument(previousAttemptDocument.$id, {
|
||||
correct,
|
||||
attemptCount: 2,
|
||||
})
|
||||
} else {
|
||||
await collections.usersAnswers.createDocument(
|
||||
{
|
||||
userId: user.$id,
|
||||
checkPoint: checkPointId,
|
||||
correct,
|
||||
experience: experienceId,
|
||||
attemptCount: 1,
|
||||
},
|
||||
[Permission.read(Role.user(user.$id)), Permission.update(Role.user(user.$id))],
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const getUserAnswer = async (userId, checkPointId) => {
|
||||
return (await databases.listDocuments('63cef30d6da945dd4250', 'users-answers', [Query.equal('checkPoint', checkPointId), Query.equal('userId', userId)])).documents[0]
|
||||
}
|
||||
|
||||
// Fetch of all experiences
|
||||
export const getExperiences = async () => {
|
||||
const experiences = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpApproved', true)])).documents
|
||||
|
|
|
@ -12,7 +12,10 @@
|
|||
import Info from './Info.svelte'
|
||||
import { Experience } from '$lib/TStypes/experiences'
|
||||
import Layout from '../Components/Layout.svelte'
|
||||
import { answer } from '$lib/utils/database/experience'
|
||||
import { answer, AnswerState, getUserAnswer } from '$lib/utils/database/experience'
|
||||
import { user } from '$lib/appwrite'
|
||||
import Button from '$lib/components/Buttons/Button.svelte'
|
||||
import LayoutImg from '$lib/components/Layouts/LayoutImg.svelte'
|
||||
|
||||
const components = {
|
||||
TEXT: TextForm,
|
||||
|
@ -24,8 +27,8 @@
|
|||
INFO: Info,
|
||||
}
|
||||
|
||||
export let control: 'wrong-firstTime' | 'wrong-secondTime' | 'correct' | 'not-control' | null = null
|
||||
let view: 'question' | 'map' | 'end' | 'start-map' = 'start-map'
|
||||
export let control: AnswerState = null
|
||||
let view: 'question' | 'map' | 'end' | 'start' | 'start-map' = 'start-map'
|
||||
export let gameData: Experience //data
|
||||
|
||||
let client = {
|
||||
|
@ -56,7 +59,7 @@
|
|||
let [lat, lng] = [null, null]
|
||||
$: if (client.pos < client.end) [lat, lng] = view === 'map' ? gameData.checkPoints[client.pos].CPLocation : gameData.ExpLocation
|
||||
|
||||
let user = { lat: 0, lng: 0 }
|
||||
let userLocation = { lat: 0, lng: 0 }
|
||||
|
||||
$: checkPoint = gameData.checkPoints[client.pos]
|
||||
let myAnswer: string | string[]
|
||||
|
@ -76,14 +79,25 @@
|
|||
</script>
|
||||
|
||||
<input type="number" bind:value={client.pos} />
|
||||
<button on:click={() => (view = view === 'start-map' ? 'map' : 'question')}>disappear map</button>
|
||||
<button on:click={() => (view = view === 'start-map' ? 'start' : 'question')}>disappear map</button>
|
||||
|
||||
{#if view === 'map' || view === 'start-map'}
|
||||
<Erantmap bind:user class="w-full h-full">
|
||||
<Marker on:enter={() => (view = view === 'start-map' ? 'map' : 'question')} {lat} {lng} {user} />
|
||||
<Erantmap bind:userLocation class="w-full h-full">
|
||||
<Marker on:enter={() => (view = view === 'start-map' ? 'start' : 'question')} {lat} {lng} {userLocation} />
|
||||
</Erantmap>
|
||||
{/if}
|
||||
|
||||
{#if view === 'start'}
|
||||
<LayoutImg img={gameData.ExpImage}>
|
||||
<div class="w-full h-auto flex flex-wrap flex-row gap-4 justify-center">
|
||||
<div class="h-full w-full flex justify-self-center justify-center text-[32px] flex-wrap flex-col gap-4 items-center">
|
||||
{@html gameData.ExpStart}
|
||||
</div>
|
||||
<Button class="w-80 mt-8 " on:click={() => (view = 'map')}>pokračovat</Button>
|
||||
</div>
|
||||
</LayoutImg>
|
||||
{/if}
|
||||
|
||||
{#if view === 'question'}
|
||||
<Layout imgSrc={'gameData.question.thumbnail'} on:submit={() => checkAnswer()} on:nextQuestion={nextQuestion} {control}>
|
||||
<span slot="title">{checkPoint.CPName}</span>
|
||||
|
@ -107,8 +121,5 @@
|
|||
</Layout>
|
||||
{/if}
|
||||
{#if view === 'end'}
|
||||
<Finish {client} {gameData}>
|
||||
<span> Získali jste {client.points} / {client.possiblePointsToSeize} bodů</span>
|
||||
<span />
|
||||
</Finish>
|
||||
<Finish {client} {gameData} />
|
||||
{/if}
|
||||
|
|
|
@ -20,11 +20,10 @@
|
|||
|
||||
onMount(async () => {
|
||||
try {
|
||||
$data = await load(params.gameurl, 10, (preview) => {
|
||||
$data = await load(params.gameurl, 1, (preview) => {
|
||||
$data = preview
|
||||
view = 'experience-preview'
|
||||
})
|
||||
view = 'experience-preview'
|
||||
} catch (error) {
|
||||
navigate('/error')
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue