diff --git a/src/lib/utils/game.ts b/src/lib/utils/database/game.ts similarity index 55% rename from src/lib/utils/game.ts rename to src/lib/utils/database/game.ts index 7800b15..8abc5f8 100644 --- a/src/lib/utils/game.ts +++ b/src/lib/utils/database/game.ts @@ -1,6 +1,7 @@ import { databases } from '$lib/appwrite' import { Query } from 'appwrite' import database from 'svelte-appwrite-client/src/lib/database' +import { getLocationDataFromLatAndLong } from '../locations' export const load = async (pathName: string) => { const checkPoints = [] @@ -11,10 +12,20 @@ export const load = async (pathName: string) => { for (const checkPointId of checkPointsIds) { checkPoints.push(await databases.getDocument('63cef30d6da945dd4250', '63cef84d908acf805758', checkPointId)) } + const rating = await getRating(game.$id) + console.log(rating) + + game['rating'] = rating game['checkPoints'] = checkPoints return game } +const getRating = async (expId: string) => { + const { documents } = await databases.listDocuments('63cef30d6da945dd4250', '63ee6353ebb174cf815d', [Query.equal('ExpID', expId)]) + const sum = documents.reduce((accumulator, rating) => accumulator + rating.ExpUserRating, 0) + return sum / documents.length +} + export const answer = async (checkPointId: string, answer: any) => { const checkPoint = await databases.getDocument('63cef30d6da945dd4250', '63cef84d908acf805758', checkPointId) console.log({ checkPoint }) @@ -24,3 +35,16 @@ export const answer = async (checkPointId: string, answer: any) => { if (CPType === 'CHECKBOX') return JSON.stringify(answer) === JSON.stringify(correctAnswer) if (CPType === 'RADIO' || CPType === 'NUMBER' || CPType === 'TEXT') return answer === correctAnswer[0] } + +export const getExpiriences = async () => { + const expiriences = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888')).documents + let items: Array<{ location: string; name: string; link: string }> = [] + for (const expirience of expiriences) { + items.push({ + location: (await getLocationDataFromLatAndLong(expirience.ExpLocation[0], expirience.ExpLocation[1])).city, + name: expirience.ExpName, + link: `${expirience.ExpURL}`, + }) + } + return items +} diff --git a/src/lib/utils/locations.ts b/src/lib/utils/locations.ts new file mode 100644 index 0000000..0082a11 --- /dev/null +++ b/src/lib/utils/locations.ts @@ -0,0 +1,8 @@ +export const getLocationDataFromLatAndLong = async (latitude: number, longitude: number) => { + const response = await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=json`) + const data = await response.json() + return { + city: data.address.town || data.address.city || data.address.village, + state: data.address.country, + } +} diff --git a/src/routes/game/Forms/MultiChoiceForm.svelte b/src/routes/game/Forms/MultiChoiceForm.svelte index 09d20c6..5e89dfd 100644 --- a/src/routes/game/Forms/MultiChoiceForm.svelte +++ b/src/routes/game/Forms/MultiChoiceForm.svelte @@ -2,7 +2,7 @@ import Layout from '../Components/Layout.svelte' import CheckBox from '../../../lib/components/Inputs/Checkbox.svelte' import { checkPoint } from '$lib/TStypes/expiriences' - import { answer } from '$lib/utils/game' + import { answer } from '$lib/utils/database/game' export let data: { name: string; checkPoint: checkPoint } const { checkPoint, name } = data diff --git a/src/routes/game/Forms/NumberForm.svelte b/src/routes/game/Forms/NumberForm.svelte index fd890ea..b86146e 100644 --- a/src/routes/game/Forms/NumberForm.svelte +++ b/src/routes/game/Forms/NumberForm.svelte @@ -2,7 +2,7 @@ import Layout from '../Components/Layout.svelte' import Input from '../../../lib/components/Inputs/Input.svelte' import { checkPoint } from '$lib/TStypes/expiriences' - import { answer } from '$lib/utils/game' + import { answer } from '$lib/utils/database/game' export let data: { name: string; checkPoint: checkPoint } const { checkPoint, name } = data diff --git a/src/routes/game/Forms/Renderer.svelte b/src/routes/game/Forms/Renderer.svelte index e6b9a5b..49cc6e2 100644 --- a/src/routes/game/Forms/Renderer.svelte +++ b/src/routes/game/Forms/Renderer.svelte @@ -21,7 +21,7 @@ } let control = null // if true => spravne if false spatne - let view: 'question' | 'map' = 'question' + let view: 'question' | 'map' = 'map' export let gameData: any = {} //data $: console.log(gameData) @@ -54,6 +54,8 @@ let user = { lat: null, lng: null } + $: console.log(page, gameData.checkPoints[clientAnswers.pos].CPType) + /* //set user to localstorage $: if (clientAnswers.pos !== clientAnswers.end && clientAnswers.pos !== 0) { //nastaví diff --git a/src/routes/game/Forms/SingleChoiceForm.svelte b/src/routes/game/Forms/SingleChoiceForm.svelte index 73bc3cf..e364d50 100644 --- a/src/routes/game/Forms/SingleChoiceForm.svelte +++ b/src/routes/game/Forms/SingleChoiceForm.svelte @@ -2,7 +2,7 @@ import Radio from '../../../lib/components/Inputs/Radio.svelte' import Layout from '../Components/Layout.svelte' import { checkPoint } from '$lib/TStypes/expiriences' - import { answer } from '$lib/utils/game' + import { answer } from '$lib/utils/database/game' export let data: { name: string; checkPoint: checkPoint } const { checkPoint, name } = data diff --git a/src/routes/game/Forms/TextForm.svelte b/src/routes/game/Forms/TextForm.svelte index 945a06f..ae6104e 100644 --- a/src/routes/game/Forms/TextForm.svelte +++ b/src/routes/game/Forms/TextForm.svelte @@ -2,7 +2,7 @@ import Layout from '../Components/Layout.svelte' import Input from '../../../lib/components/Inputs/Input.svelte' import { checkPoint } from '$lib/TStypes/expiriences' - import { answer } from '$lib/utils/game' + import { answer } from '$lib/utils/database/game' export let data: { name: string; checkPoint: checkPoint } const { checkPoint, name } = data diff --git a/src/routes/game/game.svelte b/src/routes/game/game.svelte index e665f22..5a562b6 100644 --- a/src/routes/game/game.svelte +++ b/src/routes/game/game.svelte @@ -16,7 +16,8 @@ import collections from '$lib/collections' import { Query } from 'appwrite' import { onMount } from 'svelte' - import { load } from '$lib/utils/game' + import { load } from '$lib/utils/database/game' + import { getLocationDataFromLatAndLong } from '$lib/utils/locations' export let params: { gameurl: string } @@ -28,13 +29,14 @@ $data = await load(params.gameurl) loading = false }) + $: console.log($data) $: assets = $data?.questions ?.filter((q) => q.thumbnail !== null) ?.slice(0, 8) ?.map((q) => q.thumbnail) - let view: 'game-play' | 'game-loading' = 'game-play' + let view: 'game-play' | 'game-loading' = 'game-loading' //is user already in game //const userInGame = JSON.parse(localStorage.getItem(location.pathname)) @@ -54,11 +56,13 @@
- {$data.ExpRating} + {$data.rating} - {'$data.district'} + {#await getLocationDataFromLatAndLong($data.ExpLocation[0], $data.ExpLocation[1]) then { city }} + {city} + {/await}
@@ -79,7 +83,7 @@
- + {#each $data.checkPoints as { CPLocation: [lat, lng] }} {/each} diff --git a/src/routes/homepage/Components/Comparment.svelte b/src/routes/homepage/Components/Comparment.svelte index 4cb417c..e2801d6 100644 --- a/src/routes/homepage/Components/Comparment.svelte +++ b/src/routes/homepage/Components/Comparment.svelte @@ -1,22 +1,23 @@
- + -
- {#each items as item } - - {/each} -
+
+ {#each items as item} + navigate(`${item.link}`)} price={item.price} location={item.location} name={item.name} image={item.image} /> + {/each} +
\ No newline at end of file + diff --git a/src/routes/homepage/Components/Compartment_Item.svelte b/src/routes/homepage/Components/Compartment_Item.svelte index 6d7d5e1..fcccf7b 100644 --- a/src/routes/homepage/Components/Compartment_Item.svelte +++ b/src/routes/homepage/Components/Compartment_Item.svelte @@ -1,47 +1,61 @@ -
+
+

{name}

+
+ + + + + + + + + -
-

{name}

-
- - - - - - - - - - - {location} -
-
+ {location} +
+
diff --git a/src/routes/homepage/homepage.svelte b/src/routes/homepage/homepage.svelte index 5a5f78b..8008f3a 100644 --- a/src/routes/homepage/homepage.svelte +++ b/src/routes/homepage/homepage.svelte @@ -6,41 +6,41 @@ import Comparment from './Components/Comparment.svelte' //do budoucna bych to udělal pomocí komponent import { onMount } from 'svelte' import Animation from './Components/Animation.svelte' - + import collections from '$lib/collections' + import { getLocationDataFromLatAndLong } from '$lib/utils/locations' + import { getExpiriences } from '$lib/utils/database/game' + import Loading from '$lib/components/Common/Loading.svelte' + let fitstTime = false onMount(() => { - if (localStorage.getItem("ErantFirstTime") == null){ + if (localStorage.getItem('ErantFirstTime') == null) { fitstTime = true setTimeout(() => { fitstTime = false - localStorage.setItem('ErantFirstTime', "false"); + localStorage.setItem('ErantFirstTime', 'false') }, 11000) } }) - let city = ""; - let state = ""; + let city = '' + let state = '' - if ("geolocation" in navigator) { - navigator.geolocation.getCurrentPosition(async position => { - const latitude = position.coords.latitude; - const longitude = position.coords.longitude; - const response = await fetch( - `https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=json` - ); - const data = await response.json(); - - city = data.address.town || data.address.city || data.address.village; - state = ", "+data.address.country; - }); + if ('geolocation' in navigator) { + navigator.geolocation.getCurrentPosition(async (position) => { + const latitude = position.coords.latitude + const longitude = position.coords.longitude + const response = await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=json`) + const data = await response.json() + city = data.address.town || data.address.city || data.address.village + state = ', ' + data.address.country + }) } - {#if !fitstTime} - + @@ -48,13 +48,13 @@ - + {#await getExpiriences()} +
+ +
+ {:then expiriences} + + {/await}
{:else}
@@ -64,7 +64,7 @@