Skip to content

Commit

Permalink
Fix some value handling in settings (#4644)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Jan 26, 2023
1 parent 560dbf9 commit 7e0c7fb
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions static/settings.ts
Expand Up @@ -459,29 +459,36 @@ export class Settings {
const themeSelect = this.root.find('.theme');
const colourSchemeSelect = this.root.find('.colourScheme');

const oldScheme = colourSchemeSelect.val();
const newTheme = unwrapString<colour.AppTheme>(themeSelect.val());
const oldScheme = colourSchemeSelect.val() as colour.AppTheme | undefined;
const newTheme = themeSelect.val() as colour.AppTheme | undefined;

// Small check to make sure we aren't getting something completely unexpected, like a string[] or number
assert(
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
isString(oldScheme) || oldScheme === undefined || oldScheme == null,
'Unexpected value received from colourSchemeSelect.val()'
);
assert(
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
isString(newTheme) || newTheme === undefined || newTheme == null,
'Unexpected value received from colourSchemeSelect.val()'
);

this.fillColourSchemeSelector(colourSchemeSelect, newTheme);
const newThemeStoredScheme = $.data(themeSelect, 'theme-' + newTheme) as colour.AppTheme | undefined;

// If nothing else, set the new scheme to the first of the available ones
let newScheme = unwrapString(colourSchemeSelect.first().val());
let newScheme = colourSchemeSelect.first().val() as colour.AppTheme | undefined;
// If we have one old one stored, check if it's still valid and set it if so
if (newThemeStoredScheme && this.selectorHasOption(colourSchemeSelect, newThemeStoredScheme)) {
newScheme = newThemeStoredScheme;
} else if (isString(oldScheme) && this.selectorHasOption(colourSchemeSelect, oldScheme)) {
newScheme = oldScheme;
}

colourSchemeSelect.val(newScheme);
if (newScheme) {
colourSchemeSelect.val(newScheme);
}

colourSchemeSelect.trigger('change');
}
Expand Down

0 comments on commit 7e0c7fb

Please sign in to comment.