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 1 commit
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 { useProofsStore } from '../store/proofs'

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 proofsStore = useProofsStore()
proofsStore.removeProof(this.proof.id)
this.closeDialog()
})
},
removeProofCard() {
const proofCardCol = document.getElementById(`proof_${this.proof.id}`)
proofCardCol.remove()
},
openDialog() {
this.dialog = true
},
Expand Down
18 changes: 18 additions & 0 deletions src/store/proofs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineStore } from 'pinia';
Copy link
Member

@raphodn raphodn Feb 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool to start storing data in the store ! Inspiration for #141 ^^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why in a seperate store ? Also, these are user proofs so could be under the user object, we could want to persist, and it avoid importing multiple stores, no ?

(sure in big apps they probably split stuff, but we don't need to introduce this complexity this soon, do we ?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea of this PR was also to start a discussion on separating stores, what should really be separated and how much data should be stored (if we do prices for example, there might be too much data).
I don't know the best practice, one thought was to have some kind of matching with backend models, so separate stores for User, Proof, Prices, Location, Stats...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can start the discussion once our store feels too big or complex ^^
I think we're far from that situation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned up to use the unique store. Should be ready to merge


export const useProofsStore = defineStore({
id: 'proofs',
state: () => ({
proofs: []
}),
actions: {
addProof(proof) {
if (!this.proofs.some(existingProof => existingProof.id === proof.id)) {
this.proofs.push(proof)
}
},
removeProof(proofId) {
this.proofs = this.proofs.filter(proof => proof.id !== proofId);
}
}
});
11 changes: 6 additions & 5 deletions src/views/UserDashboardProofList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 proofsStore.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.proofsStore.proofs.length < userProofTotal" class="mb-2">
<v-col align="center">
<v-btn size="small" :loading="loading" @click="getUserProofs">{{ $t('UserDashboard.LoadMore') }}</v-btn>
</v-col>
Expand All @@ -37,6 +37,7 @@
<script>
import { mapStores } from 'pinia'
import { useAppStore } from '../store'
import { useProofsStore } from '../store/proofs'
import api from '../services/api'
import ProofCard from '../components/ProofCard.vue'

Expand All @@ -46,14 +47,14 @@ export default {
},
data() {
return {
userProofList: [],
userProofTotal: null,
userProofPage: 0,
loading: false,
}
},
computed: {
...mapStores(useAppStore),
...mapStores(useProofsStore),
username() {
return this.appStore.user.username
},
Expand All @@ -67,8 +68,8 @@ 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.proofsStore.addProof(proof))
this.userProofTotal = this.proofsStore.proofs.length
this.loading = false
})
},
Expand Down
Loading