mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-01 21:15:15 +08:00
fix(theme): wrong theme application during preview (@byseif21) (#6617)
### Description Closes #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
This commit is contained in:
parent
79cc330852
commit
9cd312ddf0
1 changed files with 15 additions and 6 deletions
|
|
@ -231,20 +231,27 @@ function updateFooterIndicator(nameOverride?: string): void {
|
|||
}
|
||||
}
|
||||
|
||||
type PreviewState = {
|
||||
theme: string;
|
||||
colors?: string[];
|
||||
} | null;
|
||||
|
||||
let previewState: PreviewState = null;
|
||||
|
||||
export function preview(
|
||||
themeIdentifier: string,
|
||||
customColorsOverride?: string[]
|
||||
): void {
|
||||
debouncedPreview(themeIdentifier, customColorsOverride);
|
||||
previewState = { theme: themeIdentifier, colors: customColorsOverride };
|
||||
debouncedPreview();
|
||||
}
|
||||
|
||||
const debouncedPreview = debounce<(t: string, c?: string[]) => void>(
|
||||
250,
|
||||
(themeIdenfitier, customColorsOverride) => {
|
||||
const debouncedPreview = debounce<() => void>(250, () => {
|
||||
if (previewState) {
|
||||
isPreviewingTheme = true;
|
||||
void apply(themeIdenfitier, customColorsOverride, true);
|
||||
void apply(previewState.theme, previewState.colors, true);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
async function set(
|
||||
themeIdentifier: string,
|
||||
|
|
@ -264,6 +271,8 @@ async function set(
|
|||
}
|
||||
|
||||
export async function clearPreview(applyTheme = true): Promise<void> {
|
||||
previewState = null;
|
||||
|
||||
if (isPreviewingTheme) {
|
||||
isPreviewingTheme = false;
|
||||
if (applyTheme) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue