@@ -36,15 +36,15 @@ import { Theme, ThemesList } from "../constants/themes";
3636import { areSortedArraysEqual , areUnsortedArraysEqual } from "../utils/arrays" ;
3737import { LayoutName } from "@monkeytype/contracts/schemas/layouts" ;
3838
39- type SettingsGroups < T extends ConfigValue > = Record < string , SettingsGroup < T > > ;
39+ let settingsInitialized = false ;
4040
41+ type SettingsGroups < T extends ConfigValue > = Record < string , SettingsGroup < T > > ;
4142let customLayoutFluidSelect : SlimSelect | undefined ;
4243let customPolyglotSelect : SlimSelect | undefined ;
4344
4445export const groups : SettingsGroups < ConfigValue > = { } ;
4546
4647async function initGroups ( ) : Promise < void > {
47- await UpdateConfig . loadPromise ;
4848 groups [ "smoothCaret" ] = new SettingsGroup (
4949 "smoothCaret" ,
5050 UpdateConfig . setSmoothCaret ,
@@ -141,15 +141,7 @@ async function initGroups(): Promise<void> {
141141 groups [ "showKeyTips" ] = new SettingsGroup (
142142 "showKeyTips" ,
143143 UpdateConfig . setKeyTips ,
144- "button" ,
145- undefined ,
146- ( ) => {
147- if ( Config . showKeyTips ) {
148- $ ( ".pageSettings .tip" ) . removeClass ( "hidden" ) ;
149- } else {
150- $ ( ".pageSettings .tip" ) . addClass ( "hidden" ) ;
151- }
152- }
144+ "button"
153145 ) as SettingsGroup < ConfigValue > ;
154146 groups [ "freedomMode" ] = new SettingsGroup (
155147 "freedomMode" ,
@@ -441,26 +433,10 @@ async function initGroups(): Promise<void> {
441433 ) as SettingsGroup < ConfigValue > ;
442434}
443435
444- function reset ( ) : void {
445- $ ( ".pageSettings .section.themes .favThemes.buttons" ) . empty ( ) ;
446- $ ( ".pageSettings .section.themes .allThemes.buttons" ) . empty ( ) ;
447- $ ( ".pageSettings .section.themes .allCustomThemes.buttons" ) . empty ( ) ;
448- $ ( ".pageSettings .section[data-config-name='funbox'] .buttons" ) . empty ( ) ;
449- for ( const select of document . querySelectorAll ( ".pageSettings select" ) ) {
450- //@ts -expect-error slim gets added to the html element but ts doesnt know about it
451- // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
452- select ?. slim ?. destroy ?.( ) ;
453- }
454- }
455-
456- let groupsInitialized = false ;
457436async function fillSettingsPage ( ) : Promise < void > {
458- if ( Config . showKeyTips ) {
459- $ ( ".pageSettings .tip" ) . removeClass ( "hidden" ) ;
460- } else {
461- $ ( ".pageSettings .tip" ) . addClass ( "hidden" ) ;
437+ if ( settingsInitialized ) {
438+ return ;
462439 }
463-
464440 // Language Selection Combobox
465441
466442 const { data : languageGroups , error : getLanguageGroupsError } =
@@ -651,18 +627,13 @@ async function fillSettingsPage(): Promise<void> {
651627 } ) ;
652628
653629 setEventDisabled ( true ) ;
654- if ( ! groupsInitialized ) {
655- await initGroups ( ) ;
656- groupsInitialized = true ;
657- } else {
658- for ( const groupKey of Object . keys ( groups ) ) {
659- groups [ groupKey ] ?. updateUI ( ) ;
660- }
661- }
662- setEventDisabled ( false ) ;
630+
631+ await initGroups ( ) ;
663632 await ThemePicker . refreshCustomButtons ( ) ;
664633 await ThemePicker . refreshPresetButtons ( ) ;
665- await UpdateConfig . loadPromise ;
634+
635+ setEventDisabled ( false ) ;
636+ settingsInitialized = true ;
666637}
667638
668639// export let settingsFillPromise = fillSettingsPage();
@@ -763,12 +734,15 @@ function refreshPresetsSettingsSection(): void {
763734 }
764735}
765736
766- export async function update ( groupUpdate = true ) : Promise < void > {
767- // Object.keys(groups).forEach((group) => {
768- if ( groupUpdate ) {
769- for ( const group of Object . keys ( groups ) ) {
770- groups [ group ] ?. updateUI ( ) ;
771- }
737+ export async function update ( ) : Promise < void > {
738+ if ( Config . showKeyTips ) {
739+ $ ( ".pageSettings .tip" ) . removeClass ( "hidden" ) ;
740+ } else {
741+ $ ( ".pageSettings .tip" ) . addClass ( "hidden" ) ;
742+ }
743+
744+ for ( const group of Object . keys ( groups ) ) {
745+ groups [ group ] ?. updateUI ( ) ;
772746 }
773747
774748 refreshTagsSettingsSection ( ) ;
@@ -1397,13 +1371,13 @@ export const page = new Page({
13971371 element : $ ( ".page.pageSettings" ) ,
13981372 path : "/settings" ,
13991373 afterHide : async ( ) : Promise < void > => {
1400- reset ( ) ;
14011374 Skeleton . remove ( "pageSettings" ) ;
14021375 } ,
14031376 beforeShow : async ( ) : Promise < void > => {
14041377 Skeleton . append ( "pageSettings" , "main" ) ;
1378+ await UpdateConfig . loadPromise ;
14051379 await fillSettingsPage ( ) ;
1406- await update ( false ) ;
1380+ await update ( ) ;
14071381 } ,
14081382} ) ;
14091383
0 commit comments