MCPcopy
hub / github.com/compiler-explorer/compiler-explorer / onThemeChange

Method onThemeChange

static/settings.ts:508–546  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

506 }
507
508 private onThemeChange() {
509 // We can be called when:
510 // Site is initializing (settings and dropdowns are already done)
511 // "Make all colour schemes available" changes
512 // Selected theme changes
513 const themeSelect = this.root.find('.theme');
514 const colourSchemeSelect = this.root.find('.colourScheme');
515
516 const oldScheme = colourSchemeSelect.val() as colour.AppTheme | undefined;
517 const newTheme = themeSelect.val() as colour.AppTheme | undefined;
518
519 // Small check to make sure we aren't getting something completely unexpected, like a string[] or number
520 assert(
521 isString(oldScheme) || oldScheme === undefined || oldScheme == null,
522 'Unexpected value received from colourSchemeSelect.val()',
523 );
524 assert(
525 isString(newTheme) || newTheme === undefined || newTheme == null,
526 'Unexpected value received from colourSchemeSelect.val()',
527 );
528
529 this.fillColourSchemeSelector(colourSchemeSelect, newTheme);
530 const newThemeStoredScheme = $.data(themeSelect, 'theme-' + newTheme) as colour.AppTheme | undefined;
531
532 // If nothing else, set the new scheme to the first of the available ones
533 let newScheme = colourSchemeSelect.first().val() as colour.AppTheme | undefined;
534 // If we have one old one stored, check if it's still valid and set it if so
535 if (newThemeStoredScheme && this.selectorHasOption(colourSchemeSelect, newThemeStoredScheme)) {
536 newScheme = newThemeStoredScheme;
537 } else if (isString(oldScheme) && this.selectorHasOption(colourSchemeSelect, oldScheme)) {
538 newScheme = oldScheme;
539 }
540
541 if (newScheme) {
542 colourSchemeSelect.val(newScheme);
543 }
544
545 colourSchemeSelect.trigger('change');
546 }
547}

Callers 1

handleThemesMethod · 0.95

Calls 8

selectorHasOptionMethod · 0.95
isStringFunction · 0.85
findMethod · 0.80
valMethod · 0.80
dataMethod · 0.80
firstMethod · 0.80
assertFunction · 0.70

Tested by

no test coverage detected