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