From f885269688efea5e82a6589bd36619ffaa84cf2d Mon Sep 17 00:00:00 2001 From: Rohit Rajan Date: Fri, 19 Sep 2025 11:18:07 +0530 Subject: [PATCH] feat: persist recording id --- src/context/globalInfo.tsx | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/context/globalInfo.tsx b/src/context/globalInfo.tsx index 6919ef0c..a9b20bfa 100644 --- a/src/context/globalInfo.tsx +++ b/src/context/globalInfo.tsx @@ -249,7 +249,29 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => { const [rerenderRuns, setRerenderRuns] = useState(globalInfoStore.rerenderRuns); const [rerenderRobots, setRerenderRobots] = useState(globalInfoStore.rerenderRobots); const [recordingLength, setRecordingLength] = useState(globalInfoStore.recordingLength); - const [recordingId, setRecordingId] = useState(globalInfoStore.recordingId); + // const [recordingId, setRecordingId] = useState(globalInfoStore.recordingId); + const [recordingId, setRecordingId] = useState(() => { + try { + const stored = sessionStorage.getItem('recordingId'); + return stored ? JSON.parse(stored) : globalInfoStore.recordingId; + } catch { + return globalInfoStore.recordingId; + } + }); + + // Create a wrapped setter that persists to sessionStorage + const setPersistedRecordingId = (newRecordingId: string | null) => { + setRecordingId(newRecordingId); + try { + if (newRecordingId) { + sessionStorage.setItem('recordingId', JSON.stringify(newRecordingId)); + } else { + sessionStorage.removeItem('recordingId'); + } + } catch (error) { + console.warn('Failed to persist recordingId to sessionStorage:', error); + } + }; const [retrainRobotId, setRetrainRobotId] = useState(globalInfoStore.retrainRobotId); const [recordingName, setRecordingName] = useState(globalInfoStore.recordingName); const [isLogin, setIsLogin] = useState(globalInfoStore.isLogin); @@ -320,7 +342,7 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => { recordingLength, setRecordingLength, recordingId, - setRecordingId, + setRecordingId: setPersistedRecordingId, retrainRobotId, setRetrainRobotId, recordingName,