fast loading game

This commit is contained in:
Ota Prokopec 2023-03-06 20:36:07 +01:00
parent e17d54d995
commit f9b0244ca3
3 changed files with 14 additions and 6 deletions

View File

@ -8,7 +8,7 @@
<div class="h-full w-full overflow-auto"> <div class="h-full w-full overflow-auto">
<section class="wraper"> <section class="wraper">
{#if img} {#if img}
<img src={img} {alt} /> <img class="h-auto w-full min-h-[400px]" src={img} {alt} />
{/if} {/if}
{#if shareData !== null && shareData !== false} {#if shareData !== null && shareData !== false}
<div class="shareButton"> <div class="shareButton">

View File

@ -3,17 +3,21 @@ import { Query } from 'appwrite'
import database from 'svelte-appwrite-client/src/lib/database' import database from 'svelte-appwrite-client/src/lib/database'
import { getLocationDataFromLatAndLong } from '../locations' import { getLocationDataFromLatAndLong } from '../locations'
export const load = async (pathName: string) => { export const load = async (pathName: string, previewQuestionsCount?: number, preview?: Function) => {
const checkPoints = [] const checkPoints = []
const game = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpURL', pathName)])).documents[0] const game = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpURL', pathName)])).documents[0]
const checkPointsIds = game.ExpCPsID const checkPointsIds = game.ExpCPsID
const rating = await getRating(game.$id)
for (const checkPointId of checkPointsIds) { for (const checkPointId of checkPointsIds) {
checkPoints.push(await databases.getDocument('63cef30d6da945dd4250', '63cef84d908acf805758', checkPointId)) checkPoints.push(await databases.getDocument('63cef30d6da945dd4250', '63cef84d908acf805758', checkPointId))
if (checkPointsIds.indexOf(checkPointId) === previewQuestionsCount - 1) {
game['rating'] = rating
game['checkPoints'] = checkPoints
preview(game)
}
} }
const rating = await getRating(game.$id)
console.log(rating)
game['rating'] = rating game['rating'] = rating
game['checkPoints'] = checkPoints game['checkPoints'] = checkPoints

View File

@ -26,9 +26,11 @@
let loading: boolean = true let loading: boolean = true
onMount(async () => { onMount(async () => {
$data = await load(params.gameurl) $data = await load(params.gameurl, 5, (preview) => {
$data = preview
loading = false loading = false
}) })
})
$: console.log($data) $: console.log($data)
$: assets = $data?.questions $: assets = $data?.questions
@ -38,6 +40,8 @@
let view: 'game-play' | 'game-loading' = 'game-loading' let view: 'game-play' | 'game-loading' = 'game-loading'
$: console.log($data?.ExpImage)
//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'