mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-24 15:09:51 +00:00
主题初始调整
This commit is contained in:
@@ -6,7 +6,6 @@ import { initDarkMode, initTheme, saveThemeToCookies } from '@/lib/theme'
|
|||||||
import { ALL_THEME } from '@/themes'
|
import { ALL_THEME } from '@/themes'
|
||||||
|
|
||||||
const GlobalContext = createContext()
|
const GlobalContext = createContext()
|
||||||
let hasInit = false
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局变量Provider,包括语言本地化、样式主题、搜索词
|
* 全局变量Provider,包括语言本地化、样式主题、搜索词
|
||||||
@@ -14,7 +13,7 @@ let hasInit = false
|
|||||||
* @returns {JSX.Element}
|
* @returns {JSX.Element}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
export function GlobalContextProvider ({ children }) {
|
export function GlobalContextProvider({ children }) {
|
||||||
const [locale, updateLocale] = useState(generateLocaleDict('en-US'))
|
const [locale, updateLocale] = useState(generateLocaleDict('en-US'))
|
||||||
const [isDarkMode, updateDarkMode] = useState(false)
|
const [isDarkMode, updateDarkMode] = useState(false)
|
||||||
const [onLoading, changeLoadingState] = useState(false)
|
const [onLoading, changeLoadingState] = useState(false)
|
||||||
@@ -27,13 +26,13 @@ export function GlobalContextProvider ({ children }) {
|
|||||||
changeLoadingState(false)
|
changeLoadingState(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
function switchTheme () {
|
function switchTheme() {
|
||||||
const currentIndex = ALL_THEME.indexOf(theme)
|
const currentIndex = ALL_THEME.indexOf(theme)
|
||||||
const newIndex = currentIndex < ALL_THEME.length - 1 ? currentIndex + 1 : 0
|
const newIndex = currentIndex < ALL_THEME.length - 1 ? currentIndex + 1 : 0
|
||||||
changeTheme(ALL_THEME[newIndex])
|
changeTheme(ALL_THEME[newIndex])
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeTheme (theme) {
|
function changeTheme(theme) {
|
||||||
Router.query.theme = ''
|
Router.query.theme = ''
|
||||||
if (ALL_THEME.indexOf(theme) > -1) {
|
if (ALL_THEME.indexOf(theme) > -1) {
|
||||||
setTheme(theme)
|
setTheme(theme)
|
||||||
@@ -44,13 +43,10 @@ export function GlobalContextProvider ({ children }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!hasInit) {
|
initLocale(locale, updateLocale)
|
||||||
initLocale(locale, updateLocale)
|
initDarkMode(isDarkMode, updateDarkMode)
|
||||||
initDarkMode(isDarkMode, updateDarkMode)
|
initTheme(theme, changeTheme)
|
||||||
initTheme(theme, changeTheme)
|
}, [])
|
||||||
hasInit = true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<GlobalContext.Provider value={{ onLoading, locale, updateLocale, isDarkMode, updateDarkMode, theme, setTheme, switchTheme, changeTheme }}>
|
<GlobalContext.Provider value={{ onLoading, locale, updateLocale, isDarkMode, updateDarkMode, theme, setTheme, switchTheme, changeTheme }}>
|
||||||
|
|||||||
Reference in New Issue
Block a user