mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-31 11:59:10 +00:00
refract: simpler upload
- also reverting deleting the file that is uploaded
This commit is contained in:
@@ -24,7 +24,7 @@ export default function Editor() {
|
|||||||
|
|
||||||
<div className={styles.mainContainer}>
|
<div className={styles.mainContainer}>
|
||||||
<Box id='settings' className={styles.settings}>
|
<Box id='settings' className={styles.settings}>
|
||||||
<MenuBar onOpen={onOpen} onClose={onClose} />
|
<MenuBar onOpen={onOpen} />
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Box className={styles.editor}>
|
<Box className={styles.editor}>
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { useMutation, useQueryClient } from 'react-query';
|
import { useMutation, useQueryClient } from 'react-query';
|
||||||
import { downloadEvents, uploadEventsWithPath } from 'app/api/ontimeApi';
|
import {
|
||||||
|
downloadEvents,
|
||||||
|
uploadEvents,
|
||||||
|
uploadEventsWithPath,
|
||||||
|
} from 'app/api/ontimeApi';
|
||||||
import { EVENTS_TABLE } from 'app/api/apiConstants';
|
import { EVENTS_TABLE } from 'app/api/apiConstants';
|
||||||
import DownloadIconBtn from './buttons/DownloadIconBtn';
|
import DownloadIconBtn from './buttons/DownloadIconBtn';
|
||||||
import SettingsIconBtn from './buttons/SettingsIconBtn';
|
import SettingsIconBtn from './buttons/SettingsIconBtn';
|
||||||
@@ -10,13 +14,15 @@ import QuitIconBtn from './buttons/QuitIconBtn';
|
|||||||
import style from './MenuBar.module.css';
|
import style from './MenuBar.module.css';
|
||||||
import HelpIconBtn from './buttons/HelpIconBtn';
|
import HelpIconBtn from './buttons/HelpIconBtn';
|
||||||
import UploadIconBtn from './buttons/UploadIconBtn';
|
import UploadIconBtn from './buttons/UploadIconBtn';
|
||||||
|
import { useRef } from 'react';
|
||||||
|
|
||||||
const { ipcRenderer, remote } = window.require('electron');
|
const { ipcRenderer } = window.require('electron');
|
||||||
|
|
||||||
export default function MenuBar(props) {
|
export default function MenuBar(props) {
|
||||||
const { onOpen, onClose } = props;
|
const { onOpen } = props;
|
||||||
|
const hiddenFileInput = useRef(null);
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const uploaddbPath = useMutation(uploadEventsWithPath, {
|
const uploaddb = useMutation(uploadEvents, {
|
||||||
onSettled: () => {
|
onSettled: () => {
|
||||||
queryClient.invalidateQueries(EVENTS_TABLE);
|
queryClient.invalidateQueries(EVENTS_TABLE);
|
||||||
},
|
},
|
||||||
@@ -26,30 +32,22 @@ export default function MenuBar(props) {
|
|||||||
downloadEvents();
|
downloadEvents();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUpload = () => {
|
const handleClick = () => {
|
||||||
remote.dialog
|
if (hiddenFileInput && hiddenFileInput.current) {
|
||||||
.showOpenDialog({
|
hiddenFileInput.current.click();
|
||||||
title: 'Select the File to be uploaded',
|
}
|
||||||
buttonLabel: 'Upload',
|
};
|
||||||
filters: [
|
|
||||||
{
|
const handleUpload = (event) => {
|
||||||
name: 'Text Files',
|
const fileUploaded = event.target.files[0];
|
||||||
extensions: ['json'],
|
|
||||||
},
|
if (fileUploaded == null) return;
|
||||||
],
|
|
||||||
// Specifying the File Selector Property
|
try {
|
||||||
properties: ['openFile'],
|
uploaddb.mutate(fileUploaded);
|
||||||
})
|
} catch (error) {
|
||||||
.then((file) => {
|
console.log(error);
|
||||||
// Stating whether dialog operation was
|
}
|
||||||
// cancelled or not.
|
|
||||||
if (!file.canceled) {
|
|
||||||
uploaddbPath.mutate(file.filePaths[0].toString());
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleIPC = (action) => {
|
const handleIPC = (action) => {
|
||||||
@@ -89,6 +87,7 @@ export default function MenuBar(props) {
|
|||||||
style={{ fontSize: '1.5em' }}
|
style={{ fontSize: '1.5em' }}
|
||||||
size='lg'
|
size='lg'
|
||||||
clickhandler={() => handleIPC('help')}
|
clickhandler={() => handleIPC('help')}
|
||||||
|
disabled
|
||||||
/>
|
/>
|
||||||
<SettingsIconBtn style={{ fontSize: '1.5em' }} size='lg' disabled />
|
<SettingsIconBtn style={{ fontSize: '1.5em' }} size='lg' disabled />
|
||||||
<div className={style.gap} />
|
<div className={style.gap} />
|
||||||
@@ -97,10 +96,17 @@ export default function MenuBar(props) {
|
|||||||
size='lg'
|
size='lg'
|
||||||
clickhandler={onOpen}
|
clickhandler={onOpen}
|
||||||
/>
|
/>
|
||||||
|
<input
|
||||||
|
type='file'
|
||||||
|
style={{ display: 'none' }}
|
||||||
|
ref={hiddenFileInput}
|
||||||
|
onChange={handleUpload}
|
||||||
|
accept='.json'
|
||||||
|
/>
|
||||||
<UploadIconBtn
|
<UploadIconBtn
|
||||||
style={{ fontSize: '1.5em' }}
|
style={{ fontSize: '1.5em' }}
|
||||||
size='lg'
|
size='lg'
|
||||||
clickhandler={handleUpload}
|
clickhandler={handleClick}
|
||||||
/>
|
/>
|
||||||
<DownloadIconBtn
|
<DownloadIconBtn
|
||||||
style={{ fontSize: '1.5em' }}
|
style={{ fontSize: '1.5em' }}
|
||||||
|
|||||||
@@ -115,6 +115,9 @@ const upload = async (file, req, res) => {
|
|||||||
const rawdata = fs.readFileSync(file);
|
const rawdata = fs.readFileSync(file);
|
||||||
const uploadedJson = JSON.parse(rawdata);
|
const uploadedJson = JSON.parse(rawdata);
|
||||||
|
|
||||||
|
// delete file
|
||||||
|
deleteFile(file);
|
||||||
|
|
||||||
// check version
|
// check version
|
||||||
if (uploadedJson.settings.version === 1) parsev1(uploadedJson);
|
if (uploadedJson.settings.version === 1) parsev1(uploadedJson);
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user