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>
import InputPassword from '../../components/Inputs/InputPassword'
import InputEmail from '../../components/Inputs/InputEmail'
import { login, communityInfo } from '../../graphql/queries'
import { login } from '../../graphql/queries'
import { getCommunityInfo } from '../../mixin/getCommunityInfo'
export default {
name: 'login',
@ -70,6 +71,7 @@ export default {
InputPassword,
InputEmail,
},
mixins: [getCommunityInfo],
data() {
return {
form: {
@ -107,21 +109,6 @@ export default {
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>

View File

@ -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()
},
}
</script>
<style></style>