Skip to content

Commit 69c0659

Browse files
authored
Merge pull request #392 from GREENRAT-K405/feat/autofill-contribute-detail
2 parents eccddfd + 941ad35 commit 69c0659

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

src/component/modals/ContributeDetails.jsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useEffect, useRef } from 'react';
22
import { toast } from 'react-toastify';
33
import axios from 'axios';
44
import { EXECUTION_ENGINE_URL } from '../../serverCon/config';
@@ -10,13 +10,36 @@ const ContributeDetails = ({ superState, dispatcher }) => {
1010
const closeModal = () => {
1111
dispatcher({ type: T.SET_CONTRIBUTE_MODAL, payload: false });
1212
};
13-
const [study, setStudy] = useState('');
14-
const [path, setPath] = useState('');
15-
const [auth, setAuth] = useState('');
13+
14+
const curGraph = superState.graphs[superState.curGraphIndex] ?? {};
15+
16+
const [study, setStudy] = useState(curGraph.projectName ?? '');
17+
const [path, setPath] = useState(superState.uploadedDirName ?? '');
18+
const [auth, setAuth] = useState(curGraph.authorName ?? '');
1619
const [title, setTitle] = useState('');
1720
const [desc, setDesc] = useState('');
1821
const [branch, setBranch] = useState('');
1922
const [showAdvanceOptions, setShowAdvanceOptions] = useState(false);
23+
const prevOpenRef = useRef(false);
24+
25+
useEffect(() => {
26+
if (superState.contributeModal && !prevOpenRef.current) {
27+
const activeGraph = superState.graphs[superState.curGraphIndex] ?? {};
28+
setStudy(activeGraph.projectName ?? '');
29+
setPath(superState.uploadedDirName ?? '');
30+
setAuth(activeGraph.authorName ?? '');
31+
setTitle('');
32+
setDesc('');
33+
setBranch('');
34+
setShowAdvanceOptions(false);
35+
}
36+
prevOpenRef.current = superState.contributeModal;
37+
}, [
38+
superState.contributeModal,
39+
superState.graphs,
40+
superState.curGraphIndex,
41+
superState.uploadedDirName,
42+
]);
2043
const submit = async (e) => {
2144
if (study === '' || path === '' || auth === '') {
2245
toast.info('Please Provide necessary inputs');

0 commit comments

Comments
 (0)