feat: sync user preferences (currency, locale) with Directus on login/logout
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user