@@ -5,17 +5,14 @@ import type {StoryType} from './types'
55import LoadingView from '../components/loading'
66import { NoticeView } from '../components/notice'
77import type { TopLevelViewPropsType } from '../types'
8- import { tracker } from '../../analytics'
98import { reportNetworkProblem } from '../../lib/report-network-problem'
109import { NewsList } from './news-list'
11- import { fetchRssFeed , fetchWpJson } from './fetch-feed '
10+ import { API } from '../../globals '
1211
1312type Props = TopLevelViewPropsType & {
14- name : string ,
15- url : string ,
16- query ?: Object ,
17- mode : 'rss' | 'wp-json' ,
13+ source : string | { url : string , type : 'rss' | 'wp-json' } ,
1814 thumbnail : false | number ,
15+ title : string ,
1916}
2017
2118type State = {
@@ -40,29 +37,22 @@ export default class NewsContainer extends React.PureComponent<Props, State> {
4037
4138 fetchData = async ( ) => {
4239 try {
43- let entries : StoryType [ ] = [ ]
44-
45- if ( this . props . mode === 'rss' ) {
46- entries = await fetchRssFeed ( this . props . url , this . props . query )
47- } else if ( this . props . mode === 'wp-json' ) {
48- entries = await fetchWpJson ( this . props . url , this . props . query )
40+ let url
41+ if ( typeof this . props . source === 'string' ) {
42+ url = API ( `/news/named/${ this . props . source } ` )
43+ } else if ( this . props . source . type === 'rss' ) {
44+ url = API ( '/news/rss' , { url : this . props . source . url } )
45+ } else if ( this . props . source . type === 'wp-json' ) {
46+ url = API ( '/news/wpjson' , { url : this . props . source . url } )
4947 } else {
50- throw new Error ( `unknown mode ${ this . props . mode } ` )
48+ throw new Error ( 'invalid news source type!' )
5149 }
5250
51+ let entries : StoryType [ ] = await fetchJson ( url )
5352 this . setState ( ( ) => ( { entries} ) )
5453 } catch ( error ) {
55- if ( error . message . startsWith ( 'Unexpected token <' ) ) {
56- tracker . trackEvent ( 'news' , 'St. Olaf WPDefender strikes again' )
57- this . setState ( ( ) => ( {
58- error : new Error (
59- "Oops. Looks like we've triggered a St. Olaf website defense mechanism. Try again in 5 minutes." ,
60- ) ,
61- } ) )
62- } else {
63- reportNetworkProblem ( error )
64- this . setState ( ( ) => ( { error} ) )
65- }
54+ reportNetworkProblem ( error )
55+ this . setState ( ( ) => ( { error} ) )
6656 }
6757 }
6858
@@ -93,8 +83,7 @@ export default class NewsContainer extends React.PureComponent<Props, State> {
9383 < NewsList
9484 entries = { this . state . entries }
9585 loading = { this . state . refreshing }
96- mode = { this . props . mode }
97- name = { this . props . name }
86+ name = { this . props . title }
9887 navigation = { this . props . navigation }
9988 onRefresh = { this . refresh }
10089 thumbnail = { this . props . thumbnail }
0 commit comments