@@ -6,6 +6,7 @@ import type { I_THEME_OPTION } from "@plane/constants";
66import { THEME_OPTIONS } from "@plane/constants" ;
77import { useTranslation } from "@plane/i18n" ;
88import { setPromiseToast } from "@plane/propel/toast" ;
9+ import { applyCustomTheme } from "@plane/utils" ;
910// components
1011import { CustomThemeSelector } from "@/components/core/theme/custom-theme-selector" ;
1112import { ThemeSwitch } from "@/components/core/theme/theme-switch" ;
@@ -34,26 +35,46 @@ export const ThemeSwitcher = observer(function ThemeSwitcher(props: {
3435 } , [ userProfile ?. theme ?. theme ] ) ;
3536
3637 const handleThemeChange = useCallback (
37- ( themeOption : I_THEME_OPTION ) => {
38+ async ( themeOption : I_THEME_OPTION ) => {
3839 try {
3940 setTheme ( themeOption . value ) ;
41+
42+ // If switching to custom theme and user has saved custom colors, apply them immediately
43+ if (
44+ themeOption . value === "custom" &&
45+ userProfile ?. theme ?. primary &&
46+ userProfile ?. theme ?. background &&
47+ userProfile ?. theme ?. darkPalette !== undefined
48+ ) {
49+ applyCustomTheme (
50+ userProfile . theme . primary ,
51+ userProfile . theme . background ,
52+ userProfile . theme . darkPalette ? "dark" : "light"
53+ ) ;
54+ }
55+
4056 const updatePromise = updateUserTheme ( { theme : themeOption . value } ) ;
4157 setPromiseToast ( updatePromise , {
4258 loading : "Updating theme..." ,
4359 success : {
44- title : "Success! " ,
45- message : ( ) => "Theme updated successfully! " ,
60+ title : "Theme updated " ,
61+ message : ( ) => "Reloading to apply changes... " ,
4662 } ,
4763 error : {
4864 title : "Error!" ,
49- message : ( ) => "Failed to update the theme" ,
65+ message : ( ) => "Failed to update theme. Please try again. " ,
5066 } ,
5167 } ) ;
68+ // Wait for the promise to resolve, then reload after showing toast
69+ await updatePromise ;
70+ setTimeout ( ( ) => {
71+ window . location . reload ( ) ;
72+ } , 1500 ) ;
5273 } catch ( error ) {
5374 console . error ( "Error updating theme:" , error ) ;
5475 }
5576 } ,
56- [ updateUserTheme ]
77+ [ setTheme , updateUserTheme , userProfile ]
5778 ) ;
5879
5980 if ( ! userProfile ) return null ;
@@ -65,7 +86,12 @@ export const ThemeSwitcher = observer(function ThemeSwitcher(props: {
6586 description = { t ( props . option . description ) }
6687 control = {
6788 < div >
68- < ThemeSwitch value = { currentTheme } onChange = { handleThemeChange } />
89+ < ThemeSwitch
90+ value = { currentTheme }
91+ onChange = { ( themeOption ) => {
92+ void handleThemeChange ( themeOption ) ;
93+ } }
94+ />
6995 </ div >
7096 }
7197 />
0 commit comments