diff --git a/src/js/components/Post.js b/src/js/components/Post.js
index 06346fa..63aca7f 100644
--- a/src/js/components/Post.js
+++ b/src/js/components/Post.js
@@ -1,4 +1,5 @@
import React from 'react'
+import { Link } from 'react-router-dom'
import { prettyScore, prettyDate, parse, redditThumbnails, isDeleted } from 'utils'
export default (props) => {
@@ -41,14 +42,14 @@ export default (props) => {
{props.selftext &&
}
-
+
{props.num_comments} comments
-
+
reddit
diff --git a/src/js/pages/Subreddit.js b/src/js/pages/Subreddit.js
index a2edf89..278184b 100644
--- a/src/js/pages/Subreddit.js
+++ b/src/js/pages/Subreddit.js
@@ -1,13 +1,12 @@
import React from 'react'
+import { Link } from 'react-router-dom'
import { getRemovedThreadIDs } from 'api/removeddit'
import { getThreads } from 'api/reddit'
import Post from 'components/Post'
const getSubredditForAPI = props => {
- const { subreddit } = props.match.params
- if (subreddit === undefined) {
- return ''
- } else if (subreddit.toLowerCase() === 'all') {
+ const { subreddit = 'all' } = props.match.params
+ if (subreddit.toLowerCase() === 'all') {
return ''
}
return subreddit.toLowerCase()
@@ -20,11 +19,23 @@ export default class Subreddit extends React.Component {
this.state = {
threads: [],
+ subreddit: '',
+ }
+ }
+ componentDidMount() {
+ this.updateThreads(this.props)
+ }
+
+ componentWillReceiveProps(nextProps) {
+ const newSubreddit = getSubredditForAPI(nextProps)
+
+ if (this.state.subreddit !== newSubreddit) {
+ this.updateThreads(nextProps)
}
}
- componentDidMount() {
- const subreddit = getSubredditForAPI(this.props)
+ updateThreads(props) {
+ const subreddit = getSubredditForAPI(props)
getRemovedThreadIDs(subreddit)
.then(threadIDs => getThreads(threadIDs))
.then(threads => {
@@ -32,19 +43,18 @@ export default class Subreddit extends React.Component {
thread.removed = true
thread.selftext = ''
})
- this.setState({ threads })
+ this.setState({ threads, subreddit })
})
}
render() {
const { subreddit = 'all' } = this.props.match.params
- console.log(subreddit)
const subredditLink = `/r/${subreddit}`
return (