feat: save robot based on retrain robot params
This commit is contained in:
@@ -19,26 +19,32 @@ export const SaveRecording = ({ fileName }: SaveRecordingProps) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [openModal, setOpenModal] = useState<boolean>(false);
|
const [openModal, setOpenModal] = useState<boolean>(false);
|
||||||
const [needConfirm, setNeedConfirm] = useState<boolean>(false);
|
const [needConfirm, setNeedConfirm] = useState<boolean>(false);
|
||||||
const [recordingName, setRecordingName] = useState<string>(fileName);
|
const [saveRecordingName, setSaveRecordingName] = useState<string>(fileName);
|
||||||
const [waitingForSave, setWaitingForSave] = useState<boolean>(false);
|
const [waitingForSave, setWaitingForSave] = useState<boolean>(false);
|
||||||
|
|
||||||
const { browserId, setBrowserId, notify, recordings, isLogin } = useGlobalInfoStore();
|
const { browserId, setBrowserId, notify, recordings, isLogin, recordingName, retrainRobotId } = useGlobalInfoStore();
|
||||||
const { socket } = useSocketStore();
|
const { socket } = useSocketStore();
|
||||||
const { state, dispatch } = useContext(AuthContext);
|
const { state, dispatch } = useContext(AuthContext);
|
||||||
const { user } = state;
|
const { user } = state;
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (recordingName) {
|
||||||
|
setSaveRecordingName(recordingName);
|
||||||
|
}
|
||||||
|
}, [recordingName]);
|
||||||
|
|
||||||
const handleChangeOfTitle = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChangeOfTitle = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const { value } = event.target;
|
const { value } = event.target;
|
||||||
if (needConfirm) {
|
if (needConfirm) {
|
||||||
setNeedConfirm(false);
|
setNeedConfirm(false);
|
||||||
}
|
}
|
||||||
setRecordingName(value);
|
setSaveRecordingName(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSaveRecording = async (event: React.SyntheticEvent) => {
|
const handleSaveRecording = async (event: React.SyntheticEvent) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (recordings.includes(recordingName)) {
|
if (recordings.includes(saveRecordingName)) {
|
||||||
if (needConfirm) { return; }
|
if (needConfirm) { return; }
|
||||||
setNeedConfirm(true);
|
setNeedConfirm(true);
|
||||||
} else {
|
} 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 exitRecording = useCallback(async () => {
|
||||||
const notificationData = {
|
const notificationData = {
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: t('save_recording.notifications.save_success'),
|
message: t('save_recording.notifications.save_success'),
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
window.sessionStorage.setItem('pendingNotification', JSON.stringify(notificationData));
|
|
||||||
|
|
||||||
if (window.opener) {
|
if (window.opener) {
|
||||||
window.opener.postMessage({
|
window.opener.postMessage({
|
||||||
type: 'recording-notification',
|
type: 'recording-notification',
|
||||||
notification: notificationData
|
notification: notificationData
|
||||||
}, '*');
|
}, '*');
|
||||||
|
|
||||||
|
// Also notify about clearing any remaining session data
|
||||||
|
window.opener.postMessage({
|
||||||
|
type: 'session-data-clear',
|
||||||
|
timestamp: Date.now()
|
||||||
|
}, '*');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (browserId) {
|
if (browserId) {
|
||||||
@@ -67,16 +86,21 @@ export const SaveRecording = ({ fileName }: SaveRecordingProps) => {
|
|||||||
setBrowserId(null);
|
setBrowserId(null);
|
||||||
|
|
||||||
window.close();
|
window.close();
|
||||||
}, [setBrowserId, browserId]);
|
}, [setBrowserId, browserId, t]);
|
||||||
|
|
||||||
// notifies backed to save the recording in progress,
|
// notifies backed to save the recording in progress,
|
||||||
// releases resources and changes the view for main page by clearing the global browserId
|
// releases resources and changes the view for main page by clearing the global browserId
|
||||||
const saveRecording = async () => {
|
const saveRecording = async () => {
|
||||||
if (user) {
|
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);
|
socket?.emit('save', payload);
|
||||||
setWaitingForSave(true);
|
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 {
|
} else {
|
||||||
console.error(t('save_recording.notifications.user_not_logged'));
|
console.error(t('save_recording.notifications.user_not_logged'));
|
||||||
}
|
}
|
||||||
@@ -92,7 +116,7 @@ export const SaveRecording = ({ fileName }: SaveRecordingProps) => {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => setOpenModal(true)}
|
onClick={handleFinishClick}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
color="success"
|
color="success"
|
||||||
sx={{
|
sx={{
|
||||||
@@ -116,7 +140,7 @@ export const SaveRecording = ({ fileName }: SaveRecordingProps) => {
|
|||||||
id="title"
|
id="title"
|
||||||
label={t('save_recording.robot_name')}
|
label={t('save_recording.robot_name')}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
defaultValue={recordingName ? recordingName : null}
|
value={saveRecordingName}
|
||||||
/>
|
/>
|
||||||
{needConfirm
|
{needConfirm
|
||||||
?
|
?
|
||||||
|
|||||||
Reference in New Issue
Block a user