From a8f282515ffa0ab6d21be6c12d8c3ce803a99a3f Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Wed, 14 Jun 2023 15:32:36 +0300 Subject: [PATCH] Bugfix: Refactor date and time initialization in Export.jsx (#6794) * Refactor date and time initialization in Export.jsx to use local timezone * Update error message to include specific reason for failure in Export.jsx --- web/src/routes/Export.jsx | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/web/src/routes/Export.jsx b/web/src/routes/Export.jsx index 0a4bd246d..55f1a8933 100644 --- a/web/src/routes/Export.jsx +++ b/web/src/routes/Export.jsx @@ -1,5 +1,5 @@ import Heading from '../components/Heading'; -import { useState, useEffect } from 'preact/hooks'; +import { useState } from 'preact/hooks'; import useSWR from 'swr'; import Button from '../components/Button'; import axios from 'axios'; @@ -10,21 +10,17 @@ export default function Export() { const [camera, setCamera] = useState('select'); const [playback, setPlayback] = useState('select'); const [message, setMessage] = useState({ text: '', error: false }); - const [startDate, setStartDate] = useState('input'); - const [startTime, setStartTime] = useState('input'); - const [endDate, setEndDate] = useState('input'); - const [endTime, setEndTime] = useState('input'); - useEffect(() => { - const currentDate = new Date(); - currentDate.setHours(0, 0, 0, 0); - const offsetMs = currentDate.getTimezoneOffset() * 60 * 1000; - const localISOTime = (new Date(currentDate.getTime() - offsetMs)).toISOString().slice(0,16); - setStartDate(localISOTime); - setStartTime("00:00"); - setEndDate(localISOTime); - setEndTime("23:59"); - }, []); + const currentDate = new Date(); + currentDate.setHours(0, 0, 0, 0); + const offsetMs = currentDate.getTimezoneOffset() * 60 * 1000; + const localDate = new Date(currentDate.getTime() - offsetMs); + const localISODate = localDate.toISOString().split('T')[0]; + + const [startDate, setStartDate] = useState(localISODate); + const [startTime, setStartTime] = useState("00:00"); + const [endDate, setEndDate] = useState(localISODate); + const [endTime, setEndTime] = useState("23:59"); const onHandleExport = () => { if (camera == 'select') { @@ -52,8 +48,13 @@ export default function Export() { return; } - setMessage({ text: 'Successfully started export. View the file in the /exports folder.', error: false }); - axios.post(`export/${camera}/start/${start}/end/${end}`, { playback }); + axios.post(`export/${camera}/start/${start}/end/${end}`, { playback }) + .then(() => { + setMessage({ text: 'Successfully started export. View the file in the /exports folder.', error: false }); + }) + .catch((error) => { + setMessage({ text: 'Failed to start export: '+error.response.data.message, error: true }); + }); }; return (