mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-19 15:09:36 +00:00
reading resources
This commit is contained in:
@@ -4,6 +4,7 @@ import Router, { useRouter } from 'next/router'
|
||||
import BLOG from '@/blog.config'
|
||||
import { ALL_THEME, initDarkMode, initTheme, saveThemeToCookies } from '@/lib/theme'
|
||||
import NProgress from 'nprogress'
|
||||
import LoadingCover from '@/components/LoadingCover'
|
||||
|
||||
const GlobalContext = createContext()
|
||||
|
||||
@@ -14,11 +15,12 @@ const GlobalContext = createContext()
|
||||
* @constructor
|
||||
*/
|
||||
export function GlobalContextProvider({ children }) {
|
||||
const [lang, updateLang] = useState(BLOG.LANG)
|
||||
const [locale, updateLocale] = useState(generateLocaleDict(BLOG.LANG))
|
||||
const [theme, setTheme] = useState(BLOG.THEME)
|
||||
const [isDarkMode, updateDarkMode] = useState(BLOG.APPEARANCE === 'dark')
|
||||
const [onLoading, changeLoadingState] = useState(false)
|
||||
const [lang, updateLang] = useState(BLOG.LANG) // 默认语言
|
||||
const [locale, updateLocale] = useState(generateLocaleDict(BLOG.LANG)) // 默认语言
|
||||
const [theme, setTheme] = useState(BLOG.THEME) // 默认博客主题
|
||||
const [isDarkMode, updateDarkMode] = useState(BLOG.APPEARANCE === 'dark') // 默认深色模式
|
||||
const [onLoading, setOnLoading] = useState(false) // 加载文章数据
|
||||
const [onReading, setOnReading] = useState(true) // 资源加载中
|
||||
const router = useRouter()
|
||||
|
||||
useEffect(() => {
|
||||
@@ -30,11 +32,11 @@ export function GlobalContextProvider({ children }) {
|
||||
useEffect(() => {
|
||||
const handleStart = (url) => {
|
||||
NProgress.start()
|
||||
changeLoadingState(true)
|
||||
setOnLoading(true)
|
||||
}
|
||||
const handleStop = () => {
|
||||
NProgress.done()
|
||||
changeLoadingState(false)
|
||||
setOnLoading(false)
|
||||
}
|
||||
|
||||
router.events.on('routeChangeStart', handleStart)
|
||||
@@ -66,20 +68,20 @@ export function GlobalContextProvider({ children }) {
|
||||
}
|
||||
|
||||
return (
|
||||
<GlobalContext.Provider value={
|
||||
{
|
||||
onLoading,
|
||||
changeLoadingState,
|
||||
locale,
|
||||
updateLocale,
|
||||
isDarkMode,
|
||||
updateDarkMode,
|
||||
theme,
|
||||
setTheme,
|
||||
switchTheme,
|
||||
changeTheme
|
||||
}
|
||||
}>
|
||||
<GlobalContext.Provider value={{
|
||||
onLoading,
|
||||
setOnLoading,
|
||||
locale,
|
||||
updateLocale,
|
||||
isDarkMode,
|
||||
updateDarkMode,
|
||||
theme,
|
||||
setTheme,
|
||||
switchTheme,
|
||||
changeTheme,
|
||||
setOnReading
|
||||
}}>
|
||||
<LoadingCover onReading={onReading} setOnReading={setOnReading}/>
|
||||
{children}
|
||||
</GlobalContext.Provider>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user