From 8c4310e771f01e5f1b635fdc414c73d3401eb38d Mon Sep 17 00:00:00 2001 From: Gitea OpenCode Agent Date: Thu, 15 Oct 2026 11:03:08 +0000 Subject: [PATCH] Fix issue #47: Settings menu --- .../app/components/windows/SettingsWindow.vue | 48 +++-- frontend/app/services/WindowDefinitions.js | 9 +- tests/settings-window.test.js | 170 ++++++++++++++++++ 3 files changed, 211 insertions(+), 16 deletions(-) create mode 100644 tests/settings-window.test.js diff --git a/frontend/app/components/windows/SettingsWindow.vue b/frontend/app/components/windows/SettingsWindow.vue index 08ed765a..235dcef2 100644 --- a/frontend/app/components/windows/SettingsWindow.vue +++ b/frontend/app/components/windows/SettingsWindow.vue @@ -16,13 +16,6 @@ const data = props.data; const { locale } = useI18n(); - -const changeLocale = (lang) => { - console.log(lang); - locale.value = lang.code; - SetUserSetting('lang', lang.code); -} - const id = data.id; const rows = ref([{id: "account-settings", value: "settings.tabs.account-settings"}]); @@ -37,13 +30,40 @@ function getLocaleFromCode(code){ } } -const selectedLocale = ref(""); +// The language to show in the dropdown: always one Dragonroll offers, because a +// user that never picked one has none stored. +function localeToShow(code){ + return getLocaleFromCode(code) || locales[0]; +} + +// vue-i18n answers every translation with `SyntaxError: cannot support locale type` +// once it is given a locale it has no messages for, and the locale is global: putting +// a language that is not stored (the server answers `settings: undefined` for a user +// that never picked one) or one no longer offered took the settings window and the +// main menu behind it down (issue #47). Only known codes go into `locale`. +function applyLanguage(code){ + const stored = getLocaleFromCode(code); + if(!stored) return false; + locale.value = stored.code; + selectedLocale.value = stored; + return true; +} + +const selectedLocale = ref(localeToShow(locale.value)); + +const changeLocale = (lang) => { + if(!applyLanguage(lang?.code)) return; + SetUserSetting('lang', lang.code); +} + onBeforeMount(() => { - GetUserSetting('lang').then(value => { - locale.value = value; - selectedLocale.value = getLocaleFromCode(value); // Set selected in dropdown - }); - if(GetUser().admin) rows.value.push({ + // Set selected in dropdown. Without settings to read from the server the language + // Dragonroll is already showing stays the one on screen. + GetUserSetting('lang') + .then((value) => applyLanguage(value)) + .catch(() => {}); + + if(GetUser()?.admin) rows.value.push({ id: "site-administration", value: "settings.tabs.site-administration" }); @@ -78,7 +98,7 @@ function OpenManageAccounts(){ } const getLocaleName = (locale) => { - return locale.name; + return locale ? locale.name : ""; } diff --git a/frontend/app/services/WindowDefinitions.js b/frontend/app/services/WindowDefinitions.js index 5ca163d4..60fb27db 100644 --- a/frontend/app/services/WindowDefinitions.js +++ b/frontend/app/services/WindowDefinitions.js @@ -1,4 +1,4 @@ -import { ClearWindow, GetFirstWindowId } from './Windows' +import { ClearWindow, CreateWindow, GetFirstWindowId } from './Windows' /* Put here all dragonroll windows @@ -26,7 +26,12 @@ const defWindows = { settings: { title: "windows.settings", component: () => import('~/components/windows/SettingsWindow.vue'), - close: () => ClearWindow({type: 'settings'}), + // The settings window is only opened from the main menu, so closing it goes back + // there: CreateWindow leaves a window that is already open alone. + close: () => { + ClearWindow({ type: 'settings' }); + CreateWindow('main_menu'); + }, movable: true }, create_campaign: { diff --git a/tests/settings-window.test.js b/tests/settings-window.test.js new file mode 100644 index 00000000..22743e5c --- /dev/null +++ b/tests/settings-window.test.js @@ -0,0 +1,170 @@ +// Tests for the settings menu opened from the main menu (Syndria98/dragonroll#47): it used to show a +// "Syntax Error" instead of the menu, and the main menu did not come back after closing it. +// +// vue-i18n answers every translation with `SyntaxError: cannot support locale type` from the moment the +// locale it holds is something it has no messages for. The settings window put `GetUserSetting('lang')` +// straight into that locale, and for a user that never picked a language that is `undefined`: the server +// answers GET /user/get-settings with `settings: undefined`. The locale is global, so the one bad write +// broke every window on screen — the settings window and the main menu behind it. +// +// The repository root installs no dependencies, so the window's script is lifted out of its `