Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delete proof display #378

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/components/ProofDeleteChip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

<script>
import api from '../services/api'
import { useAppStore } from '../store'

export default {
props: {
Expand Down Expand Up @@ -75,14 +76,11 @@ export default {
// if response.status == 204
this.loading = false
this.deleteSuccessMessage = true
this.removeProofCard()
const store = useAppStore()
store.removeProof(this.proof.id)
this.closeDialog()
})
},
removeProofCard() {
const proofCardCol = document.getElementById(`proof_${this.proof.id}`)
proofCardCol.remove()
},
openDialog() {
this.dialog = true
},
Expand Down
17 changes: 17 additions & 0 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export const useAppStore = defineStore('app', {
recent_locations: [],
language: localStorage.getItem('user-locale') || import.meta.env.VITE_DEFAULT_LOCALE, // 'en'
country: import.meta.env.VITE_DEFAULT_COUNTRY, // 'FR',
proofs: [],
proofTotal: null,
},
}),
getters: {
Expand All @@ -31,6 +33,9 @@ export const useAppStore = defineStore('app', {
},
getUserCountry: (state) => {
return state.user.country
},
getUserProofTotal: (state) => {
return state.user.proofTotal
}
},
actions: {
Expand Down Expand Up @@ -59,6 +64,18 @@ export const useAppStore = defineStore('app', {
},
setCountry(country) {
this.user.country = country
},
setProofTotal(proofTotal) {
this.user.proofTotal = proofTotal
},
addProof(proof) {
if (!this.user.proofs.some(existingProof => existingProof.id === proof.id)) {
this.user.proofs.push(proof)
}
},
removeProof(proofId) {
this.user.proofs = this.user.proofs.filter(proof => proof.id !== proofId)
this.user.proofTotal -= 1
}
},
// pinia-plugin-persistedstate
Expand Down
13 changes: 6 additions & 7 deletions src/views/UserDashboardProofList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<v-row>
<v-col>
<v-chip class="mr-2" label variant="text" prepend-icon="mdi-tag-multiple-outline">
{{ $t('UserDashboard.UserProofTotal', { count: userProofTotal }) }}
{{ $t('UserDashboard.UserProofTotal', { count: this.appStore.getUserProofTotal }) }}
</v-chip>
<v-btn size="small" prepend-icon="mdi-arrow-left" to="/dashboard">
{{ $t('UserDashboard.Title') }}
Expand All @@ -22,12 +22,12 @@
</h2>

<v-row>
<v-col cols="12" sm="6" md="4" v-for="proof in userProofList" :key="proof">
<v-col cols="12" sm="6" md="4" v-for="proof in appStore.user.proofs" :key="proof">
<ProofCard :proof="proof" height="100%"></ProofCard>
</v-col>
</v-row>

<v-row v-if="userProofList.length < userProofTotal" class="mb-2">
<v-row v-if="this.appStore.user.proofs.length < this.appStore.getUserProofTotal" class="mb-2">
<v-col align="center">
<v-btn size="small" :loading="loading" @click="getUserProofs">{{ $t('UserDashboard.LoadMore') }}</v-btn>
</v-col>
Expand All @@ -46,8 +46,6 @@ export default {
},
data() {
return {
userProofList: [],
userProofTotal: null,
userProofPage: 0,
loading: false,
}
Expand All @@ -67,8 +65,9 @@ export default {
this.userProofPage += 1
return api.getProofs({ owner: this.username, page: this.userProofPage })
.then((data) => {
this.userProofList.push(...data.items)
this.userProofTotal = data.total
data.items.forEach(proof => this.appStore.addProof(proof))
this.appStore.user.proofs.sort((a, b) => new Date(b.created) - new Date(a.created))
this.appStore.setProofTotal(data.total)
this.loading = false
})
},
Expand Down
Loading