fix(web): preserve theme when toggling advanced colors (#8500)
This commit is contained in:
1 parent
c0995d2eaf
commit
0222aa255d
1 file changed
+9
-1
@@ -308,6 +308,7 @@ export function ThemeEditorPanel({
|
||||
const [simpleColorsDirtyByAppearance, setSimpleColorsDirtyByAppearance] = useState<
|
||||
Record<ThemeAppearance, boolean>
|
||||
>({ light: false, dark: false });
|
||||
const [shouldRegenerateGuidedColors, setShouldRegenerateGuidedColors] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [isMinimized, setIsMinimized] = useState(false);
|
||||
const [roleQuery, setRoleQuery] = useState("");
|
||||
@@ -401,6 +402,10 @@ export function ThemeEditorPanel({
|
||||
// regenerate when the guided editor produced it.
|
||||
setIsAdvanced(sourceTheme !== null && sourceTheme.managed !== true);
|
||||
setSimpleColorsDirtyByAppearance({ light: false, dark: false });
|
||||
// An unmanaged palette needs conversion when the user opts into the
|
||||
// guided editor. Merely revealing Advanced for a managed/default draft
|
||||
// must stay read-only until a color changes.
|
||||
setShouldRegenerateGuidedColors(sourceTheme !== null && sourceTheme.managed !== true);
|
||||
setColorsByAppearance(nextColors);
|
||||
setSelectedRole(null);
|
||||
setUsageCount(null);
|
||||
@@ -497,6 +502,7 @@ export function ThemeEditorPanel({
|
||||
[activeAppearance]: true,
|
||||
}));
|
||||
}
|
||||
if (isAdvanced) setShouldRegenerateGuidedColors(true);
|
||||
},
|
||||
[activeAppearance, isAdvanced],
|
||||
);
|
||||
@@ -735,6 +741,7 @@ export function ThemeEditorPanel({
|
||||
if (selectedRole && !THEME_EDITOR_SIMPLE_ROLES.includes(selectedRole)) {
|
||||
setSelectedRole(null);
|
||||
}
|
||||
if (!shouldRegenerateGuidedColors) return;
|
||||
|
||||
// Regenerate every appearance the theme will save, not just the visible
|
||||
// one, so the palettes shown after toggling match what gets saved.
|
||||
@@ -754,8 +761,9 @@ export function ThemeEditorPanel({
|
||||
}
|
||||
return next;
|
||||
});
|
||||
setShouldRegenerateGuidedColors(false);
|
||||
},
|
||||
[activeAppearance, editingTheme, selectedRole],
|
||||
[activeAppearance, editingTheme, selectedRole, shouldRegenerateGuidedColors],
|
||||
);
|
||||
|
||||
const handleSubmit = () => {
|
||||
|
||||
Reference in new issue
Block a user