From aff5a1fa2d16ec8f18c6d21ebabba2048f4ab69a Mon Sep 17 00:00:00 2001 From: Nikola Stojanovic <68916411+dzonidoo@users.noreply.github.com> Date: Tue, 10 Dec 2024 22:15:52 +0100 Subject: [PATCH] Setting "Appearance" preferences in the user profile is not kept upon re-login (#4696) --- .../users/directives/UserPreferencesDirective.ts | 12 ++++++++++-- scripts/apps/users/views/user-preferences.html | 4 ++-- scripts/core/menu/menu.ts | 14 +++++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/scripts/apps/users/directives/UserPreferencesDirective.ts b/scripts/apps/users/directives/UserPreferencesDirective.ts index f1a1204c7e..69d097db25 100644 --- a/scripts/apps/users/directives/UserPreferencesDirective.ts +++ b/scripts/apps/users/directives/UserPreferencesDirective.ts @@ -48,7 +48,7 @@ export function UserPreferencesDirective( const NOTIFICATIONS_KEY = 'notifications'; scope.activeNavigation = null; - scope.activeTheme = localStorage.getItem('theme'); + scope.activeTheme = ''; const registeredNotifications: IExtensionActivationResult['contributions']['notifications'] = (() => { const result = {}; @@ -81,6 +81,14 @@ export function UserPreferencesDirective( scope.$applyAsync(); }; + scope.toggleUiTheme = function(theme) { + scope.activeTheme = theme; + if (orig['application:theme'] == null) { + orig['application:theme'] = {}; + } + orig['application:theme']['theme'] = theme; + }; + scope.toggleEmailNotification = function(notificationId: string) { scope.preferences[NOTIFICATIONS_KEY][notificationId].email = !scope.preferences[NOTIFICATIONS_KEY][notificationId].email; @@ -149,7 +157,6 @@ export function UserPreferencesDirective( preferencesService.desktopNotification.requestPermission(); } - localStorage.setItem('theme', scope.activeTheme); body.attr('data-theme', scope.activeTheme); notify.success(gettext('User preferences saved')); scope.cancel(); @@ -281,6 +288,7 @@ export function UserPreferencesDirective( } }); + scope.activeTheme = data['application:theme']?.['theme'] ?? 'light-ui'; // metadata service initialization is needed if its // values object is undefined or any of the needed // data buckets are missing in it diff --git a/scripts/apps/users/views/user-preferences.html b/scripts/apps/users/views/user-preferences.html index 6ec1f938e0..78eea376d8 100644 --- a/scripts/apps/users/views/user-preferences.html +++ b/scripts/apps/users/views/user-preferences.html @@ -308,7 +308,7 @@