@@ -11,19 +11,18 @@ const markdownContext = require.context('../docs', false, /\.md$/);
1111const markdownFiles = markdownContext
1212 . keys ( )
1313 //.map((filename) => markdownContext(filename))
14- console . log ( "hey" + markdownFiles ) ;
14+ // console.log("hey"+markdownFiles);
1515
1616class App extends React . Component {
1717 constructor ( props ) {
1818 super ( props ) ;
1919 this . state = {
2020 count : 5 ,
21- posts : ''
22- }
21+ posts1 : [ ]
22+ }
2323 }
2424
2525 componentDidMount ( ) {
26- console . log ( "mark files===>" + markdownFiles ) ;
2726 var newPosts = [ ] ;
2827 const posts = markdownFiles . forEach (
2928 ( file , key ) => {
@@ -34,31 +33,52 @@ class App extends React.Component {
3433 }
3534 ) ;
3635
37- console . log ( "posts array value ==>" + JSON . stringify ( newPosts ) )
38- const posts1 = Promise . all (
39- newPosts . forEach (
40- ( file , key ) => {
41- console . log ( "---> " + file . data + " ,===" + key )
42- fetch ( file . data )
43- . then ( res => res . text ( ) )
44- . then (
45- text =>
46- {
47- console . log ( "text===>" + text ) ;
48- //this.setState({ posts1: text });
49- }
50- )
51- }
52- )
53- ) ;
54- //console.log("posts array value ==>"+JSON.stringify(posts1))
55- //console.log("posts array value ==>"+JSON.stringify(newPosts))
56- //this.setState((state) => ({ ...state, posts }));
36+ //this.getFileResults(newPosts);
37+ this . apiGetAll ( "../README.md" ) ;
5738 }
5839
40+ async apiGetAll ( newPosts ) {
41+ console . log ( newPosts )
42+ try {
43+ const resp = await fetch ( newPosts ) . then ( res => res . text ( ) ) ;
44+
45+ const newResp = await Promise . all ( ( resp ) ) . then ( result => {
46+ console . log ( "hey--->" + result ) ;
47+ this . setState ( { posts1 : result } ) ;
48+ } ) ;
49+ console . log ( "dsffdsf====" + this . state . posts1 ) ;
50+ return newResp
51+ } catch ( err ) {
52+ console . log ( err )
53+ }
54+ }
55+
56+ /*getFileResults(newPosts) {
57+ let data = [];
58+ Promise.all(
59+ newPosts.forEach(
60+ (file) => {
61+ fetch(file.data)
62+ .then( res => res.text() )
63+ .then(
64+ text =>
65+ {
66+ console.log("text===>"+text);
67+ data.push(text);
68+ return data;
69+ //this.setState((state) => ({ ...state, posts1 }));
70+ }
71+ )
72+ }
73+ )
74+ ).then(result => {
75+ const [ data ] = result;
76+ console.log("hey--->"+result);
77+
78+ });
79+ }*/
80+
5981 render ( ) {
60- //const { newPosts } = this.state;
61- //console.log("posts array value ==>"+JSON.stringify(newPosts))
6282 return (
6383 < div >
6484 < Navigation />
@@ -72,7 +92,7 @@ class App extends React.Component {
7292 < div className = "content" >
7393 {
7494 //newPosts.map((post, idx) => (
75-
95+ this . state . posts1
7696 // ))
7797 }
7898 </ div >
0 commit comments