Skip to content

Commit 217495d

Browse files
committed
2 parents a7a7dec + ce07004 commit 217495d

8 files changed

Lines changed: 55 additions & 13 deletions

File tree

package-lock.json

Lines changed: 34 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
@@ -31,6 +31,7 @@
3131
"react-modal": "^3.13.1",
3232
"react-scripts": "4.0.3",
3333
"react-simple-code-editor": "^0.13.0",
34+
"react-toastify": "^8.0.0",
3435
"react-tooltip": "^4.2.21",
3536
"web-vitals": "^0.2.4",
3637
"workbox-background-sync": "^5.1.3",

src/App.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import React, { useEffect, useReducer } from 'react';
2+
import { ToastContainer } from 'react-toastify';
3+
import 'react-toastify/dist/ReactToastify.css';
24
import './App.css';
35
import ReactTooltip from 'react-tooltip';
46
import GraphWorkspace from './GraphWorkspace';
@@ -47,6 +49,7 @@ const app = () => {
4749
</div>
4850
</section>
4951
<ReactTooltip place="bottom" type="dark" effect="solid" />
52+
<ToastContainer position="top-right" autoClose={5000} pauseOnHover={false} />
5053
</div>
5154
);
5255
};

src/component/File-drag-drop.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const app = ({ superState, dispatcher }) => {
3939
fileRef.current.value = null;
4040
if (e.dataTransfer.files.length === 1
4141
&& e.dataTransfer.files[0].name.split('.').slice(-1)[0] === 'graphml') {
42-
readFile(superState, dispatcher, { target: e.dataTransfer });
42+
readFile(superState, dispatcher, e.dataTransfer.files[0]);
4343
}
4444
});
4545
}, []);

src/graph-builder/graph-core/5-load-save.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { saveAs } from 'file-saver';
2+
import { toast } from 'react-toastify';
23
import localStorageManager from '../local-storage-manager';
34
import graphmlBuilder from '../graphml/builder';
45
import BendingDistanceWeight from '../calculations/bending-dist-weight';
@@ -125,9 +126,15 @@ class GraphLoadSave extends GraphUndoRedo {
125126
const fileName = prompt('Filename:');
126127
saveAs(blob, `${fileName || `${this.getName()}-concore`}.graphml`);
127128
}
129+
toast.success('File saved Successfully');
128130
}
129131

130132
async saveWithoutFileHandle() {
133+
const { userAgent } = navigator;
134+
if (userAgent.match(/firefox|fxios/i)) {
135+
toast.info('Switch to Edge/Chrome!');
136+
return;
137+
}
131138
const str = graphmlBuilder(this.jsonifyGraph());
132139
const bytes = new TextEncoder().encode(str);
133140
const blob = new Blob([bytes], { type: 'application/json;charset=utf-8' });
@@ -149,8 +156,7 @@ class GraphLoadSave extends GraphUndoRedo {
149156
const stream = await handle.createWritable();
150157
await stream.write(blob);
151158
await stream.close();
152-
// eslint-disable-next-line no-alert
153-
alert('File saved Successfully');
159+
toast.success('File saved Successfully');
154160
}
155161

156162
saveToFolder() {

src/reducer/reducer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ const reducer = (state, action) => {
141141

142142
case T.SET_FILE_HANDLE: {
143143
const newState = { ...state };
144-
newState.graphs = newState.graphs.map((g) => (
145-
newState.curGraphIndex === action.payload.curGraphIndex ? { ...g, fileHandle: action.payload.fileHandle }
144+
newState.graphs = newState.graphs.map((g, index) => (
145+
index === action.payload.curGraphIndex ? { ...g, fileHandle: action.payload.fileHandle }
146146
: g
147147
));
148148
return { ...newState };

src/toolbarActions/toolbarFunctions.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { toast } from 'react-toastify';
12
import { actionType as T } from '../reducer';
23

34
const getGraphFun = (superState) => superState.curGraphInstance;
@@ -88,17 +89,14 @@ async function saveGraphMLFile(state) {
8889
const stream = await graph.fileHandle.createWritable();
8990
await stream.write(getGraphFun(state).saveToFolder());
9091
await stream.close();
91-
// eslint-disable-next-line no-alert
92-
alert('File saved Successfully');
93-
} else if (graph.fileHandle === null) {
92+
toast.success('File saved Successfully');
93+
} else if (!graph.fileHandle) {
9494
getGraphFun(state).saveWithoutFileHandle();
9595
} else {
96-
// eslint-disable-next-line no-alert
97-
alert('Switch to Edge/Chrome!');
96+
toast.info('Switch to Edge/Chrome!');
9897
}
9998
} else {
100-
// eslint-disable-next-line no-alert
101-
alert('Switch to Edge/Chrome!');
99+
toast.info('Switch to Edge/Chrome!');
102100
}
103101
}
104102

src/toolbarActions/toolbarList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const toolbarList = (state, dispatcher) => [
5757
text: 'Save As',
5858
icon: FaSave,
5959
action: (s, d) => saveAction(s, d),
60-
active: true,
60+
active: state.curGraphInstance,
6161
visibility: true,
6262
},
6363
{

0 commit comments

Comments
 (0)