Withdrew duplicate code and wrote a mixin for it.

This commit is contained in:
elweyn 2021-10-27 15:37:04 +02:00
parent 183d25dde4
commit c0fc927c23
3 changed files with 23 additions and 34 deletions

View File

@ -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)
})
}
},
}

View File

@ -62,7 +62,8 @@
<script> <script>
import InputPassword from '../../components/Inputs/InputPassword' import InputPassword from '../../components/Inputs/InputPassword'
import InputEmail from '../../components/Inputs/InputEmail' import InputEmail from '../../components/Inputs/InputEmail'
import { login, communityInfo } from '../../graphql/queries' import { login } from '../../graphql/queries'
import { getCommunityInfo } from '../../mixin/getCommunityInfo'
export default { export default {
name: 'login', name: 'login',
@ -70,6 +71,7 @@ export default {
InputPassword, InputPassword,
InputEmail, InputEmail,
}, },
mixins: [getCommunityInfo],
data() { data() {
return { return {
form: { form: {
@ -107,21 +109,6 @@ export default {
this.$toasted.error(this.$t('error.no-account')) this.$toasted.error(this.$t('error.no-account'))
}) })
}, },
async onCreated() {
this.$apollo
.query({
query: communityInfo,
})
.then((result) => {
this.$store.commit('community', result.data.getCommunityInfo)
})
.catch((error) => {
this.$toasted.error(error.message)
})
},
},
created() {
this.onCreated()
}, },
} }
</script> </script>

View File

@ -161,11 +161,12 @@ import InputEmail from '../../components/Inputs/InputEmail.vue'
import InputPasswordConfirmation from '../../components/Inputs/InputPasswordConfirmation.vue' import InputPasswordConfirmation from '../../components/Inputs/InputPasswordConfirmation.vue'
import LanguageSwitchSelect from '../../components/LanguageSwitchSelect.vue' import LanguageSwitchSelect from '../../components/LanguageSwitchSelect.vue'
import { registerUser } from '../../graphql/mutations' import { registerUser } from '../../graphql/mutations'
import { communityInfo } from '../../graphql/queries' import { getCommunityInfo } from '../../mixin/getCommunityInfo'
export default { export default {
components: { InputPasswordConfirmation, InputEmail, LanguageSwitchSelect }, components: { InputPasswordConfirmation, InputEmail, LanguageSwitchSelect },
name: 'register', name: 'register',
mixins: [getCommunityInfo],
data() { data() {
return { return {
form: { form: {
@ -229,20 +230,6 @@ export default {
this.form.password.passwordRepeat = '' this.form.password.passwordRepeat = ''
this.language = '' 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: { computed: {
namesFilled() { namesFilled() {
@ -257,9 +244,6 @@ export default {
return this.form.email !== '' return this.form.email !== ''
}, },
}, },
created() {
this.onCreated()
},
} }
</script> </script>
<style></style> <style></style>