mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
Merge pull request #1991 from Human-Connection/Locale_save_by_change_LocalSwitch
Locale save by change local switch
This commit is contained in:
commit
a38731fcae
@ -37,6 +37,8 @@ import Dropdown from '~/components/Dropdown'
|
||||
import find from 'lodash/find'
|
||||
import orderBy from 'lodash/orderBy'
|
||||
import locales from '~/locales'
|
||||
import { mapGetters, mapMutations } from 'vuex'
|
||||
import { localeMutation } from '~/graphql/User.js'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@ -64,15 +66,44 @@ export default {
|
||||
})
|
||||
return routes
|
||||
},
|
||||
...mapGetters({
|
||||
currentUser: 'auth/user',
|
||||
}),
|
||||
},
|
||||
methods: {
|
||||
changeLanguage(locale, toggleMenu) {
|
||||
this.$i18n.set(locale)
|
||||
this.updateUserLocale()
|
||||
toggleMenu()
|
||||
},
|
||||
matcher(locale) {
|
||||
return locale === this.$i18n.locale()
|
||||
},
|
||||
|
||||
...mapMutations({
|
||||
setCurrentUser: 'auth/SET_USER',
|
||||
}),
|
||||
async updateUserLocale() {
|
||||
try {
|
||||
await this.$apollo.mutate({
|
||||
mutation: localeMutation(),
|
||||
variables: {
|
||||
id: this.currentUser.id,
|
||||
locale: this.$i18n.locale(),
|
||||
},
|
||||
update: (store, { data: { UpdateUser } }) => {
|
||||
const { locale } = UpdateUser
|
||||
this.setCurrentUser({
|
||||
...this.currentUser,
|
||||
locale,
|
||||
})
|
||||
},
|
||||
})
|
||||
this.$toast.success(this.$t('contribution.success'))
|
||||
} catch (err) {
|
||||
this.$toast.error(err.message)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -153,3 +153,14 @@ export const checkSlugAvailableQuery = gql`
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
export const localeMutation = () => {
|
||||
return gql`
|
||||
mutation($id: ID!, $locale: String) {
|
||||
UpdateUser(id: $id, locale: $locale) {
|
||||
id
|
||||
locale
|
||||
}
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user