fast loading game
This commit is contained in:
parent
e17d54d995
commit
f9b0244ca3
|
@ -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">
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -26,8 +26,10 @@
|
||||||
let loading: boolean = true
|
let loading: boolean = true
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
$data = await load(params.gameurl)
|
$data = await load(params.gameurl, 5, (preview) => {
|
||||||
loading = false
|
$data = preview
|
||||||
|
loading = false
|
||||||
|
})
|
||||||
})
|
})
|
||||||
$: console.log($data)
|
$: console.log($data)
|
||||||
|
|
||||||
|
@ -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'
|
||||||
|
|
Loading…
Reference in New Issue