blazing fast loading (experience)
This commit is contained in:
parent
029c7e183a
commit
3af85de747
|
@ -13,24 +13,19 @@ userStore.subscribe((res) => (user = res))
|
|||
|
||||
//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) => {
|
||||
const checkPoints: Array<CheckPoint> = []
|
||||
let checkPoints: Array<CheckPoint> = []
|
||||
// @ts-ignore
|
||||
const experience: Experience = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpURL', pathName)])).documents[0]
|
||||
|
||||
const checkPointsIds = experience.ExpCPsID
|
||||
const rating = await getRating(experience.$id)
|
||||
|
||||
for (const checkPointId of checkPointsIds) {
|
||||
try {
|
||||
// @ts-ignore
|
||||
checkPoints.push(await databases.getDocument('63cef30d6da945dd4250', '63cef84d908acf805758', checkPointId))
|
||||
if (checkPointsIds.indexOf(checkPointId) === previewQuestionsCount - 1) {
|
||||
checkPoints = (await databases.listDocuments('63cef30d6da945dd4250', '63cef84d908acf805758', [Query.equal('$id', experience.ExpCPsID)])).documents
|
||||
/*if (checkPointsIds.indexOf(checkPointId) === previewQuestionsCount - 1) {
|
||||
experience['rating'] = rating
|
||||
experience['checkPoints'] = checkPoints
|
||||
preview(experience)
|
||||
}
|
||||
} catch (error) {}
|
||||
}
|
||||
}*/
|
||||
|
||||
experience['rating'] = rating
|
||||
experience['checkPoints'] = checkPoints
|
||||
|
@ -40,7 +35,7 @@ export const load = async (pathName: string, previewQuestionsCount?: number, pre
|
|||
|
||||
export const loadAsStore = (pathName: string, previewQuestionsCount?: number, preview?: Function) => {
|
||||
const store = writable<Experience>(null)
|
||||
load(pathName, previewQuestionsCount, preview).then(experience => {
|
||||
load(pathName, previewQuestionsCount, preview).then((experience) => {
|
||||
store.set(experience)
|
||||
})
|
||||
return [store]
|
||||
|
@ -57,7 +52,6 @@ const getRating = async (expId: string) => {
|
|||
export const answer = async (experienceId: string, checkPointId: string, answer: any) => {
|
||||
try {
|
||||
const checkPoint = await databases.getDocument('63cef30d6da945dd4250', '63cef84d908acf805758', checkPointId)
|
||||
console.log({ checkPoint })
|
||||
const { CPType, CPAnswerID } = checkPoint
|
||||
const correctAnswer = CPType !== 'INFO' ? (await databases.getDocument('63cef30d6da945dd4250', '63dd5c2b764061e40025', CPAnswerID)).CPAnswer : true
|
||||
|
||||
|
@ -154,12 +148,12 @@ export const getUserProgressAsStore = (experienceId: string) => {
|
|||
return [store, loading] as const
|
||||
}
|
||||
|
||||
export const getExperienceIdByUrl = async(url: string) => {
|
||||
return (await databases.listDocuments("63cef30d6da945dd4250", "63cef4bd210fdf2e5888", [Query.equal("ExpURL", url)])).documents[0].$id
|
||||
export const getExperienceIdByUrl = async (url: string) => {
|
||||
return (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpURL', url)])).documents[0].$id
|
||||
}
|
||||
export const getExperienceIdByUrlAsStore = (url: string): [Writable<string>] => {
|
||||
const store = writable<string>(null)
|
||||
getExperienceIdByUrl(url).then(exp => store.set(exp))
|
||||
getExperienceIdByUrl(url).then((exp) => store.set(exp))
|
||||
return [store]
|
||||
}
|
||||
// !pridat trideni podle kategorie! export const getExperiencesByCategory = async (category: string) => {}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
await user.updateVerification(userId, secret)
|
||||
navigate(`/create/account/${params.erantId}`)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
navigate('/')
|
||||
}
|
||||
})()
|
||||
</script>
|
||||
|
|
|
@ -31,10 +31,8 @@
|
|||
|
||||
onMount(async () => {
|
||||
try {
|
||||
$gameData = await load(params.gameurl, (await getUserProgress(await getExperienceIdByUrl(params.gameurl))).length || 8, (preview) => {
|
||||
$gameData = preview
|
||||
$gameData = await load(params.gameurl)
|
||||
view = 'experience-preview'
|
||||
})
|
||||
} catch (error) {
|
||||
navigate('/error')
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue