From 0ada5656ad518f02e12538f5069b134f03285cba Mon Sep 17 00:00:00 2001 From: icarus Date: Sun, 12 Oct 2025 02:01:54 +0800 Subject: [PATCH] fix(video): make videoMap entries optional and handle undefined cases Fix potential runtime errors by properly handling undefined videoMap entries. Update type definition and add null checks for videoMap operations. --- src/renderer/src/store/video.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/store/video.ts b/src/renderer/src/store/video.ts index 58b2b414d3..3fd4a72521 100644 --- a/src/renderer/src/store/video.ts +++ b/src/renderer/src/store/video.ts @@ -6,7 +6,7 @@ const logger = loggerService.withContext('Store:paintings') export interface VideoState { /** Provider ID to videos */ - videoMap: Record + videoMap: Record } const initialState: VideoState = { @@ -19,7 +19,7 @@ const videoSlice = createSlice({ reducers: { addVideo: (state: VideoState, action: PayloadAction<{ providerId: string; video: Video }>) => { const { providerId, video } = action.payload - if (state[providerId]) { + if (state.videoMap[providerId]) { state.videoMap[providerId].unshift(video) } else { state.videoMap[providerId] = [video] @@ -36,8 +36,8 @@ const videoSlice = createSlice({ ) => { const { providerId, update } = action.payload - const existingIndex = state.videoMap[providerId].findIndex((c) => c.id === update.id) - if (existingIndex !== -1) { + const existingIndex = state.videoMap[providerId]?.findIndex((c) => c.id === update.id) + if (existingIndex && existingIndex !== -1) { state.videoMap[providerId] = state.videoMap[providerId]?.map((c) => (c.id === update.id ? { ...c, update } : c)) } else { logger.error(`Video with id ${update.id} not found in ${providerId}`)