Skip to content

Commit 9cd312d

Browse files
authored
fix(theme): wrong theme application during preview (@byseif21) (monkeytypegame#6617)
### Description Closes monkeytypegame#6616 Changes: - Refactored theme preview state management to use a single state object - Removed redundant state variables - Maintained the same debouncing behavior for smooth scrolling
1 parent 79cc330 commit 9cd312d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

frontend/src/ts/controllers/theme-controller.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,27 @@ function updateFooterIndicator(nameOverride?: string): void {
231231
}
232232
}
233233

234+
type PreviewState = {
235+
theme: string;
236+
colors?: string[];
237+
} | null;
238+
239+
let previewState: PreviewState = null;
240+
234241
export function preview(
235242
themeIdentifier: string,
236243
customColorsOverride?: string[]
237244
): void {
238-
debouncedPreview(themeIdentifier, customColorsOverride);
245+
previewState = { theme: themeIdentifier, colors: customColorsOverride };
246+
debouncedPreview();
239247
}
240248

241-
const debouncedPreview = debounce<(t: string, c?: string[]) => void>(
242-
250,
243-
(themeIdenfitier, customColorsOverride) => {
249+
const debouncedPreview = debounce<() => void>(250, () => {
250+
if (previewState) {
244251
isPreviewingTheme = true;
245-
void apply(themeIdenfitier, customColorsOverride, true);
252+
void apply(previewState.theme, previewState.colors, true);
246253
}
247-
);
254+
});
248255

249256
async function set(
250257
themeIdentifier: string,
@@ -264,6 +271,8 @@ async function set(
264271
}
265272

266273
export async function clearPreview(applyTheme = true): Promise<void> {
274+
previewState = null;
275+
267276
if (isPreviewingTheme) {
268277
isPreviewingTheme = false;
269278
if (applyTheme) {

0 commit comments

Comments
 (0)