Skip to content

Commit 1f6c921

Browse files
authored
Merge pull request #66 from mapswipe/fix-fetch-tutorial-tasks
Fix fetch tutorial tasks
2 parents 9a05e98 + 9d3a432 commit 1f6c921

File tree

9 files changed

+61
-176
lines changed

9 files changed

+61
-176
lines changed

src/components/CompareProject.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ export default defineComponent({
104104
type: Object as PropType<Tutorial>,
105105
required: false,
106106
},
107+
tutorialTasks: {
108+
type: Array as PropType<Task[]>,
109+
required: false,
110+
},
107111
},
108112
data(): {
109113
allAnswered: boolean
@@ -208,6 +212,7 @@ export default defineComponent({
208212
<template #tutorial>
209213
<compare-project-tutorial
210214
:tutorial="tutorial"
215+
:tasks="tutorialTasks"
211216
:options="options"
212217
@tutorialComplete="$refs.projectInfo?.toggleDialog"
213218
/>

src/components/CompareProjectTutorial.vue

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
<script lang="ts">
22
import { defineComponent, type PropType } from 'vue'
3-
import { goOnline, onValue } from 'firebase/database'
4-
import { db, getTasksRef, getGroupsRef } from '@/firebase'
53
import matchIcon from '@/utils/matchIcon'
64
import OptionButtons from '@/components/OptionButtons.vue'
75
import { type Option } from '@/components/OptionButtons.vue'
86
import CompareProjectTask, { type Task } from '@/components/CompareProjectTask.vue'
97
import TutorialCompletionCard from './TutorialCompletionCard.vue'
108
import TaskProgress from '@/components/TaskProgress.vue'
11-
import { decompressTasks } from '@/utils/tasks'
129
import { isDefined } from '@/utils/common'
1310
1411
interface Screen {
@@ -41,16 +38,18 @@ export default defineComponent({
4138
type: Array as PropType<Option[]>,
4239
required: true,
4340
},
41+
tasks: {
42+
type: Array as PropType<Task[]>,
43+
required: true,
44+
},
4445
},
4546
data(): {
46-
tasks: Task[]
4747
currentTaskIndex: number
4848
results: Record<string, number>
4949
userAttempts: number
5050
answersRevealed: boolean
5151
} {
5252
return {
53-
tasks: [],
5453
currentTaskIndex: 0,
5554
results: {},
5655
userAttempts: 0,
@@ -136,37 +135,6 @@ export default defineComponent({
136135
},
137136
},
138137
methods: {
139-
fetchTutorialGroups() {
140-
if (this.tutorial?.projectId) {
141-
onValue(
142-
getGroupsRef(this.tutorial.projectId),
143-
(snapshot) => {
144-
const data = snapshot.val()
145-
const groupKeys = Object.keys(data)
146-
this.fetchTutorialProject(groupKeys[0])
147-
},
148-
(error) => {
149-
console.error('Error fetching tasks for the tutorial', error)
150-
},
151-
{ onlyOnce: true },
152-
)
153-
}
154-
},
155-
fetchTutorialProject(groupId: string | undefined) {
156-
if (this.tutorial?.projectId && groupId) {
157-
onValue(
158-
getTasksRef(this.tutorial.projectId, groupId),
159-
(snapshot) => {
160-
const data = snapshot.val()
161-
this.tasks = decompressTasks(data)
162-
},
163-
(error) => {
164-
console.error('Error fetching tasks for the tutorial', error)
165-
},
166-
{ onlyOnce: true },
167-
)
168-
}
169-
},
170138
nextTask() {
171139
if (!this.hasCompletedAllTasks) {
172140
this.currentTaskIndex += 1
@@ -186,10 +154,6 @@ export default defineComponent({
186154
},
187155
},
188156
emits: ['tutorialComplete'],
189-
mounted() {
190-
goOnline(db)
191-
this.fetchTutorialGroups()
192-
},
193157
})
194158
</script>
195159

src/components/FindProject.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ export default defineComponent({
5151
},
5252
tutorial: {
5353
type: Object,
54-
require: false,
54+
required: false,
55+
},
56+
tutorialTasks: {
57+
type: Array,
58+
required: false,
5559
},
5660
},
5761
data() {
@@ -385,6 +389,7 @@ export default defineComponent({
385389
<template #tutorial>
386390
<find-project-tutorial
387391
:tutorial="tutorial"
392+
:tasks="tutorialTasks"
388393
:options="options"
389394
@tutorialComplete="$refs.projectInfo?.toggleDialog"
390395
/>

src/components/FindProjectTutorial.vue

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
<script lang="ts">
22
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'
73
import matchIcon from '@/utils/matchIcon'
8-
94
import TaskProgress from '@/components/TaskProgress.vue'
105
import FindProjectTask, { type Option } from '@/components/FindProjectTask.vue'
116
import TutorialCompletionCard from './TutorialCompletionCard.vue'
@@ -51,17 +46,19 @@ export default defineComponent({
5146
type: Array as PropType<Option[]>,
5247
required: true,
5348
},
49+
tasks: {
50+
type: Array as PropType<Task[]>,
51+
required: true,
52+
},
5453
},
5554
data(): {
56-
tasks: Task[]
5755
currentTaskIndex: number
5856
results: Record<string, number>
5957
selectedTasks: Record<string, boolean>
6058
userAttempts: number
6159
answersRevealed: boolean
6260
} {
6361
return {
64-
tasks: [],
6562
currentTaskIndex: 0,
6663
results: {},
6764
selectedTasks: {},
@@ -177,46 +174,16 @@ export default defineComponent({
177174
},
178175
},
179176
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+
)
220187
},
221188
nextTask() {
222189
if (!this.hasCompletedAllTasks) {
@@ -283,9 +250,7 @@ export default defineComponent({
283250
},
284251
emits: ['tutorialComplete'],
285252
mounted() {
286-
goOnline(db)
287-
this.fetchTutorialGroups()
288-
// this.fetchTutorialProject();
253+
this.fillResults()
289254
},
290255
})
291256
</script>

src/components/StreetProject.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ export default defineComponent({
7171
type: Object,
7272
required: false,
7373
},
74+
tutorialTasks: {
75+
type: Array,
76+
required: false,
77+
},
7478
},
7579
data() {
7680
return {
@@ -156,6 +160,7 @@ export default defineComponent({
156160
<template #tutorial>
157161
<street-project-tutorial
158162
:tutorial="tutorial"
163+
:tasks="tutorialTasks"
159164
:options="options"
160165
@tutorialComplete="$refs.projectInfo?.toggleDialog"
161166
/>

src/components/StreetProjectTutorial.vue

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<script lang="ts">
22
import { defineComponent, type PropType } from 'vue'
3-
import { goOnline, onValue } from 'firebase/database'
4-
import { db, getTasksRef, getGroupsRef } from '@/firebase'
5-
import { decompressTasks } from '@/utils/tasks'
63
import matchIcon from '@/utils/matchIcon'
74
import OptionButtons from '@/components/OptionButtons.vue'
85
import TaskProgress from '@/components/TaskProgress.vue'
@@ -52,17 +49,19 @@ export default defineComponent({
5249
props: {
5350
tutorial: Object as PropType<Tutorial>,
5451
options: Array as PropType<Option[]>,
52+
tasks: {
53+
type: Array as PropType<Task[]>,
54+
required: true,
55+
},
5556
},
5657
data(): {
57-
tasks: Task[]
5858
currentTaskIndex: number
5959
results: Record<string, number>
6060
userAttempts: number
6161
answersRevealed: boolean
6262
isLoading: boolean
6363
} {
6464
return {
65-
tasks: [],
6665
currentTaskIndex: 0,
6766
results: {},
6867
userAttempts: 0,
@@ -148,38 +147,6 @@ export default defineComponent({
148147
},
149148
},
150149
methods: {
151-
fetchTutorialGroups() {
152-
if (this.tutorial?.projectId) {
153-
onValue(
154-
// FIXME: verify group id
155-
getGroupsRef(this.tutorial.projectId),
156-
(snapshot) => {
157-
const data = snapshot.val()
158-
const groupKeys = Object.keys(data)
159-
this.fetchTutorialProject(groupKeys[0])
160-
},
161-
(error) => {
162-
console.error('Error fetching tasks for the tutorial', error)
163-
},
164-
{ onlyOnce: true },
165-
)
166-
}
167-
},
168-
fetchTutorialProject(groupId: string | undefined) {
169-
if (this.tutorial?.projectId && groupId) {
170-
onValue(
171-
getTasksRef(this.tutorial.projectId, groupId),
172-
(snapshot) => {
173-
const data = snapshot.val()
174-
this.tasks = decompressTasks(data)
175-
},
176-
(error) => {
177-
console.error('Error fetching tasks for the tutorial', error)
178-
},
179-
{ onlyOnce: true },
180-
)
181-
}
182-
},
183150
nextTask() {
184151
if (!this.hasCompletedAllTasks) {
185152
this.currentTaskIndex += 1
@@ -199,10 +166,6 @@ export default defineComponent({
199166
},
200167
},
201168
emits: ['tutorialComplete'],
202-
mounted() {
203-
goOnline(db)
204-
this.fetchTutorialGroups()
205-
},
206169
})
207170
</script>
208171

src/components/ValidateProject.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ export default defineComponent({
7373
type: Object,
7474
require: false,
7575
},
76+
tutorialTasks: {
77+
type: Array,
78+
required: false,
79+
},
7680
},
7781
data() {
7882
return {
@@ -197,6 +201,7 @@ export default defineComponent({
197201
<template #tutorial>
198202
<validate-project-tutorial
199203
:tutorial="tutorial"
204+
:tasks="tutorialTasks"
200205
:options="options"
201206
@tutorialComplete="$refs.projectInfo?.toggleDialog"
202207
/>

0 commit comments

Comments
 (0)