fix(theme): apply theme without saving (#6695)

pull/6728/head
Dakota Walsh 2022-04-06 09:08:35 +12:00 committed by GitHub
parent e1df46b92b
commit 3c98bf9a79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 23 deletions

View File

@ -13,35 +13,27 @@ export default class ThemeSettingsController {
this.setTheme = this.setTheme.bind(this); this.setTheme = this.setTheme.bind(this);
} }
/** Theme Settings Panel */ async setTheme(theme) {
async updateTheme() {
try { try {
if (theme === 'auto' || !theme) {
this.ThemeManager.autoTheme();
} else {
this.ThemeManager.setTheme(theme);
}
this.state.userTheme = theme;
await this.UserService.updateUserTheme(this.state.userId, this.state.userTheme); await this.UserService.updateUserTheme(this.state.userId, this.state.userTheme);
this.state.themeInProgress = false;
this.Notifications.success('Success', 'User theme successfully updated'); this.Notifications.success('Success', 'User theme successfully updated');
} catch (err) { } catch (err) {
this.Notifications.error('Failure', err, 'Unable to update user theme'); this.Notifications.error('Failure', err, 'Unable to update user theme');
} }
} }
setTheme(theme) {
if (theme === 'auto' || !theme) {
this.ThemeManager.autoTheme();
} else {
this.ThemeManager.setTheme(theme);
}
this.state.themeInProgress = true;
this.state.userTheme = theme;
}
$onInit() { $onInit() {
return this.$async(async () => { return this.$async(async () => {
this.state = { this.state = {
userId: null, userId: null,
userTheme: '', userTheme: '',
initTheme: '',
defaultTheme: 'auto', defaultTheme: 'auto',
themeInProgress: false,
}; };
this.state.availableThemes = [ this.state.availableThemes = [
@ -55,16 +47,9 @@ export default class ThemeSettingsController {
this.state.userId = await this.Authentication.getUserDetails().ID; this.state.userId = await this.Authentication.getUserDetails().ID;
const data = await this.UserService.user(this.state.userId); const data = await this.UserService.user(this.state.userId);
this.state.userTheme = data.UserTheme || this.state.defaultTheme; this.state.userTheme = data.UserTheme || this.state.defaultTheme;
this.state.initTheme = this.state.userTheme;
} catch (err) { } catch (err) {
this.Notifications.error('Failure', err, 'Unable to get user details'); this.Notifications.error('Failure', err, 'Unable to get user details');
} }
}); });
} }
$onDestroy() {
if (this.state.themeInProgress) {
this.ThemeManager.setTheme(this.state.initTheme);
}
}
} }

View File

@ -12,7 +12,6 @@
<form class="theme-panel"> <form class="theme-panel">
<!-- Theme Selector--> <!-- Theme Selector-->
<box-selector radio-name="'theme'" value="$ctrl.state.userTheme" options="$ctrl.state.availableThemes" on-change="($ctrl.setTheme)"></box-selector> <box-selector radio-name="'theme'" value="$ctrl.state.userTheme" options="$ctrl.state.availableThemes" on-change="($ctrl.setTheme)"></box-selector>
<button ng-click="$ctrl.updateTheme()" class="btn btn-primary btn-sm">Update theme</button>
<!-- !Theme --> <!-- !Theme -->
</form> </form>
</rd-widget-body> </rd-widget-body>