@@ -3,7 +3,7 @@ import { BrowserRouter as Router, Route } from 'react-router-dom';
3
3
import sortBy from 'lodash.sortby' ;
4
4
import urlEnv from '../../utils/urlEnv' ;
5
5
import profileContents from '../../utils/profileContents' ;
6
- import { queryFollowers } from '../../utils/following' ;
6
+ import { queryFollowers , followURLCheck } from '../../utils/following' ;
7
7
8
8
import ContentViewContainer from '../ContentViewContainer' ;
9
9
import Settings from '../Settings' ;
@@ -15,7 +15,7 @@ class App extends Component {
15
15
this . state = {
16
16
loading : true ,
17
17
contentSelectionOpen : false ,
18
- correctBrowser : false ,
18
+ correctBrowser : true ,
19
19
isOwner : false ,
20
20
posts : [ ] ,
21
21
theirPosts : [ ] ,
@@ -26,17 +26,16 @@ class App extends Component {
26
26
}
27
27
28
28
async componentDidMount ( ) {
29
- console . log ( 'hmmm' ) ;
30
29
try {
31
30
const archive = await new global . DatArchive ( urlEnv ( ) ) ;
32
31
const archiveInfo = await archive . getInfo ( ) ;
33
- const results = await this . refreshPosts ( archive ) ;
32
+ const allPosts = await this . getAllPosts ( archive ) ;
34
33
const theirresults = await this . refreshTheirPosts ( archive ) ;
35
34
const userData = await this . getUserInfo ( archive ) ;
36
35
37
36
this . setState ( {
38
37
correctBrowser : true ,
39
- posts : results ,
38
+ posts : allPosts ,
40
39
theirPosts : theirresults ,
41
40
loading : false ,
42
41
...( archiveInfo . isOwner && { isOwner : true } ) ,
@@ -83,7 +82,32 @@ class App extends Component {
83
82
}
84
83
} ;
85
84
86
- refreshPosts = async archive => {
85
+ /*
86
+ * This method takes an archive and
87
+ * returns all of their posts.
88
+ * It does not setState.
89
+ */
90
+ getAllPosts = async archive => {
91
+ const posts = await archive . readdir ( '/posts' ) ;
92
+ if ( posts . length === 0 ) {
93
+ this . setState ( {
94
+ posts : [ ]
95
+ } ) ;
96
+ } else {
97
+ const promises = posts . map ( async post => {
98
+ const postResponse = await archive . readFile ( `/posts/${ post } ` ) ;
99
+ return JSON . parse ( postResponse ) ;
100
+ } ) ;
101
+ const results = await Promise . all ( promises ) ;
102
+ return results ;
103
+ }
104
+ } ;
105
+
106
+ /*
107
+ * Exact same as the above function, but
108
+ * also sets state.
109
+ */
110
+ getAllPostsSaved = async archive => {
87
111
const posts = await archive . readdir ( '/posts' ) ;
88
112
if ( posts . length === 0 ) {
89
113
this . setState ( {
@@ -120,7 +144,7 @@ class App extends Component {
120
144
deletePost = async postId => {
121
145
const archive = await new global . DatArchive ( urlEnv ( ) ) ;
122
146
await archive . unlink ( `/posts/${ postId } .json` ) ;
123
- this . refreshPosts ( archive ) ;
147
+ this . getAllPostsSaved ( archive ) ;
124
148
} ;
125
149
126
150
deletePostSingle = async postId => {
@@ -140,9 +164,12 @@ class App extends Component {
140
164
3a. return true or false message if valid dat URL
141
165
---*/
142
166
const followerData = {
143
- name : 'frogs ' ,
167
+ name : '' ,
144
168
url : followerFieldVal
145
169
} ;
170
+ if ( followerData . url === '' ) {
171
+ return null ;
172
+ }
146
173
// 4. write to following array in profile.json
147
174
this . setState (
148
175
{
@@ -154,18 +181,16 @@ class App extends Component {
154
181
}
155
182
} ,
156
183
( ) => this . changeUserData ( this . state . userData )
157
- // () => console.log('update', this.state.userData)
158
184
) ;
185
+ document . querySelector ( '#add-follower-input' ) . value = '' ;
159
186
} ;
160
187
161
188
updateUserData = e => {
162
189
e . preventDefault ( ) ;
163
- console . log ( 'userdata' , this . state . userData ) ;
164
190
this . changeUserData ( this . state . userData ) ;
165
191
} ;
166
192
167
193
userDataChange = ( e , str ) => {
168
- console . log ( 'frogs' ) ;
169
194
this . setState ( {
170
195
userData : {
171
196
...this . state . userData ,
@@ -206,7 +231,7 @@ class App extends Component {
206
231
: this . state . posts
207
232
) }
208
233
isOwner = { this . state . isOwner }
209
- getPosts = { this . refreshPosts }
234
+ getPosts = { this . getAllPostsSaved }
210
235
togglePostDisplayFn = { this . togglePostDisplay }
211
236
correctBrowser = { this . state . correctBrowser }
212
237
deletePost = { this . deletePost }
@@ -224,7 +249,7 @@ class App extends Component {
224
249
contentSelectionOpen = { this . state . contentSelectionOpen }
225
250
toggleContentSelection = { this . toggleContentSelection }
226
251
togglePostDisplayFn = { this . togglePostDisplay }
227
- getPosts = { this . refreshPosts }
252
+ getPosts = { this . getAllPostsSaved }
228
253
isOwner = { this . state . isOwner }
229
254
correctBrowser = { this . state . correctBrowser }
230
255
deletePost = { this . deletePostSingle }
0 commit comments