From c0fc927c23f8cbb014e3434db649c772d5328cce Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 27 Oct 2021 15:37:04 +0200 Subject: [PATCH] Withdrew duplicate code and wrote a mixin for it. --- frontend/src/mixin/getCommunityInfo.js | 18 ++++++++++++++++++ frontend/src/views/Pages/Login.vue | 19 +++---------------- frontend/src/views/Pages/Register.vue | 20 ++------------------ 3 files changed, 23 insertions(+), 34 deletions(-) create mode 100644 frontend/src/mixin/getCommunityInfo.js diff --git a/frontend/src/mixin/getCommunityInfo.js b/frontend/src/mixin/getCommunityInfo.js new file mode 100644 index 000000000..b3feb1267 --- /dev/null +++ b/frontend/src/mixin/getCommunityInfo.js @@ -0,0 +1,18 @@ +import { communityInfo } from '../graphql/queries' + +export const getCommunityInfo = { + created() { + if (!this.$store.state.community) { + this.$apollo + .query({ + query: communityInfo, + }) + .then((result) => { + this.$store.commit('community', result.data.getCommunityInfo) + }) + .catch((error) => { + this.$toasted.error(error.message) + }) + } + }, +} diff --git a/frontend/src/views/Pages/Login.vue b/frontend/src/views/Pages/Login.vue index 0cdbeb942..9b50c9d71 100755 --- a/frontend/src/views/Pages/Login.vue +++ b/frontend/src/views/Pages/Login.vue @@ -62,7 +62,8 @@ diff --git a/frontend/src/views/Pages/Register.vue b/frontend/src/views/Pages/Register.vue index d7909c964..29b1f7dfb 100755 --- a/frontend/src/views/Pages/Register.vue +++ b/frontend/src/views/Pages/Register.vue @@ -161,11 +161,12 @@ import InputEmail from '../../components/Inputs/InputEmail.vue' import InputPasswordConfirmation from '../../components/Inputs/InputPasswordConfirmation.vue' import LanguageSwitchSelect from '../../components/LanguageSwitchSelect.vue' import { registerUser } from '../../graphql/mutations' -import { communityInfo } from '../../graphql/queries' +import { getCommunityInfo } from '../../mixin/getCommunityInfo' export default { components: { InputPasswordConfirmation, InputEmail, LanguageSwitchSelect }, name: 'register', + mixins: [getCommunityInfo], data() { return { form: { @@ -229,20 +230,6 @@ export default { this.form.password.passwordRepeat = '' this.language = '' }, - async onCreated() { - if (!this.$state.store.community) { - this.$apollo - .query({ - query: communityInfo, - }) - .then((result) => { - this.$store.commit('community', result.data.getCommunityInfo) - }) - .catch((error) => { - this.$toasted.error(error.message) - }) - } - }, }, computed: { namesFilled() { @@ -257,9 +244,6 @@ export default { return this.form.email !== '' }, }, - created() { - this.onCreated() - }, }