History

fix(web): preserve theme when toggling advanced colors (#8500)

Wout Stiens committed 2 months ago

Commit 0222aa21 parent c0995d21 file · +9 −1Browse files

Unified · Split

apps/web/src/components/settings/ThemeEditorPanel.tsx+9−1
@@ -308,6 +308,7 @@ export function ThemeEditorPanel({ · 307 unmodified lines
308308 const [simpleColorsDirtyByAppearance, setSimpleColorsDirtyByAppearance] = useState<
309309 Record<ThemeAppearance, boolean>
310310 >({ light: false, dark: false });
311+ const [shouldRegenerateGuidedColors, setShouldRegenerateGuidedColors] = useState(false);
311312 const [error, setError] = useState<string | null>(null);
312313 const [isMinimized, setIsMinimized] = useState(false);
313314 const [roleQuery, setRoleQuery] = useState("");
@@ -401,6 +402,10 @@ export function ThemeEditorPanel({ · 87 unmodified lines
401402 // regenerate when the guided editor produced it.
402403 setIsAdvanced(sourceTheme !== null && sourceTheme.managed !== true);
403404 setSimpleColorsDirtyByAppearance({ light: false, dark: false });
405+ // An unmanaged palette needs conversion when the user opts into the
406+ // guided editor. Merely revealing Advanced for a managed/default draft
407+ // must stay read-only until a color changes.
408+ setShouldRegenerateGuidedColors(sourceTheme !== null && sourceTheme.managed !== true);
404409 setColorsByAppearance(nextColors);
405410 setSelectedRole(null);
406411 setUsageCount(null);
@@ -497,6 +502,7 @@ export function ThemeEditorPanel({ · 90 unmodified lines
497502 [activeAppearance]: true,
498503 }));
499504 }
505+ if (isAdvanced) setShouldRegenerateGuidedColors(true);
500506 },
501507 [activeAppearance, isAdvanced],
502508 );
@@ -735,6 +741,7 @@ export function ThemeEditorPanel({ · 232 unmodified lines
735741 if (selectedRole && !THEME_EDITOR_SIMPLE_ROLES.includes(selectedRole)) {
736742 setSelectedRole(null);
737743 }
744+ if (!shouldRegenerateGuidedColors) return;
738745
739746 // Regenerate every appearance the theme will save, not just the visible
740747 // one, so the palettes shown after toggling match what gets saved.
@@ -754,8 +761,9 @@ export function ThemeEditorPanel({ · 13 unmodified lines
754761 }
755762 return next;
756763 });
764+ setShouldRegenerateGuidedColors(false);
757765 },
758− [activeAppearance, editingTheme, selectedRole],
766+ [activeAppearance, editingTheme, selectedRole, shouldRegenerateGuidedColors],
759767 );
760768
761769 const handleSubmit = () => {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t