add varibles object, add computed and watch currentPage

This commit is contained in:
ogerly 2022-03-16 11:02:26 +01:00
parent 90ce74a98c
commit 1a89d94bda

View File

@ -25,8 +25,9 @@
<b-collapse :class="visible ? 'bg-secondary' : ''" class="pb-4 pt-5" v-model="visible"> <b-collapse :class="visible ? 'bg-secondary' : ''" class="pb-4 pt-5" v-model="visible">
<collapse-links-list <collapse-links-list
v-model="variables"
:transactionLinkCount="transactionLinkCount"
:transactionLinks="transactionLinks" :transactionLinks="transactionLinks"
@update-list-transaction-links="updateListTransactionLinks"
/> />
</b-collapse> </b-collapse>
</div> </div>
@ -69,26 +70,50 @@ export default {
return { return {
visible: false, visible: false,
transactionLinks: [], transactionLinks: [],
variables: {
currentPage: 1,
pending: false,
pageSize: 5,
itemsShown: 0,
},
} }
}, },
methods: { methods: {
async updateListTransactionLinks() { async updateListTransactionLinks() {
this.$apollo if (this.currentPage === 0) {
.query({ this.transactionLinks = []
query: listTransactionLinks, this.variables.currentPage = 1
variables: { } else {
currentPage: 1, this.variables.pending = true
pageSize: 5, this.$apollo
}, .query({
fetchPolicy: 'network-only', query: listTransactionLinks,
}) variables: {
.then((result) => { currentPage: this.currentPage,
this.transactionLinks = result.data.listTransactionLinks },
this.$emit('update-transactions') fetchPolicy: 'network-only',
}) })
.catch((err) => { .then((result) => {
this.toastError(err.message) this.transactionLinks = [...this.transactionLinks, ...result.data.listTransactionLinks]
}) this.$emit('update-transactions')
this.variables.pending = false
this.variables.itemsShown = this.transactionLinks.length
})
.catch((err) => {
this.toastError(err.message)
this.variables.pending = false
})
}
},
},
computed: {
currentPage() {
return this.variables.currentPage
},
},
watch: {
currentPage() {
this.updateListTransactionLinks()
}, },
}, },
created() { created() {