Skip to content

Commit

Permalink
fix(project-view): go offline while contributing
Browse files Browse the repository at this point in the history
refers #14
  • Loading branch information
ofr1tz committed Jun 4, 2024
1 parent ee16741 commit 4e30e98
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components/CompareProject.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default defineComponent({
created() {
this.startTime = new Date().toISOString()
this.taskId = this.tasks[this.taskIndex].taskId
this.$emit('created')
this.logMappingStarted(this.project.projectType)
},
})
Expand Down
1 change: 1 addition & 0 deletions src/components/DigitizeProject.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export default defineComponent({
this.taskId = this.tasks[this.taskIndex].taskId
this.updateTaskFeature()
if (this.tasks.length === 1) this.endReached = true
this.$emit('created')
this.logMappingStarted(this.project.projectType)
},
})
Expand Down
1 change: 1 addition & 0 deletions src/components/FindProject.vue
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export default defineComponent({
this.onResize()
},
created() {
this.$emit('created')
this.logMappingStarted(this.project.projectType)
},
})
Expand Down
1 change: 1 addition & 0 deletions src/components/MediaProject.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export default defineComponent({
created() {
this.startTime = new Date().toISOString()
this.taskId = this.tasks[this.taskIndex].taskId
this.$emit('created')
this.logMappingStarted(this.project.projectType)
},
})
Expand Down
1 change: 1 addition & 0 deletions src/components/ValidateProject.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default defineComponent({
this.startTime = new Date().toISOString()
this.taskId = this.tasks[this.taskIndex].taskId
this.updateTaskFeature()
this.$emit('created')
this.logMappingStarted(this.project.projectType)
},
})
Expand Down
2 changes: 1 addition & 1 deletion src/firebase/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const logAnalyticsEvent = (eventName, eventParams = {}) => {
}

// used for the database refs
const db = getDatabase(firebaseApp)
export const db = getDatabase(firebaseApp)

// export reusable database references
export const dbRef = ref(db)
Expand Down
18 changes: 16 additions & 2 deletions src/views/ProjectView.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts">
import { defineComponent } from 'vue'
import { onValue, set } from 'firebase/database'
import { goOffline, goOnline, off, onValue, set } from 'firebase/database'
import {
db,
getGroupsQuery,
getProjectRef,
getProjectContributionsRef,
Expand Down Expand Up @@ -58,6 +59,7 @@ export default defineComponent({
this.completedGroupId = this.group.groupId
goOnline(db)
set(getResultsRef(this.project.projectId, this.group.groupId, this.user.uid), entry)
.then(() => {
this.showSnackbar(
Expand Down Expand Up @@ -126,6 +128,7 @@ export default defineComponent({
(g) => g.requiredCount > 0 && !completed.includes(g.groupId),
)
if (!available.length) {
this.nextDialog = false
this.to = this.i18nRoute({ name: 'projects' })
this.showDialog(
this.$t('projectView.noTasksAvailable'),
Expand All @@ -134,6 +137,8 @@ export default defineComponent({
true,
false,
)
} else {
this.hideDialog()
}
const random = available[Math.floor(Math.random() * available.length)]
this.group = random
Expand Down Expand Up @@ -182,10 +187,15 @@ export default defineComponent({
if (!this.completedGroupId) {
return true
} else {
const updated = this.projectContributions[this.completedGroupId]
const updated =
this.projectContributions[this.completedGroupId] &&
this.completedGroupId !== this.group?.groupId
return updated
}
},
handleTaskComponentCreated() {
goOffline(db)
},
},
beforeRouteLeave(to, from, next) {
if (this.mode === 'contribute' && to.name !== 'authentication') {
Expand All @@ -197,6 +207,9 @@ export default defineComponent({
true,
)
} else {
off(getProjectRef(this.projectId))
off(getGroupsQuery(this.projectId))
off(getProjectContributionsRef(this.user.uid, this.projectId))
next()
}
},
Expand All @@ -219,6 +232,7 @@ export default defineComponent({
:options="options"
:project="project"
:tasks="tasks"
@created="handleTaskComponentCreated"
/>

<v-dialog v-model="nextDialog" max-width="600" persistent>
Expand Down

0 comments on commit 4e30e98

Please sign in to comment.