From 1753ce0de43e615b6d179e36a6fda5017e824f8e Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Mon, 4 Jul 2022 16:38:56 +0200 Subject: [PATCH] Fix learningPath and topics loading --- client/src/stores/learningPath.ts | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/client/src/stores/learningPath.ts b/client/src/stores/learningPath.ts index 9c67480f..58e231c6 100644 --- a/client/src/stores/learningPath.ts +++ b/client/src/stores/learningPath.ts @@ -33,32 +33,28 @@ export const useLearningPathStore = defineStore({ if (this.learningPath) { this.learningPath.topics = []; this.learningPath.circles = []; - const emptyTopic: Topic = { - id: 0, - title: '', - slug: '', - type: 'learnpath.Topic', - translation_key: '', - is_visible: false, - circles: [] - } - let topic = Object.assign({}, emptyTopic); + + let topic: Topic | undefined; + this.learningPath.children.forEach((page) => { if (page.type === 'learnpath.Topic') { - if (topic.id !== 0) { + if (topic) { this.learningPath.topics.push(topic); } - topic = Object.assign({}, emptyTopic, page); + topic = Object.assign(page, {circles: []}); } if (page.type === 'learnpath.Circle') { const circle = Circle.fromJson(page); circle.parseCompletionData(completionData); - topic.circles.push(circle); + if (topic) { + topic.circles.push(circle); + } this.learningPath.circles.push(circle); } - this.learningPath.topics.push(topic); }) + this.learningPath.topics.push(topic); + console.log('#######################'); console.log(this.learningPath); } return this.learningPath;