临时存储当前选择的tab索引

This commit is contained in:
IndieKKY
2023-05-20 09:13:55 +08:00
parent 5656beceb2
commit d9d905facb
9 changed files with 52 additions and 19 deletions

View File

@@ -1,12 +1,12 @@
import React, {useCallback, useContext, useEffect, useMemo} from 'react'
import 'tippy.js/dist/tippy.css'
import {useAppDispatch, useAppSelector} from './hooks/redux'
import {setEnvData, setEnvReady, setFold, setPage} from './redux/envReducer'
import {setEnvData, setEnvReady, setFold, setPage, setTempData, setTempReady} from './redux/envReducer'
import Header from './biz/Header'
import Body from './biz/Body'
import useSubtitleService from './hooks/useSubtitleService'
import {cloneDeep} from 'lodash-es'
import {EVENT_EXPAND, PAGE_MAIN, PAGE_SETTINGS, STORAGE_ENV} from './const'
import {EVENT_EXPAND, PAGE_MAIN, PAGE_SETTINGS, STORAGE_ENV, STORAGE_TEMP} from './const'
import {EventBusContext} from './Router'
import useTranslateService from './hooks/useTranslateService'
import Settings from './biz/Settings'
@@ -19,6 +19,7 @@ import {setTheme} from './util/biz_util'
function App() {
const dispatch = useAppDispatch()
const envData = useAppSelector(state => state.env.envData)
const tempData = useAppSelector(state => state.env.tempData)
const fold = useAppSelector(state => state.env.fold)
const eventBus = useContext(EventBusContext)
const page = useAppSelector(state => state.env.page)
@@ -51,6 +52,18 @@ function App() {
}, [dispatch])
useLocalStorage<EnvData>('chrome_client', STORAGE_ENV, savedEnvData, onLoadEnv)
// temp数据
const savedTempData = useMemo(() => {
return handleJson(cloneDeep(tempData)) as TempData
}, [tempData])
const onLoadTemp = useCallback((data?: TempData) => {
if (data != null) {
dispatch(setTempData(data))
}
dispatch(setTempReady())
}, [dispatch])
useLocalStorage<TempData>('chrome_client', STORAGE_TEMP, savedTempData, onLoadTemp)
// theme改变时设置主题
useEffect(() => {
setTheme(envData.theme)