Skip to content

Commit d3e0739

Browse files
authored
Merge pull request #115 from parteekcoder/author_fix
Author fix
2 parents 854fa5d + c8aeb96 commit d3e0739

File tree

13 files changed

+67
-40
lines changed

13 files changed

+67
-40
lines changed

src/GraphArea.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import MyGraph from './graph-builder';
44
import { actionType as T } from './reducer';
55

66
function Graph({
7-
el, superState, dispatcher, graphID, serverID, graphML, projectName, graphContainerRef, active,
7+
el, superState, dispatcher, graphID, serverID, graphML, projectName, graphContainerRef, active, authorName,
88
}) {
99
const [instance, setInstance] = useState(null);
1010
const ref = useRef();
@@ -18,7 +18,7 @@ function Graph({
1818

1919
const initialiseNewGraph = () => {
2020
const myGraph = new MyGraph(
21-
graphID, ref.current, dispatcher, superState, projectName, nodeValidator, edgeValidator,
21+
graphID, ref.current, dispatcher, superState, projectName, nodeValidator, edgeValidator, authorName,
2222
);
2323
if (graphID) myGraph.loadGraphFromLocalStorage();
2424
if (serverID) {

src/GraphWorkspace.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const GraphComp = (props) => {
7474
projectName={el.projectName}
7575
fileHandle={el.fileHandle}
7676
fileName={el.fileName}
77+
authorName={el.authorName}
7778
/>
7879
))}
7980
<ZoomComp dispatcher={dispatcher} superState={superState} />

src/component/modals/ProjectDetails.jsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,33 @@ const ProjectDetails = ({ superState, dispatcher }) => {
1313
const { newGraphModal } = superState;
1414
const editDetailsModal = superState.editDetailsModal || (curGraph && !curGraph.projectName);
1515

16-
const setProjAuthorName = (a) => {
17-
setAuthorName(a);
18-
dispatcher({
19-
type: T.SET_AUTHOR,
20-
payload: a,
21-
});
22-
};
23-
2416
useEffect(() => {
2517
if (superState.editDetailsModal && curGraph) {
2618
setProjectName(curGraph.projectName);
27-
} else setProjectName('');
28-
}, [superState.authorName, superState.editDetailsModal, curGraph]);
19+
setAuthorName(curGraph.authorName);
20+
} else {
21+
setProjectName('');
22+
}
23+
}, [curGraph?.authorName, superState.editDetailsModal, curGraph]);
2924

3025
useEffect(() => {
31-
if (superState.authorName) setAuthorName(superState.authorName);
32-
else {
26+
if (curGraph?.authorName) {
27+
setAuthorName(curGraph.authorName);
28+
} else {
3329
const authorNameE = localStorageManager.getAuthorName();
34-
setProjAuthorName(authorNameE);
30+
setAuthorName(authorNameE);
3531
}
3632
}, []);
3733

3834
const submit = (e) => {
3935
e.preventDefault();
40-
if (newGraphModal) dispatcher({ type: T.ADD_GRAPH, payload: { projectName } });
36+
if (newGraphModal) dispatcher({ type: T.ADD_GRAPH, payload: { projectName, authorName } });
4137
else if (editDetailsModal) {
4238
superState.curGraphInstance.setProjectName(projectName);
39+
superState.curGraphInstance.setProjectAuthor(authorName);
4340
dispatcher({ type: T.SET_EDIT_DETAILS_MODAL, payload: false });
4441
}
45-
setProjAuthorName(authorName);
42+
localStorageManager.saveAllgs();
4643
localStorageManager.setAuthorName(authorName);
4744
};
4845

src/graph-builder/graph-core/1-core.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ class CoreGraph {
1717

1818
projectName;
1919

20+
authorName;
21+
2022
cy;
2123

2224
bendNode;
2325

24-
constructor(id, element, dispatcher, superState, projectName) {
26+
constructor(id, element, dispatcher, superState, projectName, nodeValidator, edgeValidator, authorName) {
2527
if (dispatcher) this.dispatcher = dispatcher;
2628
if (superState) this.superState = superState;
2729
if (typeof cytoscape('core', 'edgehandles') !== 'function') {
@@ -37,6 +39,7 @@ class CoreGraph {
3739
this.cy = cytoscape({ ...cyOptions, container: element });
3840
this.id = id;
3941
this.projectName = projectName;
42+
this.authorName = authorName;
4043
this.cy.emit('graph-modified');
4144
this.bendNode = this.cy.add(
4245
{ group: 'nodes', data: { type: 'bend' }, classes: ['hidden'] },
@@ -83,12 +86,13 @@ class CoreGraph {
8386
}
8487

8588
set({
86-
cy, dispatcher, superState, projectName,
89+
cy, dispatcher, superState, projectName, authorName,
8790
}) {
8891
if (dispatcher) this.dispatcher = dispatcher;
8992
if (superState) this.superState = superState;
9093
if (cy) this.cy = cy;
9194
if (projectName) this.projectName = projectName;
95+
if (authorName) this.authorName = authorName;
9296
}
9397

9498
setProjectName(projectName, shouldEmit = true) {
@@ -106,6 +110,21 @@ class CoreGraph {
106110
this.cy.emit('graph-modified');
107111
}
108112

113+
setProjectAuthor(authorName, shouldEmit = true) {
114+
this.authorName = authorName;
115+
if (shouldEmit) {
116+
this.dispatcher({
117+
type: T.SET_AUTHOR,
118+
payload: {
119+
value: authorName,
120+
graphID: this.id,
121+
type: 'authorName',
122+
},
123+
});
124+
}
125+
this.cy.emit('graph-modified');
126+
}
127+
109128
setServerID(serverID, shouldEmit = true) {
110129
this.serverID = serverID;
111130
if (shouldEmit) {

src/graph-builder/graph-core/4-undo-redo.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,17 @@ class GraphUndoRedo extends GraphComponent {
8383
return r;
8484
}
8585

86-
addAction(inverse, equivalent, tid, authorName = this.superState.authorName) {
86+
addAction(inverse, equivalent, tid) {
8787
if (tid === 0) return;
8888
this.actionArr.splice(this.curActionIndex);
8989

9090
const actionIdentity = GraphUndoRedo.sequencify(equivalent).toString()
9191
+ GraphUndoRedo.sequencify(equivalent).toString()
92-
+ tid
93-
+ authorName;
92+
+ tid;
9493
this.actionArr.push({
9594
tid,
9695
inverse,
9796
equivalent,
98-
authorName,
9997
hash: md5(
10098
`${actionIdentity}|${this.actionArr.length ? this.actionArr.at(-1).hash : ''}`,
10199
),

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class GraphLoadSave extends GraphUndoRedo {
6060
serverID: this.serverID,
6161
fileName: null,
6262
fileHandle: null,
63+
authorName: this.authorName,
6364
};
6465
this.cy.nodes().forEach((node) => {
6566
if (this.shouldNodeBeSaved(node.id())) {
@@ -87,10 +88,9 @@ class GraphLoadSave extends GraphUndoRedo {
8788
}
8889
});
8990
graph.actionHistory = this.actionArr.map(({
90-
tid, inverse, equivalent, authorName, hash,
91+
tid, inverse, equivalent, hash,
9192
}) => ({
9293
tid,
93-
authorName,
9494
inverse: GraphLoadSave.stringifyAction(inverse),
9595
equivalent: GraphLoadSave.stringifyAction(equivalent),
9696
hash,
@@ -176,12 +176,13 @@ class GraphLoadSave extends GraphUndoRedo {
176176
this.addEdge({ ...edge, sourceID: edge.source, targetID: edge.target }, 0);
177177
});
178178
content.actionHistory.forEach(({
179-
inverse, equivalent, tid, authorName,
179+
inverse, equivalent, tid,
180180
}) => {
181-
this.addAction(GraphLoadSave.parseAction(inverse), GraphLoadSave.parseAction(equivalent), tid, authorName);
181+
this.addAction(GraphLoadSave.parseAction(inverse), GraphLoadSave.parseAction(equivalent), tid);
182182
});
183183
this.setProjectName(content.projectName);
184184
this.setServerID(this.serverID || content.serverID);
185+
this.setProjectAuthor(content.authorName);
185186
}
186187

187188
saveLocalStorage() {

src/graph-builder/graphml/builder/graphML.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const graphML = ({
2-
nodes, edges, id, projectName, actionHistory, serverID, fileHandle, fileName,
2+
nodes, edges, id, projectName, authorName, actionHistory, serverID, fileHandle, fileName,
33
}) => ({
44
graphml: {
55
$: {
@@ -33,6 +33,7 @@ const graphML = ({
3333
serverID,
3434
fileHandle,
3535
fileName,
36+
authorName,
3637
},
3738
node: nodes,
3839
edge: edges,

src/graph-builder/graphml/builder/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const builder = (G) => {
3030
serverID: G.serverID,
3131
fileHandle: G.fileHandle,
3232
fileName: G.fileName,
33+
authorName: G.authorName,
3334
});
3435
const xml = new xml2js.Builder().buildObject(X);
3536
return xml;

src/graph-builder/graphml/parser/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ const parser = (graphMlCnt) => new Promise((resolve) => {
99
const grahML = new PropFromArr(grahMLObj);
1010
const nodes = grahML.parseProps('graphml.graph.node', 1).map(parseNode);
1111
const edges = grahML.parseProps('graphml.graph.edge', 1).map(parseEdge);
12-
const { id, projectName, serverID } = parseDetails(grahML);
12+
const {
13+
id, projectName, serverID, authorName,
14+
} = parseDetails(grahML);
1315
const actionHistory = parseActionHistory(grahML);
1416
resolve({
15-
id, projectName, edges, nodes, actionHistory, serverID,
17+
id, projectName, edges, nodes, actionHistory, serverID, authorName,
1618
});
1719
});
1820
});

src/graph-builder/graphml/parser/parseProperties.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ const parseActionML = (({ actionName, parameters }) => ({ actionName: actionName
4646

4747
const parseActionHistory = (grahML) => grahML.parseProps('graphml.graph.actionHistory', 1)
4848
.map(({
49-
authorName, equivalent, inverse, tid,
49+
equivalent, inverse, tid,
5050
}) => ({
51-
authorName: authorName[0],
51+
5252
equivalent: parseActionML(equivalent[0]),
5353
inverse: parseActionML(inverse[0]),
5454
tid: tid[0],

0 commit comments

Comments
 (0)