@@ -3,10 +3,9 @@ import React from 'react'
33import { RefreshControl } from 'react-native'
44import { ScrollView } from 'glamorous-native'
55import { Markdown } from '../components/markdown'
6+ import { reportNetworkProblem } from '../../lib/report-network-problem'
67import LoadingView from '../components/loading'
7- import { text } from '../../../docs/faqs.json'
8- import { tracker } from '../../analytics'
9- import bugsnag from '../../bugsnag'
8+ import * as defaultData from '../../../docs/faqs.json'
109import delay from 'delay'
1110
1211const faqsUrl = 'https://stodevx.github.io/AAO-React-Native/faqs.json'
@@ -17,30 +16,28 @@ export class FaqView extends React.PureComponent {
1716 }
1817
1918 state = {
20- text : text ,
19+ text : defaultData . text ,
20+ loading : true ,
2121 refreshing : false ,
2222 }
2323
2424 componentWillMount ( ) {
25- this . fetchData ( )
25+ this . fetchData ( ) . then ( ( ) => {
26+ this . setState ( ( ) => ( { loading : false } ) )
27+ } )
2628 }
2729
2830 fetchData = async ( ) => {
29- let fetched = text
30- try {
31- let blob : { text : string } = await fetchJson ( faqsUrl )
32- fetched = blob . text
33- } catch ( err ) {
34- tracker . trackException ( err . message )
35- bugsnag . notify ( err )
36- console . warn ( err . message )
37- }
31+ let { text} = await fetchJson ( faqsUrl ) . catch ( err => {
32+ reportNetworkProblem ( err )
33+ return { text : 'There was a problem loading the FAQs' }
34+ } )
3835
3936 if ( process . env . NODE_ENV === 'development' ) {
40- fetched = text
37+ text = defaultData . text
4138 }
4239
43- this . setState ( { text : fetched } )
40+ this . setState ( ( ) => ( { text} ) )
4441 }
4542
4643 refresh = async ( ) => {
@@ -58,7 +55,7 @@ export class FaqView extends React.PureComponent {
5855 }
5956
6057 render ( ) {
61- if ( ! this . state . text ) {
58+ if ( this . state . loading ) {
6259 return < LoadingView />
6360 }
6461
@@ -71,7 +68,7 @@ export class FaqView extends React.PureComponent {
7168
7269 return (
7370 < ScrollView refreshControl = { refreshControl } paddingHorizontal = { 15 } >
74- < Markdown source = { text } />
71+ < Markdown source = { this . state . text } />
7572 </ ScrollView >
7673 )
7774 }
0 commit comments