-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDataUpload.tsx
More file actions
74 lines (63 loc) · 2.91 KB
/
DataUpload.tsx
File metadata and controls
74 lines (63 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Button, Chip, Dialog, DialogActions, DialogContent, DialogTitle, Stack, Tooltip, Typography } from "@mui/material";
import { useActiveMission } from "../utils/ActiveMissionContext";
import React, { useState, useEffect } from 'react';
import FileUpload from "react-material-file-upload";
import * as DataConverter from "rocket-data"
interface IDataUploadProps {
isOpen: boolean;
onClose: () => void;
}
const MissionConfig: React.FC<IDataUploadProps> = (props: IDataUploadProps) => {
const { isOpen, onClose } = props;
const [files, setFiles] = useState<File[]>([]);
const handleSave = async () => {
const config_file = files.find((element: File) => element.name.indexOf(".json") !== -1);
const bin_file = files.find((element: File) => element.name.indexOf(".bin") !== -1);
const csv_str = await DataConverter.convert_to_csv(config_file, bin_file);
console.log(csv_str);
props.onClose();
};
const handleClose = () => {
props.onClose();
};
useEffect(() => {
console.log(files);
}, [files]);
const context = useActiveMission();
return(
<Dialog open={isOpen} fullWidth onClose={handleClose}>
<DialogTitle>
<Typography variant="h4">Upload Flight Data</Typography>
</DialogTitle>
<DialogContent>
<Stack direction={'column'} gap={2}>
<Typography variant="body1">Upload two files: config.json and data.bin or data.cvs.</Typography>
<Stack direction={'row'} gap={2} alignItems={'center'}>
<Typography variant="subtitle1">Supported File Type:</Typography>
<Chip label='.cvs' color="primary" variant="outlined"/>
<Chip label='.json' color="primary" variant="outlined"/>
<Chip label='.bin' color="primary" variant="outlined"/>
</Stack>
<Tooltip title="To upload multiple files they both must be selected in your file system">
<div>
<FileUpload
accept={[".csv", ".json", ".bin"]}
multiple
value={files}
onChange={setFiles}
title="Upload your flight data and config file to begin analyzing your flight!"
buttonText="Upload"
/>
</div>
</Tooltip>
<Typography variant="subtitle1"> </Typography>
</Stack>
</DialogContent>
<DialogActions>
<Button onClick={onClose}>Cancel</Button>
<Button onClick={handleSave}>Save</Button>
</DialogActions>
</Dialog>
);
}
export default MissionConfig;