mirror of
https://github.com/gurnec/removeddit.git
synced 2026-03-11 08:54:27 +00:00
Fixed some routing problems with the links for subreddits
This commit is contained in:
parent
dce106a6c8
commit
792939860c
2 changed files with 23 additions and 12 deletions
|
|
@ -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) => {
|
|||
<div className='thread-info'>
|
||||
submitted <span className='thread-time'>{prettyDate(props.created_utc)}</span> by
|
||||
<a className='thread-author author' href={userLink}>{props.author}</a>
|
||||
to <a className='subreddit-link author' href={`/r/${props.subreddit}`}>/r/{props.subreddit}</a>
|
||||
to <Link className='subreddit-link author' to={`/r/${props.subreddit}`}>/r/{props.subreddit}</Link>
|
||||
</div>
|
||||
{props.selftext &&
|
||||
<div className='thread-selftext user-text' dangerouslySetInnerHTML={{ __html: parse(props.selftext) }} />}
|
||||
<div className='total-comments'>
|
||||
<a className='grey-link' href={props.permalink}>
|
||||
<Link className='grey-link' to={props.permalink}>
|
||||
<b>{props.num_comments} comments</b>
|
||||
</a>
|
||||
</Link>
|
||||
<a className='grey-link' href={`https://www.reddit.com${props.permalink}`}>
|
||||
<b>reddit</b>
|
||||
</a>
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<React.Fragment>
|
||||
<div className='subreddit-box'>
|
||||
<a href={subredditLink} className='subreddit-title'>{subredditLink}</a>
|
||||
<Link to={subredditLink} className='subreddit-title'>{subredditLink}</Link>
|
||||
<span className='space' />
|
||||
<a href={`https://www.reddit.com${subredditLink}`} className='subreddit-title-link'>reddit</a>
|
||||
<span className='space' />
|
||||
|
|
|
|||
Loading…
Reference in a new issue