From 23ee6d75decfeb4e09b3feb48d5a013e8b9186ad Mon Sep 17 00:00:00 2001 From: paidge <paidge_cs@hotmail.com> Date: Sun, 30 Jan 2022 00:41:06 +0100 Subject: [PATCH] optimize computed variables --- graphql/queries.js | 4 ++-- pages/membre.vue | 58 ++++++++++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/graphql/queries.js b/graphql/queries.js index c15bb36..41b4f1c 100644 --- a/graphql/queries.js +++ b/graphql/queries.js @@ -79,7 +79,7 @@ export const NEWCOMERS = gql` } ` -// Pour la page membres/index +// Pour la page membre export const SEARCH_MEMBERS = gql` query SearchMember($hint: String) { idSearch(with: { hint: $hint }) { @@ -102,7 +102,7 @@ export const SEARCH_MEMBERS = gql` } ` -// Pour la page membres/_hash +// Pour la page membre export const SEARCH_MEMBER = gql` query SearchMemberWithHash($hash: Hash!) { idFromHash(hash: $hash) { diff --git a/pages/membre.vue b/pages/membre.vue index debc2bf..5ac2cfa 100644 --- a/pages/membre.vue +++ b/pages/membre.vue @@ -27,9 +27,9 @@ ['NEWCOMER', 'MISSING'].includes(idFromHash.status) && idFromHash.received_certifications.certifications.length < 5 }"> - {{ $t("certification.recues") }} ({{ nbCertifs("received") - }}<span v-if="nbCertifsPending('received') != 0">{{ - " + " + nbCertifsPending("received") + {{ $t("certification.recues") }} ({{ nbCertifsReceived + }}<span v-if="nbCertifsPendingReceived != 0">{{ + " + " + nbCertifsPendingReceived }}</span >) <BadgeDanger @@ -44,9 +44,9 @@ class="col-sm-10 col-md-7 col-lg-5 mx-auto" v-if="['MISSING', 'MEMBER'].includes(idFromHash.status)"> <h3 class="h4 text-center"> - {{ $t("certification.envoyees") }} ({{ nbCertifs("sent") - }}<span v-if="nbCertifsPending('sent') != 0">{{ - " + " + nbCertifsPending("sent") + {{ $t("certification.envoyees") }} ({{ nbCertifsSent + }}<span v-if="nbCertifsPendingSent != 0">{{ + " + " + nbCertifsPendingSent }}</span >) </h3> @@ -65,7 +65,7 @@ import { SEARCH_MEMBER } from "@/graphql/queries" export default { - name: 'membre', + name: "membre", data() { return { breadcrumb: [ @@ -85,28 +85,30 @@ export default { error: null } }, - methods: { - nbCertifs(sens) { - return sens == "received" - ? this.idFromHash.received_certifications.certifications.filter( - (el) => { - return el.pending == false - } - ).length - : this.idFromHash.sent_certifications.filter((el) => { - return el.pending == false - }).length + computed: { + nbCertifsSent() { + return this.idFromHash.sent_certifications.filter((el) => { + return el.pending == false + }).length + }, + nbCertifsReceived() { + return this.idFromHash.received_certifications.certifications.filter( + (el) => { + return el.pending == false + } + ).length }, - nbCertifsPending(sens) { - return sens == "received" - ? this.idFromHash.received_certifications.certifications.filter( - (el) => { - return el.pending == true - } - ).length - : this.idFromHash.sent_certifications.filter((el) => { - return el.pending == true - }).length + nbCertifsPendingSent() { + return this.idFromHash.sent_certifications.filter((el) => { + return el.pending == true + }).length + }, + nbCertifsPendingReceived() { + return this.idFromHash.received_certifications.certifications.filter( + (el) => { + return el.pending == true + } + ).length } }, apollo: { -- GitLab