Skip to content

Commit 23d3c1b

Browse files
authored
Merge pull request #165 from parteekcoder/contribute_feature
frontend of Contribute Feature
2 parents 05c77c2 + 066a045 commit 23d3c1b

8 files changed

Lines changed: 164 additions & 5 deletions

File tree

src/App.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import FileDragDrop from './component/File-drag-drop';
1414
import HistoryModal from './component/modals/History';
1515
import LocalFileBrowser from './component/fileBrowser';
1616
import FileEditModal from './component/modals/FileEdit';
17+
import ContributeDetails from './component/modals/ContributeDetails';
1718

1819
const app = () => {
1920
const [superState, dispatcher] = useReducer(reducer, initialState);
@@ -33,6 +34,7 @@ const app = () => {
3334
<ShareModal superState={superState} dispatcher={dispatcher} />
3435
<SettingsModal superState={superState} dispatcher={dispatcher} />
3536
<HistoryModal superState={superState} dispatcher={dispatcher} />
37+
<ContributeDetails superState={superState} dispatcher={dispatcher} />
3638
<FileEditModal superState={superState} dispatcher={dispatcher} />
3739
<GraphCompDetails
3840
closeModal={() => dispatcher({ type: T.Model_Close })}
@@ -49,7 +51,7 @@ const app = () => {
4951
</div>
5052
</section>
5153
<ReactTooltip place="bottom" type="dark" effect="solid" />
52-
<ToastContainer position="top-right" autoClose={5000} pauseOnHover={false} />
54+
<ToastContainer position="bottom-left" autoClose={8000} pauseOnHover={false} />
5355
</div>
5456
);
5557
};
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import React, { useState } from 'react';
2+
import { toast } from 'react-toastify';
3+
import axios from 'axios';
4+
import Modal from './ParentModal';
5+
import { actionType as T } from '../../reducer';
6+
import './contributeDetails.css';
7+
8+
const ContributeDetails = ({ superState, dispatcher }) => {
9+
const closeModal = () => {
10+
dispatcher({ type: T.SET_CONTRIBUTE_MODAL, payload: false });
11+
};
12+
const [study, setStudy] = useState('');
13+
const [path, setPath] = useState('');
14+
const [auth, setAuth] = useState('');
15+
const [title, setTitle] = useState('');
16+
const [desc, setDesc] = useState('');
17+
const [branch, setBranch] = useState('');
18+
const [showAdvanceOptions, setShowAdvanceOptions] = useState(false);
19+
const submit = async (e) => {
20+
if (study === '' || path === '' || auth === '') {
21+
toast.info('Please Provide necessary inputs');
22+
return;
23+
}
24+
const id = toast.loading('Processing your Request.Please wait...');
25+
try {
26+
e.preventDefault();
27+
const result = await axios.post('http://127.0.0.1:5000/contribute', {
28+
study,
29+
auth,
30+
desc,
31+
title,
32+
path,
33+
branch,
34+
});
35+
toast.success(result.data?.message);
36+
} catch (error) {
37+
if (error?.response?.status === 400) {
38+
toast.info(error?.response?.data?.message);
39+
} else {
40+
toast.error(error?.response.data.message);
41+
}
42+
}
43+
toast.dismiss(id);
44+
closeModal();
45+
};
46+
const toggleOptions = () => {
47+
setShowAdvanceOptions(!showAdvanceOptions);
48+
};
49+
return (
50+
<Modal
51+
ModelOpen={superState.contributeModal}
52+
title="Contribute"
53+
closeModal={closeModal}
54+
>
55+
<form className="contribute-details">
56+
<span>Study Name</span>
57+
<input
58+
required
59+
value={study}
60+
onChange={(e) => setStudy(e.target.value)}
61+
/>
62+
<span>Study Path</span>
63+
<input
64+
placeholder="Enter Full Directory Path of Study"
65+
value={path}
66+
onChange={(e) => setPath(e.target.value)}
67+
required
68+
/>
69+
<span>Author Name</span>
70+
<input
71+
value={auth}
72+
onChange={(e) => setAuth(e.target.value)}
73+
required
74+
/>
75+
{showAdvanceOptions && (
76+
<>
77+
<span>Branch Name</span>
78+
<input
79+
value={branch}
80+
onChange={(e) => setBranch(e.target.value)}
81+
/>
82+
<span>Title of Study</span>
83+
<input
84+
value={title}
85+
onChange={(e) => setTitle(e.target.value)}
86+
/>
87+
<span>Description of Study</span>
88+
<textarea
89+
value={desc}
90+
onChange={(e) => setDesc(e.target.value)}
91+
/>
92+
</>
93+
)}
94+
<button type="button" className="btn btn-secondary" onClick={toggleOptions}>
95+
{showAdvanceOptions ? 'Hide ' : 'Show '}
96+
Advance Options
97+
</button>
98+
<div className="expand">
99+
<button type="submit" className="btn btn-primary" onClick={submit}>Generate PR</button>
100+
</div>
101+
</form>
102+
</Modal>
103+
);
104+
};
105+
export default ContributeDetails;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.contribute-details{
2+
padding: 20px;
3+
display: grid;
4+
grid-template-columns: auto auto;
5+
gap: 20px;
6+
}
7+
8+
.contribute-details *{
9+
padding: 10px 5px;
10+
text-align: center;
11+
}
12+
13+
.contribute-details .expand{
14+
grid-column: 1 / span 2;
15+
padding: 0;
16+
}
17+
18+
.contribute-details .btn{
19+
width: 100%;
20+
}
21+
.contribute-details .btn-secondary{
22+
align-self: flex-end;
23+
}
24+
.contribute-details textarea{
25+
resize: vertical;
26+
max-height: 200px;
27+
max-width: 300px;
28+
text-align: left;
29+
max-lines: 10;
30+
}
31+
.Toastify__toast-container {
32+
/* width: 350px; */
33+
/* height: 80px; */
34+
padding: 3px 15px;
35+
display: inline-block;
36+
}
37+
38+
.Toastify__toast {
39+
/* width: 350px; */
40+
/* height: 80px; */
41+
width: fit-content;
42+
font-size: 16px;
43+
}

src/reducer/actionType.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const actionType = {
2323
NEW_GRAPH: 'NEW_GRAPH',
2424
SET_SHARE_MODAL: 'SET_SHARE_MODAL',
2525
SET_SETTING_MODAL: 'SET_SETTING_MODAL',
26+
SET_CONTRIBUTE_MODAL: 'SET_CONTRIBUTE_MODAL',
2627
SET_FILE_REF: 'SET_FILE_REF',
2728
SET_HISTORY_MODAL: 'SET_HISTORY_MODAL',
2829
SET_AUTHOR: 'SET_AUTHOR',

src/reducer/initialState.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const initialState = {
1313
settingsModal: false,
1414
editDetailsModal: false,
1515
newGraphModal: false,
16+
contributeModal: false,
1617

1718
eleSelected: false,
1819
drawModeOn: true,

src/reducer/reducer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ const reducer = (state, action) => {
6464
},
6565
};
6666
}
67+
case T.SET_CONTRIBUTE_MODAL: {
68+
return { ...state, contributeModal: action.payload };
69+
}
6770
case T.Model_Close: return { ...state, ModelOpen: false };
6871
case T.ELE_SELECTED: return { ...state, eleSelected: true, eleSelectedPayload: action.payload };
6972
case T.ELE_UNSELECTED: return { ...state, eleSelected: false };

src/toolbarActions/toolbarFunctions.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ const clearAll = (state) => {
145145
getGraphFun(state).clearAll();
146146
};
147147

148+
const contribute = (state, setState) => {
149+
setState({ type: T.SET_CONTRIBUTE_MODAL, payload: true });
150+
};
151+
148152
const resetAfterClear = (state) => {
149153
getGraphFun(state).resetAfterClear();
150154
};
@@ -187,5 +191,5 @@ export {
187191
createNode, editElement, deleteElem, downloadImg, saveAction, saveGraphMLFile,
188192
createFile, readFile, readTextFile, newProject, clearAll, editDetails, undo, redo,
189193
openShareModal, openSettingModal, viewHistory, resetAfterClear,
190-
toggleServer,
194+
toggleServer, contribute,
191195
};

src/toolbarActions/toolbarList.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import {
1313
createNode, editElement, deleteElem, downloadImg, saveAction, saveGraphMLFile,
1414
createFile, readFile, clearAll, undo, redo, viewHistory, resetAfterClear,
15-
toggleServer,
15+
toggleServer, contribute,
1616
// openSettingModal,
1717
} from './toolbarFunctions';
1818

@@ -227,8 +227,8 @@ const toolbarList = (state, dispatcher) => [
227227
type: 'action',
228228
text: 'Contribute',
229229
icon: FiTriangle,
230-
action: () => { window.open('https://github.com/ControlCore-Project/concore', '_blank'); },
231-
active: state.curGraphInstance || state.uploadedDirName,
230+
action: contribute,
231+
active: true,
232232
visibility: true,
233233
},
234234
// {

0 commit comments

Comments
 (0)