|
1 | 1 | <script lang="ts"> |
2 | 2 | import { defineComponent, type PropType } from 'vue' |
3 | | -import { goOnline, onValue } from 'firebase/database' |
4 | | -import { db, getTasksRef, getGroupsRef } from '@/firebase' |
5 | | -
|
6 | | -import { decompressTasks } from '@/utils/tasks' |
7 | 3 | import matchIcon from '@/utils/matchIcon' |
8 | | -
|
9 | 4 | import TaskProgress from '@/components/TaskProgress.vue' |
10 | 5 | import FindProjectTask, { type Option } from '@/components/FindProjectTask.vue' |
11 | 6 | import TutorialCompletionCard from './TutorialCompletionCard.vue' |
@@ -51,17 +46,19 @@ export default defineComponent({ |
51 | 46 | type: Array as PropType<Option[]>, |
52 | 47 | required: true, |
53 | 48 | }, |
| 49 | + tasks: { |
| 50 | + type: Array as PropType<Task[]>, |
| 51 | + required: true, |
| 52 | + }, |
54 | 53 | }, |
55 | 54 | data(): { |
56 | | - tasks: Task[] |
57 | 55 | currentTaskIndex: number |
58 | 56 | results: Record<string, number> |
59 | 57 | selectedTasks: Record<string, boolean> |
60 | 58 | userAttempts: number |
61 | 59 | answersRevealed: boolean |
62 | 60 | } { |
63 | 61 | return { |
64 | | - tasks: [], |
65 | 62 | currentTaskIndex: 0, |
66 | 63 | results: {}, |
67 | 64 | selectedTasks: {}, |
@@ -177,46 +174,16 @@ export default defineComponent({ |
177 | 174 | }, |
178 | 175 | }, |
179 | 176 | methods: { |
180 | | - fetchTutorialGroups() { |
181 | | - if (this.tutorial?.projectId) { |
182 | | - onValue( |
183 | | - // FIXME: verify group id |
184 | | - getGroupsRef(this.tutorial.projectId), |
185 | | - (snapshot) => { |
186 | | - const data = snapshot.val() |
187 | | - const groupKeys = Object.keys(data) |
188 | | - this.fetchTutorialProject(groupKeys[0]) |
189 | | - }, |
190 | | - (error) => { |
191 | | - console.error('Error fetching tasks for the tutorial', error) |
192 | | - }, |
193 | | - { onlyOnce: true }, |
194 | | - ) |
195 | | - } |
196 | | - }, |
197 | | - fetchTutorialProject(groupId: string | undefined) { |
198 | | - if (this.tutorial?.projectId && groupId) { |
199 | | - onValue( |
200 | | - getTasksRef(this.tutorial.projectId, groupId), |
201 | | - (snapshot) => { |
202 | | - const data = snapshot.val() |
203 | | - this.tasks = decompressTasks(data) |
204 | | - this.results = this.tasks.reduce( |
205 | | - (acc, val) => { |
206 | | - // Fill all the result with initial value |
207 | | - acc[val.taskId] = this.options[0].value |
208 | | -
|
209 | | - return acc |
210 | | - }, |
211 | | - {} as Record<string, number>, |
212 | | - ) |
213 | | - }, |
214 | | - (error) => { |
215 | | - console.error('Error fetching tasks for the tutorial', error) |
216 | | - }, |
217 | | - { onlyOnce: true }, |
218 | | - ) |
219 | | - } |
| 177 | + fillResults() { |
| 178 | + this.results = this.tasks.reduce( |
| 179 | + (acc, val) => { |
| 180 | + // Fill all the results with initial value |
| 181 | + acc[val.taskId] = this.options[0].value |
| 182 | +
|
| 183 | + return acc |
| 184 | + }, |
| 185 | + {} as Record<string, number>, |
| 186 | + ) |
220 | 187 | }, |
221 | 188 | nextTask() { |
222 | 189 | if (!this.hasCompletedAllTasks) { |
@@ -283,9 +250,7 @@ export default defineComponent({ |
283 | 250 | }, |
284 | 251 | emits: ['tutorialComplete'], |
285 | 252 | mounted() { |
286 | | - goOnline(db) |
287 | | - this.fetchTutorialGroups() |
288 | | - // this.fetchTutorialProject(); |
| 253 | + this.fillResults() |
289 | 254 | }, |
290 | 255 | }) |
291 | 256 | </script> |
|
0 commit comments