From a2d2bf893acf561244c58b713d4ecdb1da3281a6 Mon Sep 17 00:00:00 2001 From: Rohit Date: Wed, 9 Apr 2025 20:49:55 +0530 Subject: [PATCH] feat: save robot based on retrain robot params --- src/components/recorder/SaveRecording.tsx | 44 +++++++++++++++++------ 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/components/recorder/SaveRecording.tsx b/src/components/recorder/SaveRecording.tsx index f7020b44..87d9bd17 100644 --- a/src/components/recorder/SaveRecording.tsx +++ b/src/components/recorder/SaveRecording.tsx @@ -19,26 +19,32 @@ export const SaveRecording = ({ fileName }: SaveRecordingProps) => { const { t } = useTranslation(); const [openModal, setOpenModal] = useState(false); const [needConfirm, setNeedConfirm] = useState(false); - const [recordingName, setRecordingName] = useState(fileName); + const [saveRecordingName, setSaveRecordingName] = useState(fileName); const [waitingForSave, setWaitingForSave] = useState(false); - const { browserId, setBrowserId, notify, recordings, isLogin } = useGlobalInfoStore(); + const { browserId, setBrowserId, notify, recordings, isLogin, recordingName, retrainRobotId } = useGlobalInfoStore(); const { socket } = useSocketStore(); const { state, dispatch } = useContext(AuthContext); const { user } = state; const navigate = useNavigate(); + useEffect(() => { + if (recordingName) { + setSaveRecordingName(recordingName); + } + }, [recordingName]); + const handleChangeOfTitle = (event: React.ChangeEvent) => { const { value } = event.target; if (needConfirm) { setNeedConfirm(false); } - setRecordingName(value); + setSaveRecordingName(value); } const handleSaveRecording = async (event: React.SyntheticEvent) => { event.preventDefault(); - if (recordings.includes(recordingName)) { + if (recordings.includes(saveRecordingName)) { if (needConfirm) { return; } setNeedConfirm(true); } else { @@ -46,19 +52,32 @@ export const SaveRecording = ({ fileName }: SaveRecordingProps) => { } }; + const handleFinishClick = () => { + if (recordingName && !recordings.includes(recordingName)) { + saveRecording(); + } else { + setOpenModal(true); + } + }; + const exitRecording = useCallback(async () => { const notificationData = { type: 'success', message: t('save_recording.notifications.save_success'), timestamp: Date.now() }; - window.sessionStorage.setItem('pendingNotification', JSON.stringify(notificationData)); if (window.opener) { window.opener.postMessage({ type: 'recording-notification', notification: notificationData }, '*'); + + // Also notify about clearing any remaining session data + window.opener.postMessage({ + type: 'session-data-clear', + timestamp: Date.now() + }, '*'); } if (browserId) { @@ -67,16 +86,21 @@ export const SaveRecording = ({ fileName }: SaveRecordingProps) => { setBrowserId(null); window.close(); - }, [setBrowserId, browserId]); + }, [setBrowserId, browserId, t]); // notifies backed to save the recording in progress, // releases resources and changes the view for main page by clearing the global browserId const saveRecording = async () => { if (user) { - const payload = { fileName: recordingName, userId: user.id, isLogin: isLogin }; + const payload = { + fileName: saveRecordingName || recordingName, + userId: user.id, + isLogin: isLogin, + robotId: retrainRobotId, + }; socket?.emit('save', payload); setWaitingForSave(true); - console.log(`Saving the recording as ${recordingName} for userId ${user.id}`); + console.log(`Saving the recording as ${saveRecordingName || recordingName} for userId ${user.id}`); } else { console.error(t('save_recording.notifications.user_not_logged')); } @@ -92,7 +116,7 @@ export const SaveRecording = ({ fileName }: SaveRecordingProps) => { return (