feat: sync user preferences (currency, locale) with Directus on login/logout

This commit is contained in:
2026-02-05 17:29:34 +01:00
parent 56cf5a63c3
commit 5c66ca28b9
4 changed files with 86 additions and 6 deletions

View File

@@ -46,13 +46,17 @@ class PageSettings extends HTMLElement {
})
// Language select
this.querySelector('#lang-select')?.addEventListener('change', (e) => {
this.querySelector('#lang-select')?.addEventListener('change', async (e) => {
i18n.setLocale(e.target.value)
// Save to user profile if logged in
if (this.isLoggedIn) {
await auth.updatePreferences({ preferred_locale: e.target.value })
}
})
// Currency select
this.querySelector('#currency-select')?.addEventListener('change', (e) => {
this.setCurrency(e.target.value)
this.querySelector('#currency-select')?.addEventListener('change', async (e) => {
await this.setCurrency(e.target.value)
this.showToast(t('settings.currencyChanged'))
})
@@ -103,9 +107,14 @@ class PageSettings extends HTMLElement {
return localStorage.getItem('dgray_currency') || 'USD'
}
setCurrency(currency) {
async setCurrency(currency) {
localStorage.setItem('dgray_currency', currency)
window.dispatchEvent(new CustomEvent('currency-changed', { detail: { currency } }))
// Save to user profile if logged in
if (auth.isLoggedIn()) {
await auth.updatePreferences({ preferred_currency: currency })
}
}
showToast(message) {