Skip to content

Commit

Permalink
Merge pull request #263 from codersforcauses/i188-display_message_whe…
Browse files Browse the repository at this point in the history
…n_challenge_is_achieved

I188 display message when challenge is achieved
  • Loading branch information
K-Straiton authored Jul 22, 2023
2 parents c99130d + 3d6feca commit c34babe
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
35 changes: 35 additions & 0 deletions client/src/components/ChallengeCompletePopupModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<template>
<v-dialog v-model="value" :fullscreen="isFullscreen" max-width="500">
<v-card>
<div style="height: 8px">
<v-img src="/images/Footer-min.jpeg" width="100%" alt="red background" cover />
</div>
<v-card-item class="d-flex justify-center">
<v-card-title class="d-flex justify-center"> Congratulations! </v-card-title>
<v-card-subtitle>You completed the {{ challengeName }} challenge!</v-card-subtitle>
</v-card-item>
<v-card-actions class="d-flex justify-end">
<v-btn @click="$emit('update:modelValue', !modelValue)">CLOSE</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
const isFullscreen = ref(false)
const emit = defineEmits(['update:modelValue'])
const props = defineProps(['modelValue', 'challengeName'])
const value = computed({
get() {
return props.modelValue
},
set(value) {
emit('update:modelValue', value)
}
})
</script>

<style scoped></style>
24 changes: 21 additions & 3 deletions client/src/views/DashboardView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
color="primaryRed"
@click="dialog = true"
/>
<MileageModal v-model="dialog" @handle-submit="updateChallengeProgress" />
<MileageModal v-model="dialog" @handle-submit="updateChallengeProgress(true)" />
</v-col>
</v-row>
</v-container>
Expand Down Expand Up @@ -71,19 +71,27 @@
<v-divider />
</v-container>
</div>

<ChallengeCompletePopupModalVue
v-model="isCompleted"
:challenge-name="challengeName"
></ChallengeCompletePopupModalVue>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import MileageModal from '../components/MileageModal.vue'
import { useUserStore } from '@/stores/user'
import { useMileageStore } from '@/stores/mileage'
import ChallengeCompletePopupModalVue from '@/components/ChallengeCompletePopupModal.vue'
const userStore = useUserStore()
const method = ref()
const loading = ref(true)
const user = ref()
const username = ref()
const isCompleted = ref(false)
const challengeName = ref('')
const getIconName = (medium: any) => {
switch (medium) {
Expand Down Expand Up @@ -125,8 +133,18 @@ function getRecentMileage() {
return 0
}
function updateChallengeProgress() {
function updateChallengeProgress(checkForCompletion: boolean) {
let oldDistance = distanceTravelled.value
distanceTravelled.value = getRecentMileage()
if (checkForCompletion) {
challenges.value.forEach((challenge) => {
if (oldDistance < challenge.length && distanceTravelled.value >= challenge.length) {
challengeName.value = challenge.name
isCompleted.value = true
}
})
}
}
onMounted(async () => {
Expand All @@ -136,7 +154,7 @@ onMounted(async () => {
username.value = user.value.username
getIconName(user.value.travelMethod)
await mileageStore.getRecentMileage(userStore.user.id)
updateChallengeProgress()
updateChallengeProgress(false)
} catch (error) {
console.log(error)
}
Expand Down

0 comments on commit c34babe

Please sign in to comment.