You've already forked bilibili-subtitle
临时存储当前选择的tab索引
This commit is contained in:
17
src/App.tsx
17
src/App.tsx
@@ -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)
|
||||
|
Reference in New Issue
Block a user