Skip to content

Commit

Permalink
feat(displaypreferences): sync locale to server
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultNocchi committed Dec 17, 2020
1 parent e94d675 commit 6dc78e6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
12 changes: 11 additions & 1 deletion components/LocaleSwitcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@
v-for="(item, index) in $i18n.locales"
:key="index"
:input-value="item.code === $i18n.locale"
@click="$i18n.setLocale(item.code)"
@click="editCustomPref({ key: 'locale', value: item.code })"
>
<v-list-item-title>{{ item.name }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</template>
<script lang="ts">
import Vue from 'vue';
import { mapActions } from 'vuex';
export default Vue.extend({
methods: {
...mapActions('displayPreferences', ['editCustomPref'])
}
});
</script>
<style scoped>
.v-list {
max-height: 31em;
Expand Down
3 changes: 2 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ const config: NuxtConfig = {
defaultLocale: 'en',
vueI18n: {
fallbackLocale: 'en'
}
},
detectBrowserLanguage: { useCookie: false }
},
/*
** vuetify module configuration
Expand Down
8 changes: 6 additions & 2 deletions store/displayPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export interface DisplayPreferencesState extends DisplayPreferencesDto {
const defaultCustomPrefs: {
[key: string]: string;
} = {
darkMode: 'True'
darkMode: 'True',
locale: 'en'
};

const defaultState = (): DisplayPreferencesState => ({
Expand All @@ -23,6 +24,9 @@ const booleanToString = (value: boolean) => (value ? 'True' : 'False');
const updateMethods: { [key: string]: (value: string) => void } = {
darkMode: (value: string) => {
window.$nuxt.$vuetify.theme.dark = stringToBoolean(value);
},
locale: (value: string) => {
window.$nuxt.$i18n.setLocale(value);
}
};

Expand Down Expand Up @@ -179,7 +183,7 @@ export const actions: ActionTree<
{ key, value }: { key: string; value: string }
) {
commit('EDIT_CUSTOM_PREF', { pref: { key, value } });
await dispatch('pushState');
if (this.$auth.loggedIn) await dispatch('pushState');
},

/**
Expand Down

0 comments on commit 6dc78e6

Please sign in to comment.