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:
Seif Soliman 2025-06-23 16:01:25 +03:00 committed by GitHub
parent 79cc330852
commit 9cd312ddf0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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) {