diff --git a/src/lib/TStypes/experiences.ts b/src/lib/TStypes/experiences.ts index db04eee..56fcfd1 100644 --- a/src/lib/TStypes/experiences.ts +++ b/src/lib/TStypes/experiences.ts @@ -1,4 +1,4 @@ -export type checkPoint = { +export type CheckPoint = { $id: string CPAfter: string CPAnswerID: string @@ -12,7 +12,7 @@ export type checkPoint = { CPType: 'CHECKBOX' | 'TEXT' | 'INFO' | 'RADIO' | 'NUMBER' } -export type expirience = { +export type Experience = { ExpApproved: boolean ExpCpsID: string[] ExpCategory?: string @@ -27,5 +27,5 @@ export type expirience = { ExpTestingCode: string ExpURL: string UserID: string - checkPoint: Array + checkPoint: Array } diff --git a/src/lib/components/Map/Marker.svelte b/src/lib/components/Map/Marker.svelte index 63aa589..262db7e 100644 --- a/src/lib/components/Map/Marker.svelte +++ b/src/lib/components/Map/Marker.svelte @@ -1,11 +1,13 @@ - - - - - - - - - - - - - - - - + + {#if popup} + {popup} + {/if} diff --git a/src/lib/utils/database/game.ts b/src/lib/utils/database/game.ts index 365c00d..61a1db3 100644 --- a/src/lib/utils/database/game.ts +++ b/src/lib/utils/database/game.ts @@ -2,6 +2,8 @@ import { databases } from '$lib/appwrite' 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' export const load = async (pathName: string, previewQuestionsCount?: number, preview?: Function) => { const checkPoints = [] @@ -44,14 +46,31 @@ export const answer = async (checkPointId: string, answer: any) => { export const getExpiriences = async () => { const expiriences = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpApproved', true)])).documents - let items: Array<{ location: string; name: string; link: string }> = [] + let items = [] for (const expirience of expiriences) { items.push({ - location: (await getLocationDataFromLatAndLong(expirience.ExpLocation[0], expirience.ExpLocation[1])).city, - name: expirience.ExpName, - link: `${expirience.ExpURL}`, + city: (await getLocationDataFromLatAndLong(expirience.ExpLocation[0], expirience.ExpLocation[1])).city, + ...expirience, }) } return items } + +export const getExpiriencesAsStore = () => { + const store = writable([]) + const loading = writable(true) + databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpApproved', true)]).then(async ({ documents }) => { + let items: Array = [] + for (const expirience of documents) { + items.push({ + city: (await getLocationDataFromLatAndLong(expirience.ExpLocation[0], expirience.ExpLocation[1])).city, + ...expirience, + }) + } + loading.set(false) + store.set(items) + }) + + return [store, loading] as const +} diff --git a/src/routes/homepage/Components/Comparment.svelte b/src/routes/homepage/Components/Comparment.svelte index c00e3e7..76f4182 100644 --- a/src/routes/homepage/Components/Comparment.svelte +++ b/src/routes/homepage/Components/Comparment.svelte @@ -13,7 +13,7 @@
{#each items as item} - navigate(`${item.link}`)} price={item.price} location={item.location} name={item.name} image={item.image} /> + navigate(`${item.ExpURL}`)} price={item.price} location={item.location} name={item.ExpName} image={item.image} /> {/each}
diff --git a/src/routes/map/map.svelte b/src/routes/map/map.svelte index c64de74..c6fc73f 100644 --- a/src/routes/map/map.svelte +++ b/src/routes/map/map.svelte @@ -2,6 +2,9 @@ import NavigationBarLayout from '$lib/components/Layouts/NavigationBarLayout.svelte' import Erantmap from '$lib/components/Map/Erantmap.svelte' import LocationRequest from '$lib/components/Map/LocationRequest.svelte' + import Marker from '$lib/components/Map/Marker.svelte' + import { navigate } from '$lib/router' + import { getExpiriencesAsStore } from '$lib/utils/database/game' import { onMount } from 'svelte' let user: { lat: number; lng: number } = { lat: 0, lng: 0 } @@ -14,28 +17,19 @@ granted = true } - onMount(() => { - if ('permissions' in navigator) { - navigator.permissions.query({ name: 'geolocation' }).then((permissionStatus) => { - if (permissionStatus.state === 'granted') { - navigator.geolocation.getCurrentPosition( - (position) => { - handleLocationGranted(position) - }, - (error) => { - console.log(error) - }, - ) - } - }) - } - }) + navigator.geolocation.getCurrentPosition(handleLocationGranted) + + $: [experiences] = getExpiriencesAsStore() {#if granted} - + + {#each $experiences as experience} + navigate(`/${experience.ExpURL}`)} lat={experience.ExpLocation[0]} lng={experience.ExpLocation[1]} {user} /> + {/each} + {:else} (granted = true)} />