Fix admin languages selection

Closes #515

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-03-04 15:49:35 +01:00
parent fba9ff4a62
commit 8cbc1e016d
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -71,7 +71,7 @@
{{ $t("Main languages you/your moderators speak") }}
</small>
<b-taginput
v-model="adminSettings.instanceLanguages"
v-model="instanceLanguages"
:data="filteredLanguages"
autocomplete
:open-on-focus="true"
@ -361,24 +361,23 @@ export default class Settings extends Vue {
RouteName = RouteName;
@Watch("languages")
setCorrectLanguagesNames(): void {
if (this.languages && this.adminSettings) {
this.adminSettings.instanceLanguages = this.adminSettings.instanceLanguages
.map((code) => this.languageForCode(code))
.filter((language) => language) as string[];
}
get instanceLanguages(): string[] {
const languageCodes = this.adminSettings.instanceLanguages || [];
return languageCodes
.map((code) => this.languageForCode(code))
.filter((language) => language) as string[];
}
set instanceLanguages(instanceLanguages: string[]) {
this.adminSettings.instanceLanguages = instanceLanguages
.map((language) => {
return this.codeForLanguage(language);
})
.filter((code) => code !== undefined) as string[];
}
async updateSettings(): Promise<void> {
const variables = { ...this.adminSettings };
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
variables.instanceLanguages = variables.instanceLanguages.map(
(language) => {
return this.codeForLanguage(language);
}
);
try {
await this.$apollo.mutate({
mutation: SAVE_ADMIN_SETTINGS,
@ -408,7 +407,7 @@ export default class Settings extends Vue {
: [];
}
codeForLanguage(language: string): string | undefined {
private codeForLanguage(language: string): string | undefined {
if (this.languages) {
const lang = this.languages.find(({ name }) => name === language);
if (lang) return lang.code;
@ -416,7 +415,7 @@ export default class Settings extends Vue {
return undefined;
}
languageForCode(codeGiven: string): string | undefined {
private languageForCode(codeGiven: string): string | undefined {
if (this.languages) {
const lang = this.languages.find(({ code }) => code === codeGiven);
if (lang) return lang.name;