Skip to content

Commit f899f00

Browse files
committed
fixing author error
1 parent 70c7536 commit f899f00

4 files changed

Lines changed: 33 additions & 18 deletions

File tree

src/component/modals/ProjectDetails.jsx

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,32 @@ 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);
4642
localStorageManager.setAuthorName(authorName);
4743
};
4844

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ class CoreGraph {
106106
this.cy.emit('graph-modified');
107107
}
108108

109+
setProjectAuthor(authorName, shouldEmit = true) {
110+
this.authorName = authorName;
111+
if (shouldEmit) {
112+
this.dispatcher({
113+
type: T.SET_AUTHOR,
114+
payload: {
115+
value: authorName,
116+
graphID: this.id,
117+
type: 'authorName',
118+
},
119+
});
120+
}
121+
this.cy.emit('graph-modified');
122+
}
123+
109124
setServerID(serverID, shouldEmit = true) {
110125
this.serverID = serverID;
111126
if (shouldEmit) {

src/reducer/initialState.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const initialState = {
2121
graphs: [],
2222
curGraphIndex: 0,
2323
viewHistory: false,
24-
authorName: '',
2524
isWorkflowOnServer: false,
2625
curGraphInstance: null,
2726
zoomLevel: 100,
@@ -32,7 +31,7 @@ const initialGraphState = {
3231
graphID: null,
3332
serverID: null,
3433
graphML: null,
35-
34+
authorName: '',
3635
component: null,
3736
instance: null,
3837
id: null,

src/reducer/reducer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ const reducer = (state, action) => {
9797
graphML: action.payload.graphML,
9898
fileHandle: action.payload.fileHandle || null,
9999
fileName: action.payload.fileName,
100+
authorName: action.payload.authorName,
100101
},
101102
],
102103
};
@@ -153,7 +154,11 @@ const reducer = (state, action) => {
153154
}
154155

155156
case T.SET_AUTHOR: {
156-
return { ...state, authorName: action.payload };
157+
const newState = { ...state };
158+
newState.graphs = newState.graphs.map((g) => (
159+
g.graphID === action.payload.graphID ? { ...g, [action.payload.type]: action.payload.value } : g
160+
));
161+
return { ...newState };
157162
}
158163

159164
case T.IS_WORKFLOW_ON_SERVER: {

0 commit comments

Comments
 (0)