WASM improvements

main
Ziyang Hu 2 years ago
parent d03ea7d13d
commit efb5267724

@ -78,7 +78,7 @@ function App() {
}
function handleQuery() {
if (!db) {
if (!db || inProgress) {
setInProgress(false);
setErrorMessage([]);
setStatusMessage(['database not ready']);
@ -92,6 +92,8 @@ function App() {
setErrorMessage([]);
setStatusMessage('');
setQueryResults(null);
requestAnimationFrame(() => {
setTimeout(() => {
try {
const t0 = performance.now();
const res_str = db.run(query, params);
@ -124,6 +126,8 @@ function App() {
} finally {
setInProgress(false);
}
}, 0)
})
}
}
@ -157,7 +161,7 @@ function App() {
<div style={{paddingTop: 10, display: 'flex', flexDirection: 'row'}}>
<Button
icon="play"
text={db ? "Run script" : "Loading WASM ..."}
text={db ? (inProgress ? "Query is running" : "Run script") : "Loading WASM ..."}
onClick={() => handleQuery()}
disabled={!db || inProgress}
intent={Intent.PRIMARY}
@ -211,7 +215,7 @@ function App() {
cellRenderer={renderCell(idx)}
/>)}
</Table2> : null) : null}
{!(queryResults || errorMessage.length) && <div id="welcome">
{!(queryResults || errorMessage.length || inProgress) && <div id="welcome">
<p>
This is the demo page for Cozo running in your browser as
a <a href="https://webassembly.org/">Web assembly</a> module.
@ -259,6 +263,7 @@ function ImportUrl({db}) {
let content = await resp.text();
const res = JSON.parse(db.import_relations(content));
if (res.ok) {
AppToaster.show({message: "Imported", intent: Intent.SUCCESS})
handleClose()
} else {
AppToaster.show({message: res.message, intent: Intent.DANGER})
@ -310,6 +315,7 @@ function ImportFile({db}) {
let content = await file.text();
const res = JSON.parse(db.import_relations(content));
if (res.ok) {
AppToaster.show({message: "Imported", intent: Intent.SUCCESS})
handleClose()
} else {
AppToaster.show({message: res.message, intent: Intent.DANGER})
@ -370,6 +376,7 @@ function Export({db}) {
if (res.ok) {
const blob = new Blob([JSON.stringify(res.data)], {type: "text/plain;charset=utf-8"});
saveAs(blob, "export.json");
AppToaster.show({message: "Exported", intent: Intent.SUCCESS})
handleClose()
} else {
AppToaster.show({message: res.message, intent: Intent.DANGER})

Loading…
Cancel
Save