gamebrary/src/pages/Language.vue

89 lines
2 KiB
Vue
Raw Normal View History

2020-08-31 21:34:32 +00:00
<template lang="html">
2020-09-26 00:09:20 +00:00
<b-container-fluid>
<b-jumbotron
header="Language"
header-level="5"
fluid
lead="Contributors wanted"
/>
2020-08-31 21:34:32 +00:00
2020-09-26 00:09:20 +00:00
<b-container>
<b-form-select v-model="language" class="mb-2 w-50">
2020-08-31 21:34:32 +00:00
<b-form-select-option
v-for="{ flag, code } in languages"
:key="code"
:value="code"
>
{{ flag }} {{ $t(`settings.languages.${code}`) }}
</b-form-select-option>
</b-form-select>
2020-09-26 00:09:20 +00:00
<br>
2020-08-31 21:34:32 +00:00
<b-button
:disabled="saving"
2020-09-26 00:09:20 +00:00
variant="primary"
2020-08-31 21:34:32 +00:00
@click="saveSettings"
>
<b-spinner small v-if="saving" />
<span v-else>Save and reload browser</span>
</b-button>
2020-09-26 00:09:20 +00:00
</b-container>
</b-container-fluid>
2020-08-31 21:34:32 +00:00
</template>
<script>
import { mapState } from 'vuex';
export default {
data() {
return {
saving: false,
languages: [
{ flag: '🇺🇸', code: 'en' },
{ flag: '🇪🇸', code: 'es' },
{ flag: '🇵🇱', code: 'pl' },
{ flag: '🇩🇪', code: 'de' },
{ flag: '🇦🇪', code: 'ar' },
{ flag: '🇫🇷', code: 'fr' },
{ flag: '🇯🇵', code: 'ja' },
{ flag: '🇮🇹', code: 'it' },
{ flag: '🇨🇿', code: 'cs' },
],
language: null,
};
},
computed: {
...mapState(['settings']),
},
2020-09-26 00:09:20 +00:00
mounted() {
const { settings } = this;
2020-08-31 21:34:32 +00:00
2020-09-26 00:09:20 +00:00
this.language = settings.language || 'en';
},
2020-08-31 21:34:32 +00:00
2020-09-26 00:09:20 +00:00
methods: {
2020-08-31 21:34:32 +00:00
saveSettings() {
const { language, settings } = this;
const payload = {
...settings,
language,
};
this.$store.dispatch('SAVE_SETTINGS', payload)
.then(() => {
this.$bvToast.toast('Settings saved', { title: 'Success', variant: 'success' });
location.reload();
})
.catch(() => {
this.$bvToast.toast('There was an error saving your settings', { title: 'Error', variant: 'danger' });
this.saving = false;
});
},
},
};
</script>