From 84706e430b0d6fda8f818e18e512f5126b10ea57 Mon Sep 17 00:00:00 2001 From: ogerly Date: Thu, 14 Jul 2022 11:50:17 +0200 Subject: [PATCH] add slot ContributionListItem.vue, add verifyLogin, update store for creation --- .../Contributions/ContributionForm.vue | 1 + .../Contributions/ContributionList.vue | 52 ++++++++++++- .../Contributions/ContributionListItem.vue | 73 +++++++++++++++++++ frontend/src/pages/Community.vue | 51 ++++++++++--- 4 files changed, 164 insertions(+), 13 deletions(-) create mode 100644 frontend/src/components/Contributions/ContributionListItem.vue diff --git a/frontend/src/components/Contributions/ContributionForm.vue b/frontend/src/components/Contributions/ContributionForm.vue index a788e1563..20d7ff921 100644 --- a/frontend/src/components/Contributions/ContributionForm.vue +++ b/frontend/src/components/Contributions/ContributionForm.vue @@ -57,6 +57,7 @@ {{ $t('contribution.submit') }} + {{ $store.state }} diff --git a/frontend/src/components/Contributions/ContributionList.vue b/frontend/src/components/Contributions/ContributionList.vue index e3dc41b5f..e7fc930e6 100644 --- a/frontend/src/components/Contributions/ContributionList.vue +++ b/frontend/src/components/Contributions/ContributionList.vue @@ -1,17 +1,65 @@ diff --git a/frontend/src/components/Contributions/ContributionListItem.vue b/frontend/src/components/Contributions/ContributionListItem.vue new file mode 100644 index 000000000..11cb2266e --- /dev/null +++ b/frontend/src/components/Contributions/ContributionListItem.vue @@ -0,0 +1,73 @@ + + diff --git a/frontend/src/pages/Community.vue b/frontend/src/pages/Community.vue index c639ec969..6db97b5a0 100644 --- a/frontend/src/pages/Community.vue +++ b/frontend/src/pages/Community.vue @@ -6,12 +6,15 @@ - - - - - + + @@ -20,7 +23,7 @@ import ContributionForm from '@/components/Contributions/ContributionForm.vue' import ContributionList from '@/components/Contributions/ContributionList.vue' import { createContribution } from '@/graphql/mutations' -import { listContributions } from '@/graphql/queries' +import { listContributions, verifyLogin } from '@/graphql/queries' export default { name: 'Community', @@ -30,9 +33,10 @@ export default { }, data() { return { + items: [], currentPage: 1, pageSize: 25, - items: [], + contributionCount: 0, } }, methods: { @@ -51,19 +55,24 @@ export default { .then((result) => { // console.log('result', result.data) this.toastSuccess(result.data) + this.updateListContributions({ + currentPage: this.currentPage, + pageSize: this.pageSize, + }) + this.verifyLogin() }) .catch((err) => { this.toastError(err.message) }) }, - getListContributions(data) { + async updateListContributions(pagination) { this.$apollo .query({ fetchPolicy: 'no-cache', query: listContributions, variables: { - currentPage: this.currentPage, - pageSize: this.pageSize, + currentPage: pagination.currentPage, + pageSize: pagination.pageSize, }, }) .then((result) => { @@ -71,6 +80,7 @@ export default { const { data: { listContributions }, } = result + this.contributionCount = listContributions.length this.items = listContributions // this.toastSuccess(result.data) }) @@ -78,9 +88,28 @@ export default { this.toastError(err.message) }) }, + verifyLogin() { + this.$apollo + .query({ + query: verifyLogin, + fetchPolicy: 'network-only', + }) + .then((result) => { + const { + data: { verifyLogin }, + } = result + this.$store.dispatch('login', verifyLogin) + }) + .catch(() => { + this.$emit('logout') + }) + }, }, created() { - this.getListContributions() + this.updateListContributions({ + currentPage: this.currentPage, + pageSize: this.pageSize, + }) }, }