Skip to content

Commit 091f2e6

Browse files
committed
remove fetch-feed and move news sources to ccc-server
1 parent 4272a3e commit 091f2e6

File tree

3 files changed

+25
-147
lines changed

3 files changed

+25
-147
lines changed

source/views/news/fetch-feed.js

Lines changed: 0 additions & 102 deletions
This file was deleted.

source/views/news/index.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ const NewsView = TabNavigator({
1212
StOlafNewsView: {
1313
screen: ({navigation}) => (
1414
<NewsContainer
15-
mode="wp-json"
16-
name="St. Olaf"
1715
navigation={navigation}
18-
query={{per_page: 10, _embed: true}}
16+
source="stolaf"
1917
thumbnail={newsImages.stolaf}
20-
url="https://wp.stolaf.edu/wp-json/wp/v2/posts"
18+
title="St. Olaf"
2119
/>
2220
),
2321
navigationOptions: {
@@ -29,12 +27,10 @@ const NewsView = TabNavigator({
2927
OlevilleNewsView: {
3028
screen: ({navigation}) => (
3129
<NewsContainer
32-
mode="wp-json"
33-
name="Oleville"
3430
navigation={navigation}
35-
query={{per_page: 10, _embed: true}}
31+
source="oleville"
3632
thumbnail={newsImages.oleville}
37-
url="https://oleville.com/wp-json/wp/v2/posts/"
33+
title="Oleville"
3834
/>
3935
),
4036
navigationOptions: {
@@ -46,12 +42,10 @@ const NewsView = TabNavigator({
4642
MessNewsView: {
4743
screen: ({navigation}) => (
4844
<NewsContainer
49-
mode="wp-json"
50-
name="The Mess"
5145
navigation={navigation}
52-
query={{per_page: 10, _embed: true}}
46+
source="mess"
5347
thumbnail={newsImages.mess}
54-
url="https://www.manitoumessenger.com/wp-json/wp/v2/posts/"
48+
title="The Mess"
5549
/>
5650
),
5751
navigationOptions: {
@@ -63,11 +57,10 @@ const NewsView = TabNavigator({
6357
PoliticOleNewsView: {
6458
screen: ({navigation}) => (
6559
<NewsContainer
66-
mode="rss"
67-
name="PoliticOle"
6860
navigation={navigation}
61+
source="politicole"
6962
thumbnail={newsImages.politicole}
70-
url="https://oleville.com/politicole/feed/"
63+
title="PoliticOle"
7164
/>
7265
),
7366
navigationOptions: {
@@ -79,12 +72,10 @@ const NewsView = TabNavigator({
7972
KstoNewsView: {
8073
screen: ({navigation}) => (
8174
<NewsContainer
82-
mode="wp-json"
83-
name="KSTO"
8475
navigation={navigation}
85-
query={{per_page: 10, _embed: true}}
76+
source="ksto"
8677
thumbnail={newsImages.ksto}
87-
url="https://pages.stolaf.edu/ksto/wp-json/wp/v2/posts/"
78+
title="KSTO"
8879
/>
8980
),
9081
navigationOptions: {

source/views/news/news-container.js

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@ import type {StoryType} from './types'
55
import LoadingView from '../components/loading'
66
import {NoticeView} from '../components/notice'
77
import type {TopLevelViewPropsType} from '../types'
8-
import {tracker} from '../../analytics'
98
import {reportNetworkProblem} from '../../lib/report-network-problem'
109
import {NewsList} from './news-list'
11-
import {fetchRssFeed, fetchWpJson} from './fetch-feed'
10+
import {API} from '../../globals'
1211

1312
type 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

2118
type 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

Comments
 (0)