Skip to content

Commit

Permalink
feat: 테마 변경 시 toast ui 추가 (#ATR-537)
Browse files Browse the repository at this point in the history
  • Loading branch information
LC-02s committed Jul 13, 2024
1 parent 1426089 commit 6b6b621
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions apps/service/src/entities/theme/model/useThemeSetting.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use client'

import { useCallback, useEffect, useState } from 'react'
import { toast } from 'react-toastify'
import { RealTheme, Theme } from './type'
import { THEME_NAME } from '../constant'

function getCurrentTheme(): Theme {
if (typeof window === 'undefined') {
Expand Down Expand Up @@ -40,10 +42,16 @@ export default function useThemeSetting() {
setLightTheme()
}, [currentTheme])

const setTheme = useCallback((theme: Theme) => {
setCurrentTheme(theme)
localStorage.setItem('theme', theme)
}, [])
const setTheme = useCallback(
(theme: Theme) => {
setCurrentTheme(theme)
localStorage.setItem('theme', theme)
if (theme !== currentTheme) {
toast.success(`테마가 변경되었어요 (${THEME_NAME[theme]})`)
}
},
[currentTheme],
)

return { currentTheme, realTheme, setTheme }
}

0 comments on commit 6b6b621

Please sign in to comment.