优化性能

This commit is contained in:
IndieKKY
2025-06-02 09:26:38 +08:00
parent d5b5b5d374
commit fea22fae61
5 changed files with 33 additions and 14 deletions

View File

@@ -13,6 +13,7 @@ import SegmentItem from './SegmentItem'
import {stopPopFunc} from '../utils/util' import {stopPopFunc} from '../utils/util'
import useSubtitle from '../hooks/useSubtitle' import useSubtitle from '../hooks/useSubtitle'
import DebateChat from './DebateChat' import DebateChat from './DebateChat'
import { RootState } from '../store'
const SummarizeItemOverview = (props: { const SummarizeItemOverview = (props: {
segment: Segment segment: Segment
@@ -25,7 +26,7 @@ const SummarizeItemOverview = (props: {
const {move} = useSubtitle() const {move} = useSubtitle()
const time = parseStrTimeToSeconds(overviewItem.time) const time = parseStrTimeToSeconds(overviewItem.time)
const currentTime = useAppSelector(state => state.env.currentTime) const currentTime = useAppSelector((state: RootState) => state.currentTime.currentTime)
const isIn = useMemo(() => { const isIn = useMemo(() => {
if (currentTime != null) { if (currentTime != null) {
// check in current segment // check in current segment

View File

@@ -4,15 +4,11 @@ import {
setCurFetched, setCurFetched,
setCurIdx, setCurIdx,
setCurInfo, setCurInfo,
setCurrentTime,
setData, setData,
setInfos,
setNoVideo, setNoVideo,
setSegmentFold, setSegmentFold,
setSegments, setSegments,
setTitle,
setTotalHeight, setTotalHeight,
setUrl,
setTempData, setTempData,
} from '../redux/envReducer' } from '../redux/envReducer'
import {EventBusContext} from '../Router' import {EventBusContext} from '../Router'
@@ -20,6 +16,8 @@ import {EVENT_EXPAND, TOTAL_HEIGHT_MAX, TOTAL_HEIGHT_MIN, WORDS_MIN, WORDS_RATE}
import {useAsyncEffect, useInterval} from 'ahooks' import {useAsyncEffect, useInterval} from 'ahooks'
import {getModelMaxTokens, getWholeText} from '../utils/bizUtil' import {getModelMaxTokens, getWholeText} from '../utils/bizUtil'
import { useMessage } from './useMessageService' import { useMessage } from './useMessageService'
import { setCurrentTime } from '../redux/currentTimeReducer'
import { RootState } from '../store'
/** /**
* Service是单例类似后端的服务概念 * Service是单例类似后端的服务概念
@@ -31,10 +29,10 @@ const useSubtitleService = () => {
const curFetched = useAppSelector(state => state.env.curFetched) const curFetched = useAppSelector(state => state.env.curFetched)
const fold = useAppSelector(state => state.env.fold) const fold = useAppSelector(state => state.env.fold)
const envReady = useAppSelector(state => state.env.envReady) const envReady = useAppSelector(state => state.env.envReady)
const envData = useAppSelector(state => state.env.envData) const envData = useAppSelector((state: RootState) => state.env.envData)
const data = useAppSelector(state => state.env.data) const data = useAppSelector((state: RootState) => state.env.data)
const currentTime = useAppSelector(state => state.env.currentTime) const currentTime = useAppSelector((state: RootState) => state.currentTime.currentTime)
const curIdx = useAppSelector(state => state.env.curIdx) const curIdx = useAppSelector((state: RootState) => state.env.curIdx)
const eventBus = useContext(EventBusContext) const eventBus = useContext(EventBusContext)
const needScroll = useAppSelector(state => state.env.needScroll) const needScroll = useAppSelector(state => state.env.needScroll)
const segments = useAppSelector(state => state.env.segments) const segments = useAppSelector(state => state.env.segments)

View File

@@ -0,0 +1,23 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
interface CurrentTimeState {
currentTime?: number
}
const initialState: CurrentTimeState = {
currentTime: undefined
}
export const slice = createSlice({
name: 'currentTime',
initialState,
reducers: {
setCurrentTime: (state, action: PayloadAction<number | undefined>) => {
state.currentTime = action.payload
}
}
})
export const { setCurrentTime } = slice.actions
export default slice.reducer

View File

@@ -23,7 +23,6 @@ interface EnvState {
totalHeight: number totalHeight: number
curIdx?: number // 从0开始 curIdx?: number // 从0开始
needScroll?: boolean needScroll?: boolean
currentTime?: number
infos?: any[] infos?: any[]
curInfo?: any curInfo?: any
curFetched?: boolean curFetched?: boolean
@@ -263,9 +262,6 @@ export const slice = createSlice({
setNeedScroll: (state, action: PayloadAction<boolean>) => { setNeedScroll: (state, action: PayloadAction<boolean>) => {
state.needScroll = action.payload state.needScroll = action.payload
}, },
setCurrentTime: (state, action: PayloadAction<number | undefined>) => {
state.currentTime = action.payload
},
setUrl: (state, action: PayloadAction<string | undefined>) => { setUrl: (state, action: PayloadAction<string | undefined>) => {
state.url = action.payload state.url = action.payload
}, },
@@ -337,7 +333,6 @@ export const {
setCurIdx, setCurIdx,
setEnvData, setEnvData,
setEnvReady, setEnvReady,
setCurrentTime,
setInfos, setInfos,
setCurInfo, setCurInfo,
setCurFetched, setCurFetched,

View File

@@ -1,9 +1,11 @@
import {configureStore} from '@reduxjs/toolkit' import {configureStore} from '@reduxjs/toolkit'
import envReducer from './redux/envReducer' import envReducer from './redux/envReducer'
import currentTimeReducer from './redux/currentTimeReducer'
const store = configureStore({ const store = configureStore({
reducer: { reducer: {
env: envReducer, env: envReducer,
currentTime: currentTimeReducer,
}, },
}) })