@@ -6,11 +6,13 @@ import './nodeDetails.css';
66import localStorageManager from '../../graph-builder/local-storage-manager' ;
77
88const NodeDetails = ( {
9- data, setData, submit, labelAllowed,
9+ data, setData, submit, labelAllowed, state ,
1010} ) => {
1111 const inputRef = useCallback ( ( node ) => node && node . focus ( ) , [ ] ) ;
1212 const textRef = createRef ( ) ;
1313 const [ widthSet ] = useState ( false ) ;
14+ const [ mdList , setMdList ] = useState ( [ ] ) ;
15+ const [ mdCont , setMdCont ] = useState ( new Map ( '' ) ) ;
1416 const [ labelName , setLabelName ] = useState ( '' ) ;
1517 const [ labelFile , setLabelFile ] = useState ( '' ) ;
1618 const indexOfFile = [ ] ;
@@ -20,6 +22,25 @@ const NodeDetails = ({
2022 setData ( { ...data , style : { ...data . style , ...prop } } ) ;
2123 } ;
2224
25+ useEffect ( ( ) => {
26+ const list = mdList ;
27+ state . fileState . forEach ( ( ele ) => {
28+ if ( ele . key . toString ( ) . includes ( '.md' ) ) {
29+ list . push ( ele ) ;
30+ setMdList ( list ) ;
31+ let mdmap = new Map ( ) ;
32+ mdmap = mdCont ;
33+ const fr = new FileReader ( ) ;
34+ fr . onload = ( x ) => {
35+ const strCont = ' : ' ;
36+ mdmap . set ( ele , strCont . concat ( x . target . result . slice ( 0 , 50 ) . replace ( '#' , '' ) ) ) ;
37+ setMdCont ( mdmap ) ;
38+ } ;
39+ fr . readAsText ( ele . fileObj ) ;
40+ }
41+ } ) ;
42+ } , [ state . fileState ] ) ;
43+
2344 useEffect ( ( ) => {
2445 if ( ! widthSet ) {
2546 setStyle ( {
@@ -104,29 +125,42 @@ const NodeDetails = ({
104125 value = { data . label . split ( ':' ) [ 1 ] }
105126 onChange = { ( e ) => {
106127 setLabelFile ( e . target . value . split ( '/' ) . pop ( ) ) ;
128+ setLabelFile ( e . target . value . split ( ' :' ) [ 0 ] ) ;
107129 if ( labelName ) {
108130 let lname = labelName ;
109131 if ( labelName . slice ( - 1 ) !== ':' ) {
110132 setLabelName ( `${ labelName } :` ) ;
111133 lname += ':' ;
112134 }
113- setData ( { ...data , label : lname + e . target . value . split ( '/' ) . pop ( ) } ) ;
114- } else setData ( { ...data , label : `:${ e . target . value . split ( '/' ) . pop ( ) } ` } ) ;
135+ // eslint-disable-next-line max-len
136+ setData ( { ...data , label : lname + e . target . value . split ( '/' ) . pop ( ) . split ( ' :' ) [ 0 ] } ) ;
137+ // eslint-disable-next-line max-len
138+ } else setData ( { ...data , label : `:${ e . target . value . split ( '/' ) . pop ( ) . split ( ' :' ) [ 0 ] } ` } ) ;
115139 } }
116140 list = "files"
117141 />
118142 < datalist id = "files" >
119143 {
120144 localStorageManager . getFileList ( )
121145 // eslint-disable-next-line max-len, prefer-arrow-callback
122- ? JSON . parse ( localStorageManager . getFileList ( ) )
146+ ? state . fileState
123147 . map ( ( item ) => {
124148 const list = [ ] ;
125149 const acceptedTypes = [ '.v' , '.c' , '.cpp' , '.py' , '.m' , '.sh' ] ;
126150 let index ;
151+ if ( item . key . toString ( ) . includes ( '.md' ) ) {
152+ return null ;
153+ }
127154 // eslint-disable-next-line max-len
128155 if ( ( acceptedTypes . some ( ( substring ) => item . key . toString ( ) . includes ( substring ) ) ) ) {
129- list . push ( item . key . toString ( ) ) ;
156+ const fileName = item . key . toString ( ) . split ( '.' ) [ 0 ] . concat ( '.md' ) ;
157+ // eslint-disable-next-line max-len
158+ const matchingFile = mdList . find ( ( ele ) => ele . key . toString ( ) === fileName ) ;
159+ if ( mdCont . get ( matchingFile ) ) {
160+ list . push ( item . key . toString ( ) . concat ( mdCont . get ( matchingFile ) ) ) ;
161+ } else {
162+ list . push ( item . key . toString ( ) ) ;
163+ }
130164 indexOfFile . push ( indexOfFile [ indexOfFile . length - 1 ] + 1 ) ;
131165 index = indexOfFile [ indexOfFile . length - 1 ] + 1 ;
132166 // eslint-disable-next-line jsx-a11y/control-has-associated-label
0 commit comments