Update categories, preferences, and experience, indentation, and other minor changes

Changes to be committed:
	modified:   package-lock.json
	modified:   package.json
	modified:   src/__routes.svelte
	renamed:    src/lib/components/Interests/category.svelte -> src/lib/components/Categories/category.svelte
	new file:   src/lib/components/Categories/category2InRow.svelte
	new file:   src/lib/components/Categories/category3InRow.svelte
	renamed:    src/lib/components/Interests/Interests.svelte -> src/lib/components/Categories/interests.svelte
	modified:   src/lib/router/Router.svelte
	renamed:    src/lib/stores/game.js -> src/lib/stores/stores.js
	modified:   src/lib/utils/IdGenerator.js
	modified:   src/lib/utils/api.js
	renamed:    src/lib/utils/database/game.ts -> src/lib/utils/database/experience.ts
	new file:   src/lib/utils/database/preferences.ts
	modified:   src/lib/utils/stores.js
	new file:   src/locales/cz.json
	new file:   src/locales/en.json
	new file:   src/locales/i18n.ts
	new file:   src/locales/languages.ts
	modified:   src/routes/authorization/register/register.svelte
	modified:   src/routes/explore/explore.svelte
	modified:   src/routes/game/Forms/MultiChoiceForm.svelte
	modified:   src/routes/game/Forms/NumberForm.svelte
	modified:   src/routes/game/Forms/Renderer.svelte
	modified:   src/routes/game/Forms/SingleChoiceForm.svelte
	modified:   src/routes/game/Forms/TextForm.svelte
	renamed:    src/routes/game/game.svelte -> src/routes/game/experience.svelte
	modified:   src/routes/homepage/homepage.svelte
	modified:   src/routes/map/map.svelte
	modified:   src/routes/onboarding/interestsPage.svelte
	modified:   src/routes/profile/functions/Interests-Update.svelte

 Changes not staged for commit:
	modified:   src/lib/utils/parseQuestion.js
This commit is contained in:
matthieu42morin 2023-03-20 08:44:21 +01:00
parent e9402c2825
commit 5e5c9eee93
30 changed files with 299 additions and 204 deletions

36
package-lock.json generated
View File

@ -39,9 +39,10 @@
"eslint-plugin-promise": "^6.1.1", "eslint-plugin-promise": "^6.1.1",
"flowbite-svelte": "^0.28.11", "flowbite-svelte": "^0.28.11",
"postcss": "^8.4.19", "postcss": "^8.4.19",
"sass": "^1.56.1", "sass": "^1.59.3",
"svelte": "^3.52.0", "svelte": "^3.52.0",
"svelte-preprocess": "^4.10.7", "svelte-preprocess": "^4.10.7",
"svelte-preprocess-sass": "^2.0.1",
"tailwindcss": "^3.2.4", "tailwindcss": "^3.2.4",
"typescript": "^4.9.5", "typescript": "^4.9.5",
"vite": "^3.2.3" "vite": "^3.2.3"
@ -5823,6 +5824,24 @@
} }
} }
}, },
"node_modules/svelte-preprocess-filter": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/svelte-preprocess-filter/-/svelte-preprocess-filter-1.0.0.tgz",
"integrity": "sha512-92innv59nyEx24xbfcSurB5ocwC8qFdDtGli/JVMHzJsxyvV2yjQKIcbUqU9VIV5mKUWO2PoY93nncS2yF4ULQ==",
"dev": true
},
"node_modules/svelte-preprocess-sass": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/svelte-preprocess-sass/-/svelte-preprocess-sass-2.0.1.tgz",
"integrity": "sha512-0y4FjRsRWcN7rJeNJnSfZ7LVAz6S7/j9Dg24XFRelr/rjMMjXORdEvXy4r38fUYmyk9Y7yjwlHCiqyGxMHhEbg==",
"dev": true,
"dependencies": {
"svelte-preprocess-filter": "^1.0.0"
},
"peerDependencies": {
"sass": "^1.35.2"
}
},
"node_modules/svelte-preprocess/node_modules/magic-string": { "node_modules/svelte-preprocess/node_modules/magic-string": {
"version": "0.25.9", "version": "0.25.9",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz",
@ -10417,6 +10436,21 @@
} }
} }
}, },
"svelte-preprocess-filter": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/svelte-preprocess-filter/-/svelte-preprocess-filter-1.0.0.tgz",
"integrity": "sha512-92innv59nyEx24xbfcSurB5ocwC8qFdDtGli/JVMHzJsxyvV2yjQKIcbUqU9VIV5mKUWO2PoY93nncS2yF4ULQ==",
"dev": true
},
"svelte-preprocess-sass": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/svelte-preprocess-sass/-/svelte-preprocess-sass-2.0.1.tgz",
"integrity": "sha512-0y4FjRsRWcN7rJeNJnSfZ7LVAz6S7/j9Dg24XFRelr/rjMMjXORdEvXy4r38fUYmyk9Y7yjwlHCiqyGxMHhEbg==",
"dev": true,
"requires": {
"svelte-preprocess-filter": "^1.0.0"
}
},
"svelte-routing": { "svelte-routing": {
"version": "1.6.0", "version": "1.6.0",
"resolved": "https://registry.npmjs.org/svelte-routing/-/svelte-routing-1.6.0.tgz", "resolved": "https://registry.npmjs.org/svelte-routing/-/svelte-routing-1.6.0.tgz",

View File

@ -22,9 +22,10 @@
"eslint-plugin-promise": "^6.1.1", "eslint-plugin-promise": "^6.1.1",
"flowbite-svelte": "^0.28.11", "flowbite-svelte": "^0.28.11",
"postcss": "^8.4.19", "postcss": "^8.4.19",
"sass": "^1.56.1", "sass": "^1.59.3",
"svelte": "^3.52.0", "svelte": "^3.52.0",
"svelte-preprocess": "^4.10.7", "svelte-preprocess": "^4.10.7",
"svelte-preprocess-sass": "^2.0.1",
"tailwindcss": "^3.2.4", "tailwindcss": "^3.2.4",
"typescript": "^4.9.5", "typescript": "^4.9.5",
"vite": "^3.2.3" "vite": "^3.2.3"

View File

@ -76,7 +76,7 @@
}, },
{ {
path: '/:gameurl', path: '/:gameurl',
component: () => import('$routes/game/game.svelte'), component: () => import('$root/src/routes/game/experience.svelte'),
}, },
{ {
path: '/terms-and-conditions', path: '/terms-and-conditions',

View File

@ -3,7 +3,7 @@
import collections from '$lib/collections' import collections from '$lib/collections'
import { Query } from 'appwrite' import { Query } from 'appwrite'
import { navigate } from 'svelte-routing' import { navigate } from 'svelte-routing'
import Category from "$lib/components/Interests/category.svelte"; import Category from "$lib/components/Categories/category.svelte";
export let current_state = 1 export let current_state = 1

View File

@ -33,3 +33,4 @@
{/if} {/if}
{/each} {/each}
</Router> </Router>

View File

@ -1,3 +1,3 @@
export const idGenerator = () => { export const idGenerator = () => {
return JSON.stringify(Date.now() * Math.floor(Math.random() * 100000)) return JSON.stringify(Date.now() * Math.floor(Math.random() * 100000))
} }

View File

@ -1,55 +1,55 @@
async function send({ method, path, body, token, headers }) { async function send ({ method, path, body, token, headers }) {
const opts = { method, headers: new Headers(), mode: 'cors' } const opts = { method, headers: new Headers(), mode: 'cors' }
opts.headers.append('Content-Type', 'application/json') opts.headers.append('Content-Type', 'application/json')
opts.headers.append('Access-Control-Allow-Origin', '*') opts.headers.append('Access-Control-Allow-Origin', '*')
if (body) { if (body) {
opts.body = JSON.stringify(body) opts.body = JSON.stringify(body)
} }
if (headers) { if (headers) {
for (const [k, v] of Object.entries(headers)) { for (const [k, v] of Object.entries(headers)) {
opts.headers.append(k, v) opts.headers.append(k, v)
} }
} }
if (token) { if (token) {
opts.headers['Authorization'] = `Bearer ${token}` opts.headers.Authorization = `Bearer ${token}`
} }
const res = fetch(path, opts) const res = fetch(path, opts)
.then(async (r) => { .then(async (r) => {
if (r.status >= 200 && r.status < 400) { if (r.status >= 200 && r.status < 400) {
return await r.text() return await r.text()
} else { } else {
return await r.text() return await r.text()
} }
}) })
.then((str) => { .then((str) => {
try { try {
return JSON.parse(str) return JSON.parse(str)
} catch (err) { } catch (err) {
return str return str
} }
}) })
return res return res
} }
export function get(path, token = null) { export function get (path, token = null) {
return send({ method: 'GET', path, body: null, token }) return send({ method: 'GET', path, body: null, token })
} }
export function del(path, token = null) { export function del (path, token = null) {
return send({ method: 'DELETE', path, body: null, token }) return send({ method: 'DELETE', path, body: null, token })
} }
export function post(path, body, token = null) { export function post (path, body, token = null) {
return send({ method: 'POST', path, body, token }) return send({ method: 'POST', path, body, token })
} }
export function put(path, body, token = null, headers = []) { export function put (path, body, token = null, headers = []) {
return send({ method: 'PUT', path, body, token, headers }) return send({ method: 'PUT', path, body, token, headers })
} }
export const hostName = 'https://erant.cz/api' export const hostName = 'https://erant.cz/api'

View File

@ -5,6 +5,7 @@ import { getLocationDataFromLatAndLong } from '../locations'
import { writable } from 'svelte/store' import { writable } from 'svelte/store'
import { CheckPoint, Experience } from '$lib/TStypes/experiences' import { CheckPoint, Experience } from '$lib/TStypes/experiences'
//Loading of checkpoints and rating is done in the same function to prevent multiple requests to the database
export const load = async (pathName: string, previewQuestionsCount?: number, preview?: Function) => { export const load = async (pathName: string, previewQuestionsCount?: number, preview?: Function) => {
const checkPoints: Array<CheckPoint> = [] const checkPoints: Array<CheckPoint> = []
// @ts-ignore // @ts-ignore
@ -30,13 +31,13 @@ export const load = async (pathName: string, previewQuestionsCount?: number, pre
return experience return experience
} }
//Fetch of Rating
const getRating = async (expId: string) => { const getRating = async (expId: string) => {
const { documents, total } = await databases.listDocuments('63cef30d6da945dd4250', '63ee6353ebb174cf815d', [Query.equal('ExpID', expId)]) const { documents, total } = await databases.listDocuments('63cef30d6da945dd4250', '63ee6353ebb174cf815d', [Query.equal('ExpID', expId)])
const sum = documents.reduce((accumulator, rating) => accumulator + rating.ExpUserRating, 0) const sum = documents.reduce((accumulator, rating) => accumulator + rating.ExpUserRating, 0)
return sum / total || 0 return sum / total || 0
} }
// Fetch of answers to the checkpoints
export const answer = async (checkPointId: string, answer: any) => { export const answer = async (checkPointId: string, answer: any) => {
const checkPoint = await databases.getDocument('63cef30d6da945dd4250', '63cef84d908acf805758', checkPointId) const checkPoint = await databases.getDocument('63cef30d6da945dd4250', '63cef84d908acf805758', checkPointId)
console.log({ checkPoint }) console.log({ checkPoint })
@ -46,29 +47,29 @@ export const answer = async (checkPointId: string, answer: any) => {
if (CPType === 'CHECKBOX') return JSON.stringify(answer) === JSON.stringify(correctAnswer) if (CPType === 'CHECKBOX') return JSON.stringify(answer) === JSON.stringify(correctAnswer)
if (CPType === 'RADIO' || CPType === 'NUMBER' || CPType === 'TEXT') return answer === correctAnswer[0] if (CPType === 'RADIO' || CPType === 'NUMBER' || CPType === 'TEXT') return answer === correctAnswer[0]
} }
// Fetch of all experiences
export const getExpiriences = async () => { export const getExperiences = async () => {
const expiriences = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpApproved', true)])).documents const experiences = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpApproved', true)])).documents
let items = [] let items = []
for (const expirience of expiriences) { for (const experience of experiences) {
items.push({ items.push({
city: (await getLocationDataFromLatAndLong(expirience.ExpLocation[0], expirience.ExpLocation[1])).city, city: (await getLocationDataFromLatAndLong(experience.ExpLocation[0], experience.ExpLocation[1])).city,
...expirience, ...experience,
}) })
} }
return items return items
} }
// Fetch of all experiences as store
export const getExpiriencesAsStore = () => { export const getExperiencesAsStore = () => {
const store = writable([]) const store = writable([])
const loading = writable<boolean>(true) const loading = writable<boolean>(true)
databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpApproved', true)]).then(async ({ documents }) => { databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpApproved', true)]).then(async ({ documents }) => {
let items: Array<any> = [] let items: Array<any> = []
for (const expirience of documents) { for (const experience of documents) {
items.push({ items.push({
city: (await getLocationDataFromLatAndLong(expirience.ExpLocation[0], expirience.ExpLocation[1])).city, city: (await getLocationDataFromLatAndLong(experience.ExpLocation[0], experience.ExpLocation[1])).city,
...expirience, ...experience,
}) })
} }
loading.set(false) loading.set(false)
@ -77,3 +78,10 @@ export const getExpiriencesAsStore = () => {
return [store, loading] as const return [store, loading] as const
} }
// !pridat trideni podle kategorie! export const getExperiencesByCategory = async (category: string) => {}

View File

@ -0,0 +1,25 @@
import { databases } from '$lib/appwrite';
import { Query } from 'appwrite';
export const getPreferences = async () => {
const { documents } = await databases.listDocuments('6417cf1de159d094b370', '6417cf29f2118829b3b4', [
Query.orderAsc('Name')
]);
const preferences = documents.map(({ Name, Image }) => ({ name: Name, img: Image }));
return preferences;
};
export const addSelectedPreferences = async (userId, preferences) => {
const { document: user } = await databases.getDocument('63ded6c18e8493bffc83', 'Users', userId);
const updatedUser = {
...user,
userPreferences: preferences
};
await databases.updateDocument('6417cf1de159d094b370', 'user-collection', user.$id, updatedUser);
return updatedUser;
};

View File

@ -2,82 +2,82 @@ import { writable } from 'svelte/store'
import * as api from './api' import * as api from './api'
class FetchArray extends Array { class FetchArray extends Array {
constructor(items, caller = () => null) { constructor (items, caller = () => null) {
super() super()
this.push(...items) this.push(...items)
this.caller = caller this.caller = caller
} }
setFetch(caller) { setFetch (caller) {
this.caller = caller this.caller = caller
return this return this
} }
fetch(fetchBody = {}, then = () => null) { fetch (fetchBody = {}, then = () => null) {
return this.caller(fetchBody, then) return this.caller(fetchBody, then)
} }
} }
export function fetchable(path, initBody = {}) { export function fetchable (path, initBody = {}) {
const { subscribe, set } = writable(null) const { subscribe, set } = writable(null)
return { return {
subscribe, subscribe,
fetch(fetchBody = {}, then = () => null) { fetch (fetchBody = {}, then = () => null) {
const body = Object.assign(initBody, fetchBody) const body = Object.assign(initBody, fetchBody)
api.post(path, body).then((result) => { api.post(path, body).then((result) => {
set(result) set(result)
then(result) then(result)
}) })
return this return this
} }
} }
} }
export function loadable(path, initBody = {}) { export function loadable (path, initBody = {}) {
const fetcher = fetchable(path, initBody) const fetcher = fetchable(path, initBody)
const fetchCaller = fetcher.fetch const fetchCaller = fetcher.fetch
const isFetching = writable(false) const isFetching = writable(false)
fetcher.fetch = (fetchBody = {}, then = () => null) => { fetcher.fetch = (fetchBody = {}, then = () => null) => {
isFetching.set(true) isFetching.set(true)
fetchCaller(fetchBody, (result) => { fetchCaller(fetchBody, (result) => {
isFetching.set(false) isFetching.set(false)
then(result) then(result)
}) })
return new FetchArray([fetcher, isFetching], fetcher.fetch) return new FetchArray([fetcher, isFetching], fetcher.fetch)
} }
return new FetchArray([fetcher, isFetching], fetcher.fetch) return new FetchArray([fetcher, isFetching], fetcher.fetch)
} }
export function mutable(path, callback = () => null) { export function mutable (path, callback = () => null) {
const isFetching = writable(false) const isFetching = writable(false)
const { subscribe, set } = writable(null) const { subscribe, set } = writable(null)
const mutateCall = async (fetchBody = {}) => { const mutateCall = async (fetchBody = {}) => {
isFetching.set(true) isFetching.set(true)
const result = await api.post(path, fetchBody) const result = await api.post(path, fetchBody)
set(result) set(result)
isFetching.set(false) isFetching.set(false)
return result return result
} }
return [ return [
{ {
subscribe, subscribe,
mutate(fetchBody = {}) { mutate (fetchBody = {}) {
callback(mutateCall, fetchBody) callback(mutateCall, fetchBody)
return this return this
} }
}, },
isFetching isFetching
] ]
} }

0
src/locales/cz.json Normal file
View File

13
src/locales/en.json Normal file
View File

@ -0,0 +1,13 @@
{
"page": {
"home": {
"title": "Discover the best Travel Experiences"
},
"Map": {
"title": "Map the best Travel Experiences"
},
"register": {
"title": "Register to the best Travel Experiences"
}
}
}

11
src/locales/i18n.ts Normal file
View File

@ -0,0 +1,11 @@
import { register, init, getLocaleFromNavigator, isLoading, locale, locales } from 'svelte-i18n'
import registers from './languages'
Object.entries(registers).forEach(([key, file]) => register(key, file))
export const i18n = () => init({
fallbackLocale: 'en',
initialLocale: getLocaleFromNavigator(),
})
export { isLoading, locale, locales }

4
src/locales/languages.ts Normal file
View File

@ -0,0 +1,4 @@
export default {
'en': () => import('./en.json'),
'cz': () => import('./cz.json')
}

View File

@ -10,11 +10,11 @@
import { Helper } from 'flowbite-svelte' import { Helper } from 'flowbite-svelte'
import Button from '$lib/components/Buttons/Button.svelte' import Button from '$lib/components/Buttons/Button.svelte'
let email = 'dfsafads' let email = ''
let password = 'aaaaaaaaa' let password = ''
let repeatPassword = 'aaaaaaaaa' let repeatPassword = ''
let name = 'fdsafsda' let name = ''
let erantId = 'dfsafdsa' let erantId = ''
let state: 'email-sent' | 'register' | 'loading' = 'register' let state: 'email-sent' | 'register' | 'loading' = 'register'
let error: string | null = null let error: string | null = null
@ -26,7 +26,7 @@
state = 'loading' state = 'loading'
error = null error = null
if (await getUserByErantId(erantId)) { if (await getUserByErantId(erantId)) {
const err = new Error('fdjsaůl') const err = new Error('Erant ID is already taken')
err['code'] = 1001 err['code'] = 1001
throw err throw err
} }
@ -54,8 +54,8 @@
<Helper class="ml-4" color="red">{error}</Helper> <Helper class="ml-4" color="red">{error}</Helper>
{/if} {/if}
<div class="inform"> <div class="inform">
<input bind:value={name} type="text" placeholder="Name" autocomplete="full-name" required /> <input bind:value={name} type="text" placeholder="Your name" autocomplete="full-name" required />
<input bind:value={email} type="text" placeholder="E-mail" autocomplete="email" required /> <input bind:value={email} type="text" placeholder="Your e-mail" autocomplete="email" required />
<input bind:value={erantId} type="text" placeholder="@your_nickname" autocomplete="email" required /> <input bind:value={erantId} type="text" placeholder="@your_nickname" autocomplete="email" required />
<HiddenInput bind:value={password} placeholder="Password" /> <HiddenInput bind:value={password} placeholder="Password" />
<HiddenInput bind:value={repeatPassword} placeholder="Re-type password" /> <HiddenInput bind:value={repeatPassword} placeholder="Re-type password" />

View File

@ -2,7 +2,7 @@
import NavigationBarLayout from '../../lib/components/Layouts/NavigationBarLayout.svelte' import NavigationBarLayout from '../../lib/components/Layouts/NavigationBarLayout.svelte'
import Result from './Components/Result.svelte' import Result from './Components/Result.svelte'
import Top from './Components/Top.svelte' import Top from './Components/Top.svelte'
import { getExpiriences } from '$lib/utils/database/game' import { getExperiences } from '$lib/utils/database/experience'
import Loading from '$lib/components/Common/Loading.svelte' import Loading from '$lib/components/Common/Loading.svelte'
let Search: string let Search: string
@ -12,7 +12,7 @@
<Top bind:search_value={Search} /> <Top bind:search_value={Search} />
<div class="results"> <div class="results">
{#await getExpiriences()} {#await getExperiences()}
<div class="w-full h-24 flex items-center justify-center"> <div class="w-full h-24 flex items-center justify-center">
<Loading /> <Loading />
</div> </div>

View File

@ -2,7 +2,7 @@
import Layout from '../Components/Layout.svelte' import Layout from '../Components/Layout.svelte'
import CheckBox from '../../../lib/components/Inputs/Checkbox.svelte' import CheckBox from '../../../lib/components/Inputs/Checkbox.svelte'
import { CheckPoint } from '$lib/TStypes/experiences' import { CheckPoint } from '$lib/TStypes/experiences'
import { answer } from '$lib/utils/database/game' import { answer } from '$lib/utils/database/experience'
export let data: { name: string; checkPoint: CheckPoint } export let data: { name: string; checkPoint: CheckPoint }
const { checkPoint, name } = data const { checkPoint, name } = data

View File

@ -2,7 +2,7 @@
import Layout from '../Components/Layout.svelte' import Layout from '../Components/Layout.svelte'
import Input from '../../../lib/components/Inputs/Input.svelte' import Input from '../../../lib/components/Inputs/Input.svelte'
import { CheckPoint } from '$lib/TStypes/experiences' import { CheckPoint } from '$lib/TStypes/experiences'
import { answer } from '$lib/utils/database/game' import { answer } from '$lib/utils/database/experience'
export let data: { name: string; checkPoint: CheckPoint } export let data: { name: string; checkPoint: CheckPoint }
const { checkPoint, name } = data const { checkPoint, name } = data

View File

@ -8,7 +8,7 @@
import IntervalForm from './IntervalForm.svelte' import IntervalForm from './IntervalForm.svelte'
import QrCode from './QrCode.svelte' import QrCode from './QrCode.svelte'
import Finish from './Finish.svelte' import Finish from './Finish.svelte'
import { data } from '$lib/stores/game' import { data } from '$lib/stores/stores'
import Erantmap from '$lib/components/Map/Erantmap.svelte' import Erantmap from '$lib/components/Map/Erantmap.svelte'
import Info from './Info.svelte' import Info from './Info.svelte'

View File

@ -2,7 +2,7 @@
import Radio from '../../../lib/components/Inputs/Radio.svelte' import Radio from '../../../lib/components/Inputs/Radio.svelte'
import Layout from '../Components/Layout.svelte' import Layout from '../Components/Layout.svelte'
import { CheckPoint } from '$lib/TStypes/experiences' import { CheckPoint } from '$lib/TStypes/experiences'
import { answer } from '$lib/utils/database/game' import { answer } from '$lib/utils/database/experience'
export let data: { name: string; checkPoint: CheckPoint } export let data: { name: string; checkPoint: CheckPoint }
const { checkPoint, name } = data const { checkPoint, name } = data

View File

@ -2,7 +2,7 @@
import Layout from '../Components/Layout.svelte' import Layout from '../Components/Layout.svelte'
import Input from '../../../lib/components/Inputs/Input.svelte' import Input from '../../../lib/components/Inputs/Input.svelte'
import { CheckPoint } from '$lib/TStypes/experiences' import { CheckPoint } from '$lib/TStypes/experiences'
import { answer } from '$lib/utils/database/game' import { answer } from '$lib/utils/database/experience'
export let data: { name: string; checkPoint: CheckPoint } export let data: { name: string; checkPoint: CheckPoint }
const { checkPoint, name } = data const { checkPoint, name } = data

View File

@ -6,7 +6,7 @@
import IconStar from '../../lib/svg/Star.svelte' import IconStar from '../../lib/svg/Star.svelte'
import IconPoint from '../../lib/svg/Point.svelte' import IconPoint from '../../lib/svg/Point.svelte'
import Loading from '../../lib/components/Common/Loading.svelte' import Loading from '../../lib/components/Common/Loading.svelte'
import { data } from '../../lib/stores/game' import { data } from '../../lib/stores/stores'
import GeolocateControl from '@beyonk/svelte-mapbox/src/lib/map/controls/GeolocateControl.svelte' import GeolocateControl from '@beyonk/svelte-mapbox/src/lib/map/controls/GeolocateControl.svelte'
import Map from '../../lib/components/Map/Map.svelte' import Map from '../../lib/components/Map/Map.svelte'
import Renderer from './Forms/Renderer.svelte' import Renderer from './Forms/Renderer.svelte'
@ -16,7 +16,7 @@
import collections from '$lib/collections' import collections from '$lib/collections'
import { Query } from 'appwrite' import { Query } from 'appwrite'
import { onMount } from 'svelte' import { onMount } from 'svelte'
import { load } from '$lib/utils/database/game' import { load } from '$lib/utils/database/experience'
import { getLocationDataFromLatAndLong } from '$lib/utils/locations' import { getLocationDataFromLatAndLong } from '$lib/utils/locations'
import { navigate } from '$lib/router' import { navigate } from '$lib/router'
@ -26,9 +26,9 @@
try { try {
$data = await load(params.gameurl, 5, (preview) => { $data = await load(params.gameurl, 5, (preview) => {
$data = preview $data = preview
view = 'game-preview' view = 'experience-preview'
}) })
view = 'game-preview' view = 'experience-preview'
} catch (error) { } catch (error) {
navigate('/error') navigate('/error')
} }
@ -39,19 +39,19 @@
?.slice(0, 8) ?.slice(0, 8)
?.map((q) => q.thumbnail)*/ ?.map((q) => q.thumbnail)*/
let view: 'game-play' | 'game-loading' | 'game-preview' = 'game-loading' let view: 'experience-play' | 'experience-loading' | 'experience-preview' = 'experience-loading'
//is user already in game //is user already in game
//const userInGame = JSON.parse(localStorage.getItem(location.pathname)) //const userInGame = JSON.parse(localStorage.getItem(location.pathname))
//$: if ($data && userInGame) view = 'game-play' //$: if ($data && userInGame) view = 'game-play'
</script> </script>
{#if view === 'game-loading'} {#if view === 'experience-loading'}
<h1 class="flex items-center justify-center flex-col"> <h1 class="flex items-center justify-center flex-col">
<span>Experience is loading...</span> <span>Experience is loading...</span>
<Loading /> <Loading />
</h1> </h1>
{:else if view === 'game-preview'} {:else if view === 'experience-preview'}
<Overlay shareData={{ url: window.location.href }} img={$data.ExpImage}> <Overlay shareData={{ url: window.location.href }} img={$data.ExpImage}>
<div> <div>
<span class="text-[36px]">{$data.ExpName}</span> <span class="text-[36px]">{$data.ExpName}</span>
@ -99,7 +99,7 @@
<Button on:click={() => (view = 'game-play')} primary>Hrát</Button> <Button on:click={() => (view = 'game-play')} primary>Hrát</Button>
{/if} {/if}
</Overlay> </Overlay>
{:else if view === 'game-play'} {:else if view === 'experience-play'}
<Renderer gameData={$data} /> <Renderer gameData={$data} />
{/if} {/if}

View File

@ -6,7 +6,7 @@
import Comparment from './Components/Comparment.svelte' //do budoucna bych to udělal pomocí komponent import Comparment from './Components/Comparment.svelte' //do budoucna bych to udělal pomocí komponent
import { onMount } from 'svelte' import { onMount } from 'svelte'
import Animation from './Components/Animation.svelte' import Animation from './Components/Animation.svelte'
import { getExpiriences } from '$lib/utils/database/game' import { getExperiences } from '$lib/utils/database/experience'
import Loading from '$lib/components/Common/Loading.svelte' import Loading from '$lib/components/Common/Loading.svelte'
let fitstTime = false let fitstTime = false
@ -45,12 +45,12 @@
<Categories /> <Categories />
{#await getExpiriences()} {#await getExperiences()}
<div class="w-full h-24 flex items-center justify-center"> <div class="w-full h-24 flex items-center justify-center">
<Loading /> <Loading />
</div> </div>
{:then expiriences} {:then experiences}
<Comparment items={expiriences} /> <Comparment items={experiences} />
{/await} {/await}
{:else} {:else}
<div class="content"> <div class="content">

View File

@ -4,7 +4,7 @@
import LocationRequest from '$lib/components/Map/LocationRequest.svelte' import LocationRequest from '$lib/components/Map/LocationRequest.svelte'
import Marker from '$lib/components/Map/Marker.svelte' import Marker from '$lib/components/Map/Marker.svelte'
import { navigate } from '$lib/router' import { navigate } from '$lib/router'
import { getExpiriencesAsStore } from '$lib/utils/database/game' import { getExpiriencesAsStore } from '$lib/utils/database/experience'
import { onMount } from 'svelte' import { onMount } from 'svelte'
let user: { lat: number; lng: number } = { lat: 0, lng: 0 } let user: { lat: number; lng: number } = { lat: 0, lng: 0 }

View File

@ -1,61 +1,59 @@
<!-- The InterestsPage component is responsible for displaying a list of categories that a user can select from -->
<script lang="ts"> <script lang="ts">
// Import necessary modules and components import Loading from './../../lib/components/Common/Loading.svelte';
import { user } from '$lib/appwrite'; // Import necessary modules and components
import collections from '$lib/collections'; import { user } from '$lib/appwrite';
import { Query } from 'appwrite'; import collections from '$lib/collections';
import { navigate } from 'svelte-routing'; import Loading from '$lib/components/Common/Loading.svelte';
import Category from "$lib/components/Interests/category.svelte"; import Category2InRow from '$lib/components/categories/Category2InRow.svelte';
import Category3InRow from '$lib/components/categories/Category3InRow.svelte';
// Define reactive variables using Svelte's $ syntax import { getPreferences, addSelectedPreferences } from '$lib/utils/database/preferences';
$: [userInfo] = collections.users.getDocument([Query.equal('userId', $user?.$id || '')]); import { navigate } from '$lib/router'
$: console.log($user); import { onMount } from 'svelte';
// Define a writable store to keep track of selected categories
import { writable } from 'svelte/store'; // Define a variable to store the preferences
const selectedCategories = writable([]); let preferences = [];
// Define a variable to store the selected preferences
// Define a function to toggle the selected state of a category let selectedPreferences = [];
const toggleSelected = (categoryName) => {
selectedCategories.update((categories) => { onMount(async () => {
if (categories.includes(categoryName)) { preferences = await getPreferences();
return categories.filter((name) => name !== categoryName); });
} else {
return [...categories, categoryName]; function updateSelectedPreferences(preference) {
} if (selectedPreferences.includes(preference)) {
}); selectedPreferences = selectedPreferences.filter((item) => item !== preference);
}; } else {
selectedPreferences = [...selectedPreferences, preference];
// Define a function to handle the form submission }
const handleSubmit = async () => { }
const { $id } = await collections.users.updateDocument(userInfo.$id, { // Define a function to handle the form submission
preferences: { async function submitPreferences() {
categories: $selectedCategories, await addSelectedPreferences(user, selectedPreferences);
}, selectedPreferences = [];
}); }
</script>
navigate(`/profile/${$id}`);
}; {#if preferences.length > 0}
</script> <div class="preferences-page">
<div class="progress-bar"></div>
<!-- Render each category as a Category component and pass its name, image, and selected state as props to the Category component. --> <h2>What are your interests?</h2>
{#await collections.categories.listDocuments()} <Category3InRow
<p>Loading...</p> preferences={preferences.slice(0, 3)}
{:then categories} on:preferenceSelect={updateSelectedPreferences}
{#each categories.data as category} />
<Category <h2>Who do you like to travel with?</h2>
name={category.name} <Category2InRow
image={category.image} preferences={preferences.slice(3, 5)}
selected={$selectedCategories.includes(category.name)} on:preferenceSelect={updateSelectedPreferences}
onToggle={() => toggleSelected(category.name)} />
/> <h2>What brought you to our app?</h2>
{/each} <Category3InRow
preferences={preferences.slice(5)}
<!-- Display a form with a button to submit the selected categories --> on:preferenceSelect={updateSelectedPreferences}
<form on:submit|preventDefault={handleSubmit}> />
<button type="submit">Save Preferences</button> <button on:click={submitPreferences}>Submit Preferences</button>
</form> </div>
{:catch error} {:else}
<p>Error: {error.message}</p> <Loading>
{/await} {/if}

View File

@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import Interests from "$lib/components/Interests/interests.svelte" import Interests from "$lib/components/Categories/interests.svelte"
let current_state = 1 let current_state = 1
</script> </script>