mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +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 find from 'lodash/find'
|
||||||
import orderBy from 'lodash/orderBy'
|
import orderBy from 'lodash/orderBy'
|
||||||
import locales from '~/locales'
|
import locales from '~/locales'
|
||||||
|
import { mapGetters, mapMutations } from 'vuex'
|
||||||
|
import { localeMutation } from '~/graphql/User.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -64,15 +66,44 @@ export default {
|
|||||||
})
|
})
|
||||||
return routes
|
return routes
|
||||||
},
|
},
|
||||||
|
...mapGetters({
|
||||||
|
currentUser: 'auth/user',
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
changeLanguage(locale, toggleMenu) {
|
changeLanguage(locale, toggleMenu) {
|
||||||
this.$i18n.set(locale)
|
this.$i18n.set(locale)
|
||||||
|
this.updateUserLocale()
|
||||||
toggleMenu()
|
toggleMenu()
|
||||||
},
|
},
|
||||||
matcher(locale) {
|
matcher(locale) {
|
||||||
return locale === this.$i18n.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>
|
</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