Inspector: fix types and cleanup effects [#49]

This commit is contained in:
Brandon Liu
2022-12-04 23:57:37 +08:00
parent 382225d1da
commit ce0dba5ed4
2 changed files with 12 additions and 12 deletions

View File

@@ -57,14 +57,7 @@ function App() {
globalStyles();
let [errorDisplay, setErrorDisplay] = useState<string | undefined>();
let [file, setFileRaw] = useState<PMTiles | undefined>();
let setFile = (file: PMTiles) => {
setFileRaw(file);
file.getHeader().catch((e) => {
setErrorDisplay(e.message);
});
};
let [file, setFile] = useState<PMTiles | undefined>();
// initial load
useEffect(() => {
@@ -75,6 +68,14 @@ function App() {
}
}, []);
useEffect(() => {
if (file) {
file.getHeader().catch((e) => {
setErrorDisplay(e.message);
});
}
}, [file]);
// maintaining URL state
useEffect(() => {
const url = new URL(window.location.href);
@@ -106,7 +107,7 @@ function App() {
</GithubLink>
</Header>
{file ? <Loader file={file} /> : <Start setFile={setFile} />}
<DialogPrimitive.Root open={errorDisplay}>
<DialogPrimitive.Root open={errorDisplay !== undefined}>
<DialogPrimitive.Portal>
<StyledOverlay />
<StyledContent