Skip to content

Commit

Permalink
Setting "Appearance" preferences in the user profile is not kept upon…
Browse files Browse the repository at this point in the history
… re-login (#4696)
  • Loading branch information
dzonidoo authored Dec 10, 2024
1 parent 07d5daf commit aff5a1f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
12 changes: 10 additions & 2 deletions scripts/apps/users/directives/UserPreferencesDirective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/apps/users/views/user-preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ <h4 class="sd-heading sd-text-align--left sd-text--sans sd-heading--h4 sd-margin
</svg>
</figure>
<div class="sd-theme-selector__item-action">
<input type="radio" class="sd-theme-selector__input" value="light-ui" ng-model="activeTheme" id="id390" tabindex="0" name="id39">
<input ng-change="toggleUiTheme('light-ui')" type="radio" class="sd-theme-selector__input" value="light-ui" ng-model="activeTheme" id="id390" tabindex="0" name="id39">
<span class="sd-radio-new"></span>
<label class="sd-theme-selector__label" for="id390">Light</label>
<span class="sd-theme-selector__label-text" aria-hidden="true">Light</span>
Expand Down Expand Up @@ -366,7 +366,7 @@ <h4 class="sd-heading sd-text-align--left sd-text--sans sd-heading--h4 sd-margin
</svg>
</figure>
<div class="sd-theme-selector__item-action">
<input type="radio" class="sd-theme-selector__input" value="dark-ui" ng-model="activeTheme" id="id391" tabindex="0" name="id39">
<input ng-change="toggleUiTheme('dark-ui')" type="radio" class="sd-theme-selector__input" value="dark-ui" ng-model="activeTheme" id="id391" tabindex="0" name="id39">
<span class="sd-radio-new"></span>
<label class="sd-theme-selector__label" for="id391">Dark</label>
<span class="sd-theme-selector__label-text" aria-hidden="true">Dark</span>
Expand Down
14 changes: 11 additions & 3 deletions scripts/core/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ angular.module('superdesk.core.menu', [
'lodash',
'workspaceMenu',
'$location',
'preferencesService',
function(
$route,
superdesk,
Expand All @@ -174,6 +175,7 @@ angular.module('superdesk.core.menu', [
_,
workspaceMenu,
$location,
preferencesService,
) {
return {
require: '^sdSuperdeskView',
Expand All @@ -184,13 +186,19 @@ angular.module('superdesk.core.menu', [
scope.currentRoute = null;
scope.flags = ctrl.flags;
scope.menu = [];
scope.theme = localStorage.getItem('theme') || '';
scope.theme = 'light-ui';
scope.isTestEnvironment = appConfig.isTestEnvironment;
scope.environmentName = appConfig.environmentName;
scope.workspaceConfig = appConfig.workspace || {}; // it's used in workspaceMenu.filter

// set theme
body.attr('data-theme', scope.theme);
preferencesService.get().then((result) => {
scope.theme = result['application:theme']?.['theme'] != null
? result['application:theme']['theme']
: 'light-ui';

// set theme
body.attr('data-theme', scope.theme);
});

// menu items and groups - start
let group = null;
Expand Down

0 comments on commit aff5a1f

Please sign in to comment.