From 010a5e426def0a0b7f2658234f3c9d6eec46a68e Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 23 Aug 2023 16:11:55 +0200 Subject: [PATCH] fix(front): fix changing language not being saved to the user's settings Signed-off-by: Thomas Citharel --- js/src/components/Settings/SettingsOnboarding.vue | 6 ++++-- js/src/composition/apollo/user.ts | 8 ++------ js/src/views/Settings/PreferencesView.vue | 9 ++++++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/js/src/components/Settings/SettingsOnboarding.vue b/js/src/components/Settings/SettingsOnboarding.vue index e9a489b7c..383d7d25f 100644 --- a/js/src/components/Settings/SettingsOnboarding.vue +++ b/js/src/components/Settings/SettingsOnboarding.vue @@ -70,14 +70,16 @@ const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; const { loggedUser } = useUserSettings(); +const { mutate: doUpdateLocale } = updateLocale(); + onMounted(() => { - updateLocale(locale as unknown as string); + doUpdateLocale({ locale: locale as unknown as string }); doUpdateSetting({ timezone }); }); watch(locale, () => { if (locale.value) { - updateLocale(locale.value as string); + doUpdateLocale({ locale: locale as unknown as string }); saveLocaleData(locale.value as string); } }); diff --git a/js/src/composition/apollo/user.ts b/js/src/composition/apollo/user.ts index 4e8128eb4..b1459ff2b 100644 --- a/js/src/composition/apollo/user.ts +++ b/js/src/composition/apollo/user.ts @@ -59,12 +59,8 @@ export async function doUpdateSetting( })); } -export async function updateLocale(locale: string) { - useMutation<{ id: string; locale: string }>(UPDATE_USER_LOCALE, () => ({ - variables: { - locale, - }, - })); +export function updateLocale() { + return useMutation<{ id: string; locale: string }>(UPDATE_USER_LOCALE); } export function registerAccount() { diff --git a/js/src/views/Settings/PreferencesView.vue b/js/src/views/Settings/PreferencesView.vue index 919131972..2be472a9e 100644 --- a/js/src/views/Settings/PreferencesView.vue +++ b/js/src/views/Settings/PreferencesView.vue @@ -47,6 +47,7 @@ @@ -147,7 +148,7 @@ import RouteName from "../../router/name"; import { AddressSearchType } from "@/types/enums"; import { Address, IAddress } from "@/types/address.model"; import { useTimezones } from "@/composition/apollo/config"; -import { useUserSettings } from "@/composition/apollo/user"; +import { useUserSettings, updateLocale } from "@/composition/apollo/user"; import { useHead } from "@vueuse/head"; import { computed, defineAsyncComponent, ref, watch } from "vue"; import { useI18n } from "vue-i18n"; @@ -172,6 +173,12 @@ useHead({ const theme = ref(localStorage.getItem("theme")); const systemTheme = ref(!("theme" in localStorage)); +const { mutate: doUpdateLocale } = updateLocale(); + +const updateLanguage = (newLocale: string) => { + doUpdateLocale({ locale: newLocale }); +}; + watch(systemTheme, (newSystemTheme) => { console.debug("changing system theme", newSystemTheme); if (newSystemTheme) {