From b4df394e29b711b3244db6a0c5da94ed699928ff Mon Sep 17 00:00:00 2001 From: Ota Prokopec Date: Fri, 17 Mar 2023 18:47:41 +0100 Subject: [PATCH] err --- src/lib/TStypes/experiences.ts | 13 ++++++++++++- src/lib/components/Map/Erantmap.svelte | 20 +++++++++++++++----- src/lib/utils/database/game.ts | 25 ++++++++++++++----------- src/routes/game/Forms/Info.svelte | 3 ++- src/routes/game/game.svelte | 7 +++---- 5 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/lib/TStypes/experiences.ts b/src/lib/TStypes/experiences.ts index 56fcfd1..6e17856 100644 --- a/src/lib/TStypes/experiences.ts +++ b/src/lib/TStypes/experiences.ts @@ -1,5 +1,10 @@ export type CheckPoint = { $id: string + $collectionId: string + $createdAt: string + $databaseId: string + $permissions: string + $updatedAt: string CPAfter: string CPAnswerID: string CPHint: string @@ -13,6 +18,12 @@ export type CheckPoint = { } export type Experience = { + $id: string + $collectionId: string + $createdAt: string + $databaseId: string + $permissions: string + $updatedAt: string ExpApproved: boolean ExpCpsID: string[] ExpCategory?: string @@ -27,5 +38,5 @@ export type Experience = { ExpTestingCode: string ExpURL: string UserID: string - checkPoint: Array + checkPoints: Array } diff --git a/src/lib/components/Map/Erantmap.svelte b/src/lib/components/Map/Erantmap.svelte index 0b7fa10..4206ac6 100644 --- a/src/lib/components/Map/Erantmap.svelte +++ b/src/lib/components/Map/Erantmap.svelte @@ -13,9 +13,17 @@ let className = '' export { className as class } + /*;(() => { + navigator.geolocation.getCurrentPosition(() => { + navigator.geolocation.watchPosition((e) => { + console.log(e) + }) + }) + })()*/ + navigator.geolocation.getCurrentPosition((e) => {}) - if (navigator.geolocation) { - navigator.geolocation.getCurrentPosition(showPosition, () => dispatch('locationFailed')) + /* if (navigator.geolocation) { + navigator.geolocation.watchPosition(showPosition, () => dispatch('locationFailed')) } else { alert("Can't load your location!") } @@ -23,14 +31,16 @@ user.lat = position.coords.latitude user.lng = position.coords.longitude if (!center) center = user - } + }*/ - const userCenter = () => document.getElementsByClassName('mapboxgl-ctrl-geolocate')[0].click() + const userCenter = () => { + document.getElementsByClassName('mapboxgl-ctrl-geolocate')[0].click() + } {#if center} - setTimeout(() => userCenter(), 40)} {center} bind:mapComponent class={className} on:move> + setTimeout(() => setInterval(() => userCenter(), 1000), 100)} {center} bind:mapComponent class={className} on:move> { diff --git a/src/lib/utils/database/game.ts b/src/lib/utils/database/game.ts index 61a1db3..30771d2 100644 --- a/src/lib/utils/database/game.ts +++ b/src/lib/utils/database/game.ts @@ -3,29 +3,32 @@ import { Query } from 'appwrite' import database from 'svelte-appwrite-client/src/lib/database' import { getLocationDataFromLatAndLong } from '../locations' import { writable } from 'svelte/store' -import { Experience } from '$lib/TStypes/experiences' +import { CheckPoint, Experience } from '$lib/TStypes/experiences' export const load = async (pathName: string, previewQuestionsCount?: number, preview?: Function) => { - const checkPoints = [] - const game = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpURL', pathName)])).documents[0] + const checkPoints: Array = [] + // @ts-ignore + const experience: Experience = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpURL', pathName)])).documents[0] - const checkPointsIds = game.ExpCPsID - const rating = await getRating(game.$id) + const checkPointsIds = experience.ExpCpsID + const rating = await getRating(experience.$id) for (const checkPointId of checkPointsIds) { try { + // @ts-ignore checkPoints.push(await databases.getDocument('63cef30d6da945dd4250', '63cef84d908acf805758', checkPointId)) if (checkPointsIds.indexOf(checkPointId) === previewQuestionsCount - 1) { - game['rating'] = rating - game['checkPoints'] = checkPoints - preview(game) + experience['rating'] = rating + experience['checkPoints'] = checkPoints + preview(experience) } } catch (error) {} } - game['rating'] = rating - game['checkPoints'] = checkPoints - return game + experience['rating'] = rating + experience['checkPoints'] = checkPoints + + return experience } const getRating = async (expId: string) => { diff --git a/src/routes/game/Forms/Info.svelte b/src/routes/game/Forms/Info.svelte index e79b464..c511581 100644 --- a/src/routes/game/Forms/Info.svelte +++ b/src/routes/game/Forms/Info.svelte @@ -6,6 +6,7 @@ const { checkPoint, name } = data export let nextQuestion + export const control: 'wrong-firstTime' | 'wrong-secondTime' | 'correct' | 'not-control' | null = 'not-control' + \ No newline at end of file diff --git a/src/routes/game/game.svelte b/src/routes/game/game.svelte index 8da2d0b..968dee7 100644 --- a/src/routes/game/game.svelte +++ b/src/routes/game/game.svelte @@ -33,12 +33,11 @@ navigate('/error') } }) - $: console.log($data) - $: assets = $data?.questions + /*$: assets = $data?.questions ?.filter((q) => q.thumbnail !== null) ?.slice(0, 8) - ?.map((q) => q.thumbnail) + ?.map((q) => q.thumbnail)*/ let view: 'game-play' | 'game-loading' | 'game-preview' = 'game-loading' @@ -113,4 +112,4 @@ justify-content: flex-start; gap: 15px; } - + \ No newline at end of file