init
This commit is contained in:
37
src/componets/FileChooser.tsx
Normal file
37
src/componets/FileChooser.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Env } from "../models/Env";
|
||||
import { ConfigReader } from "../models/ConfigReader";
|
||||
import { Config } from "../models/Config";
|
||||
|
||||
|
||||
export function FileChooser(props: { onSelected: (x: Config) => void }) {
|
||||
async function handleFile(x: React.ChangeEvent<HTMLInputElement>) {
|
||||
let file = x.target.files![0];
|
||||
|
||||
console.log(file.name, file.type, file.size, "supported:", ConfigReader.isSupportedFormat(file));
|
||||
let reader = new ConfigReader();
|
||||
let cfg = await reader.parseFromFile(file);
|
||||
|
||||
if (cfg !== null) {
|
||||
props.onSelected(cfg);
|
||||
}
|
||||
}
|
||||
|
||||
function handleNew(){
|
||||
let cfg = new Config();
|
||||
cfg.addEnvs([new Env(0,"DEFAULT", [])]);
|
||||
props.onSelected(cfg);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="col-2">
|
||||
<button className="btn btn-primary" onClick={handleNew} >Create new</button>
|
||||
</div>
|
||||
<div className="col-1">or</div>
|
||||
|
||||
<div className="col">
|
||||
<input className="form-control" type="file" id="formFile" onChange={handleFile} />
|
||||
</div >
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user