@@ -150,43 +150,52 @@ class DiscoverScreen extends React.Component {
150150 view : VIEWS . TAG_DETAIL ,
151151 } ) ;
152152
153- this . _fetchTagCommunities ( tag ) ;
154- this . _fetchHotTopicsForTag ( tag ) ;
153+ this . _fetchTagDetail ( tag ) ;
155154 }
156155
157- _fetchHotTopicsForTag ( tag ) {
158- api
159- . fetchHotTopics ( tag , 1 )
160- . then ( json => {
161- if ( tag !== this . state . activeTag ) {
162- return ; // stale response
163- }
156+ async _fetchTagDetail ( tag ) {
157+ const [ communitiesResult , hotTopicsResult ] = await Promise . allSettled ( [
158+ api . fetchTagCommunities ( tag ) ,
159+ api . fetchHotTopics ( tag , 1 ) ,
160+ ] ) ;
164161
165- const topics = json . hot_topics || [ ] ;
166- this . setState ( {
167- hotTopics : topics ,
168- hotTopicsLoading : false ,
169- hotTopicsHasMore : Boolean ( json . more_topics_url ) ,
170- } ) ;
162+ if ( tag !== this . state . activeTag ) {
163+ return ; // stale response
164+ }
171165
172- if ( topics . length === 0 ) {
173- this . setState ( {
174- view : VIEWS . ALL_COMMUNITIES ,
175- previousView : VIEWS . SPLASH ,
176- communitiesFilter : tag ,
177- allCommunities : [ ] ,
178- allCommunitiesLoading : true ,
179- } ) ;
180- this . _fetchAllCommunities ( tag ) ;
181- }
182- } )
183- . catch ( e => {
184- console . log ( e ) ;
185- if ( tag !== this . state . activeTag ) {
186- return ;
187- }
188- this . setState ( { hotTopicsLoading : false } ) ;
166+ if ( communitiesResult . status === 'rejected' ) {
167+ console . log ( communitiesResult . reason ) ;
168+ }
169+ if ( hotTopicsResult . status === 'rejected' ) {
170+ console . log ( hotTopicsResult . reason ) ;
171+ }
172+
173+ const hotTopicsJson = hotTopicsResult . value ;
174+ const topics = hotTopicsJson ?. hot_topics || [ ] ;
175+ const loaded = {
176+ hotTopicsLoading : false ,
177+ tagCommunitiesLoading : false ,
178+ tagCommunities : communitiesResult . value ?. topics || [ ] ,
179+ } ;
180+
181+ if ( hotTopicsResult . status === 'fulfilled' && topics . length === 0 ) {
182+ this . setState ( {
183+ ...loaded ,
184+ view : VIEWS . ALL_COMMUNITIES ,
185+ previousView : VIEWS . SPLASH ,
186+ communitiesFilter : tag ,
187+ allCommunities : [ ] ,
188+ allCommunitiesLoading : true ,
189189 } ) ;
190+ this . _fetchAllCommunities ( tag ) ;
191+ return ;
192+ }
193+
194+ this . setState ( {
195+ ...loaded ,
196+ hotTopics : topics ,
197+ hotTopicsHasMore : Boolean ( hotTopicsJson ?. more_topics_url ) ,
198+ } ) ;
190199 }
191200
192201 fetchHotTopics ( tag , opts = { } ) {
@@ -221,29 +230,6 @@ class DiscoverScreen extends React.Component {
221230 } ) ;
222231 }
223232
224- _fetchTagCommunities ( tag ) {
225- api
226- . fetchTagCommunities ( tag )
227- . then ( json => {
228- if ( tag !== this . state . activeTag ) {
229- return ;
230- }
231-
232- if ( json . topics ) {
233- this . setState ( {
234- tagCommunities : json . topics ,
235- tagCommunitiesLoading : false ,
236- } ) ;
237- } else {
238- this . setState ( { tagCommunities : [ ] , tagCommunitiesLoading : false } ) ;
239- }
240- } )
241- . catch ( e => {
242- console . log ( e ) ;
243- this . setState ( { tagCommunitiesLoading : false } ) ;
244- } ) ;
245- }
246-
247233 onPressCommunity ( community ) {
248234 this . setState ( {
249235 activeCommunity : community ,
0 commit comments