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
This commit is contained in:
Sergey Krashevich 2023-06-14 15:32:36 +03:00 committed by GitHub
parent 7e5abe7a65
commit a8f282515f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import Heading from '../components/Heading'; import Heading from '../components/Heading';
import { useState, useEffect } from 'preact/hooks'; import { useState } from 'preact/hooks';
import useSWR from 'swr'; import useSWR from 'swr';
import Button from '../components/Button'; import Button from '../components/Button';
import axios from 'axios'; import axios from 'axios';
@ -10,21 +10,17 @@ export default function Export() {
const [camera, setCamera] = useState('select'); const [camera, setCamera] = useState('select');
const [playback, setPlayback] = useState('select'); const [playback, setPlayback] = useState('select');
const [message, setMessage] = useState({ text: '', error: false }); 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(); const currentDate = new Date();
currentDate.setHours(0, 0, 0, 0); currentDate.setHours(0, 0, 0, 0);
const offsetMs = currentDate.getTimezoneOffset() * 60 * 1000; const offsetMs = currentDate.getTimezoneOffset() * 60 * 1000;
const localISOTime = (new Date(currentDate.getTime() - offsetMs)).toISOString().slice(0,16); const localDate = new Date(currentDate.getTime() - offsetMs);
setStartDate(localISOTime); const localISODate = localDate.toISOString().split('T')[0];
setStartTime("00:00");
setEndDate(localISOTime); const [startDate, setStartDate] = useState(localISODate);
setEndTime("23:59"); const [startTime, setStartTime] = useState("00:00");
}, []); const [endDate, setEndDate] = useState(localISODate);
const [endTime, setEndTime] = useState("23:59");
const onHandleExport = () => { const onHandleExport = () => {
if (camera == 'select') { if (camera == 'select') {
@ -52,8 +48,13 @@ export default function Export() {
return; return;
} }
axios.post(`export/${camera}/start/${start}/end/${end}`, { playback })
.then(() => {
setMessage({ text: 'Successfully started export. View the file in the /exports folder.', error: false }); setMessage({ text: 'Successfully started export. View the file in the /exports folder.', error: false });
axios.post(`export/${camera}/start/${start}/end/${end}`, { playback }); })
.catch((error) => {
setMessage({ text: 'Failed to start export: '+error.response.data.message, error: true });
});
}; };
return ( return (