Skip to content

Commit fc267de

Browse files
Merge pull request #24 from visual-heuristics/feat_addLoading
add loading
2 parents 0817ce5 + e505212 commit fc267de

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/pages/PageOne/dropAndFetch.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import DropZone from "./dropZone";
33
import Button from "@material-ui/core/Button";
44
import Container from "@material-ui/core/Container";
55
import CloudUploadIcon from "@material-ui/icons/CloudUpload";
6+
import CircularProgress from '@material-ui/core/CircularProgress';
67
import css from "./index.module.less";
78

89
/**
@@ -14,6 +15,7 @@ import css from "./index.module.less";
1415
*/
1516
export default function DropAndFetch({ onStore, onClick, newURL }) {
1617
const [dataFiles, setDataFiles] = useState({});
18+
const [loading, setLoading] = useState(false);
1719

1820
const dragsAndDrops = [
1921
{ name: "Domain", fileType: ".pddl", desc: "or predictes and actions." },
@@ -41,6 +43,7 @@ export default function DropAndFetch({ onStore, onClick, newURL }) {
4143
formData.append(name, files[name]);
4244
}
4345
try {
46+
setLoading(true)
4447
const resp = await fetch(
4548
"https://planimation.planning.domains/upload/pddl",
4649
{
@@ -55,6 +58,8 @@ export default function DropAndFetch({ onStore, onClick, newURL }) {
5558
onStore(txt);
5659
} catch (error) {
5760
alert(error);
61+
} finally {
62+
setLoading(false);
5863
}
5964
};
6065

@@ -92,6 +97,7 @@ export default function DropAndFetch({ onStore, onClick, newURL }) {
9297
onFileLoad={handleFileLoad}
9398
/>
9499
))}
100+
{loading && <div className={css.loadingBox}/>}
95101
</Container>
96102
<Container maxWidth="sm" component="main">
97103
<div className={css.buttonBox}>
@@ -102,14 +108,18 @@ export default function DropAndFetch({ onStore, onClick, newURL }) {
102108
>
103109
Cancel
104110
</Button>
111+
<div className={css.wrapper}>
105112
<Button
106113
variant="contained"
107114
color="primary"
108115
startIcon={<CloudUploadIcon />}
109116
onClick={handleSubmit}
117+
disabled={loading}
110118
>
111119
Upload Files
112120
</Button>
121+
{loading && <CircularProgress size={24} className={css.loading}/>}
122+
</div>
113123
</div>
114124
</Container>
115125
</div>

src/pages/PageOne/index.module.less

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,23 @@ background: #fff;
2020
*/
2121
display: flex;
2222
justify-content: space-around;
23+
position: relative;
24+
25+
}
26+
.wrapper {
27+
position: relative;
28+
29+
}
30+
.loading {
31+
position: absolute;
32+
top: 5px;
33+
left: 71px;
34+
}
35+
.loadingBox {
36+
position: absolute;
37+
top: 0;
38+
left: 0;
39+
right: 0;
40+
bottom: 0;
41+
z-index: 999;
2342
}

0 commit comments

Comments
 (0)