Skip to content

Commit e644637

Browse files
committed
Loader Added
1 parent 232f186 commit e644637

8 files changed

Lines changed: 60 additions & 10 deletions

File tree

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"react-modal": "^3.13.1",
3333
"react-scripts": "4.0.3",
3434
"react-simple-code-editor": "^0.13.0",
35+
"react-spinners": "^0.13.8",
3536
"react-toastify": "^8.0.0",
3637
"react-tooltip": "^4.2.21",
3738
"web-vitals": "^0.2.4",

src/App.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import LocalFileBrowser from './component/fileBrowser';
1616
import FileEditModal from './component/modals/FileEdit';
1717
import MarkDown from './component/modals/markDown';
1818
import OptionsModal from './component/modals/OptionsModal';
19+
import Loader from './component/modals/Loader';
1920

2021
const app = () => {
2122
const [superState, dispatcher] = useReducer(reducer, initialState);
@@ -37,6 +38,7 @@ const app = () => {
3738
<HistoryModal superState={superState} dispatcher={dispatcher} />
3839
<FileEditModal superState={superState} dispatcher={dispatcher} />
3940
<OptionsModal superState={superState} dispatcher={dispatcher} />
41+
<Loader superState={superState} />
4042
<GraphCompDetails
4143
closeModal={() => dispatcher({ type: T.Model_Close })}
4244
superState={superState}

src/component/modals/Loader.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import BeatLoader from 'react-spinners/BeatLoader';
3+
import ParentModal from './ParentModal';
4+
5+
const Loader = ({ superState }) => (
6+
<ParentModal ModelOpen={superState.loader} title="Wait........">
7+
<BeatLoader color="#36d7b7" />
8+
</ParentModal>
9+
);
10+
11+
export default Loader;

src/graph-builder/graph-core/6-server.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,71 +68,85 @@ class GraphServer extends GraphLoadSave {
6868

6969
build() {
7070
// TODO
71+
this.dispatcher({ type: T.SET_LOADER, payload: true });
7172
Axios.post(`http://127.0.0.1:5000/build/${this.superState.uploadedDirName}?fetch=${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}&unlock=${this.superState.unlockCheck}&docker=${this.superState.dockerCheck}&maxtime=${this.superState.maxTime}&params=${this.superState.params}`)
7273
.then((res) => { // eslint-disable-next-line
7374
toast.success(res.data['message'])
75+
this.dispatcher({ type: T.SET_LOADER, payload: false });
7476
}).catch((err) => { // eslint-disable-next-line
75-
toast.success(err);
77+
toast.error(err.message);
78+
this.dispatcher({ type: T.SET_LOADER, payload: false });
7679
});
7780
if (this.serverID);
7881
}
7982

8083
debug() {
8184
// TODO
85+
this.dispatcher({ type: T.SET_LOADER, payload: true });
8286
Axios.post(`http://127.0.0.1:5000/debug/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
8387
.then((res) => { // eslint-disable-next-line
8488
toast.success(res.data['message'])
89+
this.dispatcher({ type: T.SET_LOADER, payload: false });
8590
}).catch((err) => { // eslint-disable-next-line
86-
toast.success(err);
91+
toast.error(err.message);
92+
this.dispatcher({ type: T.SET_LOADER, payload: false });
8793
});
8894
if (this.serverID);
8995
}
9096

9197
run() {
9298
// TODO
99+
this.dispatcher({ type: T.SET_LOADER, payload: true });
93100
Axios.post(`http://127.0.0.1:5000/run/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
94101
.then((res) => { // eslint-disable-next-line
95102
toast.success(res.data['message'])
103+
this.dispatcher({ type: T.SET_LOADER, payload: false });
96104
}).catch((err) => { // eslint-disable-next-line
97-
toast.success(err);
105+
toast.error(err.message);
106+
this.dispatcher({ type: T.SET_LOADER, payload: false });
98107
});
99108
if (this.serverID);
100109
}
101110

102111
clear() {
103112
// TODO
113+
this.dispatcher({ type: T.SET_LOADER, payload: true });
104114
Axios.post(`http://127.0.0.1:5000/clear/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}
105115
?unlock=${this.superState.unlockCheck}&maxtime=${this.superState.maxTime}&params=${this.superState.params}`)
106116
.then((res) => { // eslint-disable-next-line
107117
toast.success(res.data['message']);
108-
// console.log(this.superState.dockerCheck);
109-
// console.log(this.superState.unlockCheck);
110-
// console.log(this.superState.maxTime);
111-
// console.log(this.superState.params);
118+
this.dispatcher({ type: T.SET_LOADER, payload: false });
112119
}).catch((err) => { // eslint-disable-next-line
113-
toast.success(err);
120+
toast.error(err.message);
121+
this.dispatcher({ type: T.SET_LOADER, payload: false });
114122
});
115123
if (this.serverID);
116124
}
117125

118126
stop() {
119127
// TODO
128+
this.dispatcher({ type: T.SET_LOADER, payload: true });
120129
Axios.post(`http://127.0.0.1:5000/stop/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
121130
.then((res) => { // eslint-disable-next-line
122131
toast.success(res.data['message'])
132+
this.dispatcher({ type: T.SET_LOADER, payload: false });
123133
}).catch((err) => { // eslint-disable-next-line
124-
toast.success(err);
134+
toast.error(err.message);
135+
this.dispatcher({ type: T.SET_LOADER, payload: false });
125136
});
126137
if (this.serverID);
127138
}
128139

129140
destroy() {
130141
// TODO
142+
this.dispatcher({ type: T.SET_LOADER, payload: true });
131143
Axios.delete(`http://127.0.0.1:5000/destroy/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
132144
.then((res) => { // eslint-disable-next-line
133145
toast.success(res.data['message'])
146+
this.dispatcher({ type: T.SET_LOADER, payload: false });
134147
}).catch((err) => { // eslint-disable-next-line
135-
toast.success(err);
148+
toast.error(err.message);
149+
this.dispatcher({ type: T.SET_LOADER, payload: false });
136150
});
137151
if (this.serverID);
138152
}

src/reducer/actionType.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const actionType = {
3939
SET_FILE_STATE: 'SET_FILE_STATE',
4040
SET_INPUT_FILE: 'SET_INPUT_FILE',
4141
SET_OPTIONS: 'SET_OPTIONS',
42+
SET_LOADER: 'SET_LOADER',
4243
};
4344

4445
export default zealit(actionType);

src/reducer/initialState.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const initialState = {
3333
maxTime: '',
3434
dockerCheck: false,
3535
unlockCheck: false,
36+
loader: false,
3637
};
3738

3839
const initialGraphState = {

src/reducer/reducer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ const reducer = (state, action) => {
181181
return { ...state, viewHistory: action.payload };
182182
}
183183

184+
case T.SET_LOADER: {
185+
return { ...state, loader: action.payload };
186+
}
187+
184188
case T.SET_AUTHOR: {
185189
const newState = { ...state };
186190
newState.graphs = newState.graphs.map((g) => (

0 commit comments

Comments
 (0)