Skip to content

Commit 524af56

Browse files
committed
Merge branch 'frogpond-news' into frogpond-data
* frogpond-news: remove fetch-feed and move news sources to ccc-server add support for disabling thumbnails on the news views
2 parents 95c23d5 + 091f2e6 commit 524af56

File tree

5 files changed

+42
-155
lines changed

5 files changed

+42
-155
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: 16 additions & 27 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',
18-
thumbnail: number,
13+
source: string | {url: string, type: 'rss' | 'wp-json'},
14+
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}

source/views/news/news-list.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ type Props = TopLevelViewPropsType & {
2020
onRefresh: () => any,
2121
entries: StoryType[],
2222
loading: boolean,
23-
thumbnail: number,
23+
thumbnail: false | number,
2424
}
2525

2626
export class NewsList extends React.PureComponent<Props> {
2727
onPressNews = (url: string) => {
2828
return openUrl(url)
2929
}
3030

31-
renderSeparator = () => <ListSeparator spacing={{left: 101}} />
31+
renderSeparator = () => (
32+
<ListSeparator
33+
spacing={{left: this.props.thumbnail === false ? undefined : 101}}
34+
/>
35+
)
3236

3337
renderItem = ({item}: {item: StoryType}) => (
3438
<NewsRow

source/views/news/news-row.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {StoryType} from './types'
99
type Props = {
1010
onPress: string => any,
1111
story: StoryType,
12-
thumbnail: number,
12+
thumbnail: false | number,
1313
}
1414

1515
export class NewsRow extends React.PureComponent<Props> {
@@ -23,14 +23,19 @@ export class NewsRow extends React.PureComponent<Props> {
2323

2424
render() {
2525
const {story} = this.props
26-
const thumb = story.featuredImage
27-
? {uri: story.featuredImage}
28-
: this.props.thumbnail
26+
const thumb =
27+
this.props.thumbnail !== false
28+
? story.featuredImage
29+
? {uri: story.featuredImage}
30+
: this.props.thumbnail
31+
: null
2932

3033
return (
3134
<ListRow arrowPosition="top" onPress={this._onPress}>
3235
<Row alignItems="center">
33-
<Image source={thumb} style={styles.image} />
36+
{thumb !== null ? (
37+
<Image source={thumb} style={styles.image} />
38+
) : null}
3439
<Column flex={1}>
3540
<Title lines={2}>{story.title}</Title>
3641
<Detail lines={3}>{story.excerpt}</Detail>

0 commit comments

Comments
 (0)