22import type { ThemeColor , ThemeType } from ' @/constants/themes'
33import { THEME_COLORS , THEME_TYPE } from ' @/constants/themes'
44
5- const { color, setColor, type, setThemeType } = useCustomize ()
5+ const { theme, updateAppSettings } = useAppSettings ()
66
77const allColors: ThemeColor [] = THEME_COLORS .map (color => color .name )
88const allTypes: ThemeType [] = THEME_TYPE
99
10- watch (color , () => {
10+ watch (() => theme . value ?. color , () => {
1111 setClassColor ()
1212})
1313
1414function setClassColor() {
1515 document .body .classList .remove (
1616 ... allColors .map (color => ` color-${color } ` ),
1717 )
18- document .body .classList .add (` color-${color .value } ` )
18+ document .body .classList .add (` color-${theme .value ?. color || ' default ' } ` )
1919}
2020
21- watch (type , () => {
21+ watch (() => theme . value ?. type , () => {
2222 setClassType ()
2323})
2424
2525function setClassType() {
2626 document .body .classList .remove (
2727 ... allTypes .map (type => ` theme-${type } ` ),
2828 )
29- document .body .classList .add (` theme-${type .value } ` )
29+ document .body .classList .add (` theme-${theme .value ?. type || ' default ' } ` )
3030}
3131
3232function backgroundColor(color : ThemeColor ) {
@@ -46,11 +46,11 @@ const colorMode = useColorMode()
4646 <Button
4747 class =" justify-start gap-2"
4848 variant =" outline"
49- :class =" { '!border-primary border-2 !bg-primary/10': color === col }"
50- @click =" setColor( col)"
49+ :class =" { '!border-primary border-2 !bg-primary/10': theme?. color === col }"
50+ @click =" updateAppSettings({ theme: { color: col } } )"
5151 >
5252 <span class =" h-5 w-5 flex items-center justify-center rounded-full border border-white" :style =" { backgroundColor: backgroundColor(col) }" >
53- <Icon v-if =" col === color" name =" i-radix-icons-check" size =" 16" class =" text-white" />
53+ <Icon v-if =" col === theme?. color" name =" i-radix-icons-check" size =" 16" class =" text-white" />
5454 </span >
5555 <span class =" text-xs capitalize" >{{ col }}</span >
5656 </Button >
@@ -64,8 +64,8 @@ const colorMode = useColorMode()
6464 <Button
6565 class =" justify-center gap-2"
6666 variant =" outline"
67- :class =" { '!border-primary border-2 !bg-primary/10': themeType === type }"
68- @click =" setThemeType( themeType)"
67+ :class =" { '!border-primary border-2 !bg-primary/10': theme?.type === themeType }"
68+ @click =" updateAppSettings({ theme: { type: themeType } } )"
6969 >
7070 <span class =" text-xs capitalize" >{{ themeType }}</span >
7171 </Button >
0 commit comments