테마 깜빡임·로딩 스플래시 및 메인 커버 저장 흐름 수정
head 인라인 스크립트로 data-theme 선적용, 로고 캐시 스플래시 추가. 메인 커버는 업로드 후 저장 버튼에서 이미지·텍스트 일괄 반영. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
const themeStorageKey = 'SITE_THEME'
|
||||
import {
|
||||
SITE_THEME_STORAGE_KEY,
|
||||
resolveSiteTheme
|
||||
} from '~/lib/site-theme-init.js'
|
||||
|
||||
/**
|
||||
* HTML 루트 요소에 현재 테마를 반영한다.
|
||||
@@ -34,19 +37,23 @@ export const useThemeMode = () => {
|
||||
const theme = useState('site-theme-mode', () => 'light')
|
||||
const isDarkMode = computed(() => theme.value === 'dark')
|
||||
|
||||
onMounted(() => {
|
||||
const savedTheme = localStorage.getItem(themeStorageKey)
|
||||
const nextTheme = savedTheme === 'light' || savedTheme === 'dark' ? savedTheme : getSystemTheme()
|
||||
theme.value = nextTheme
|
||||
applyThemeToDocument(nextTheme)
|
||||
})
|
||||
if (import.meta.client) {
|
||||
const fromDocument = document.documentElement.dataset.theme
|
||||
if (fromDocument === 'light' || fromDocument === 'dark') {
|
||||
theme.value = fromDocument
|
||||
} else {
|
||||
const savedTheme = localStorage.getItem(SITE_THEME_STORAGE_KEY)
|
||||
theme.value = resolveSiteTheme(savedTheme, getSystemTheme() === 'dark')
|
||||
applyThemeToDocument(theme.value)
|
||||
}
|
||||
}
|
||||
|
||||
watch(theme, (nextTheme) => {
|
||||
if (!import.meta.client) {
|
||||
return
|
||||
}
|
||||
|
||||
localStorage.setItem(themeStorageKey, nextTheme)
|
||||
localStorage.setItem(SITE_THEME_STORAGE_KEY, nextTheme)
|
||||
applyThemeToDocument(nextTheme)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user