mirror of
https://github.com/gurnec/removeddit.git
synced 2026-03-11 08:54:27 +00:00
Disable subreddit support
This commit is contained in:
parent
57d753b42e
commit
043c80839c
7 changed files with 134 additions and 137 deletions
|
|
@ -1,11 +1,11 @@
|
|||
const baseURL = 'http://unddit.com/api'
|
||||
|
||||
export const getRemovedThreadIDs = (subreddit = '', page = 1) => {
|
||||
if (subreddit.toLowerCase() === 'all') {
|
||||
subreddit = ''
|
||||
}
|
||||
|
||||
return window.fetch(`${baseURL}/threads?subreddit=${subreddit}&page=${page - 1}`)
|
||||
.then(response => response.json())
|
||||
.catch(() => { throw new Error('Could not get removed threads') })
|
||||
}
|
||||
//const baseURL = 'http://unddit.com/api'
|
||||
//
|
||||
//export const getRemovedThreadIDs = (subreddit = '', page = 1) => {
|
||||
// if (subreddit.toLowerCase() === 'all') {
|
||||
// subreddit = ''
|
||||
// }
|
||||
//
|
||||
// return window.fetch(`${baseURL}/threads?subreddit=${subreddit}&page=${page - 1}`)
|
||||
// .then(response => response.json())
|
||||
// .catch(() => { throw new Error('Could not get removed threads') })
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { Provider } from 'unstated'
|
|||
|
||||
import Header from './pages/common/Header'
|
||||
import About from './pages/about'
|
||||
import Subreddit from './pages/subreddit'
|
||||
//import Subreddit from './pages/subreddit'
|
||||
import Thread from './pages/thread'
|
||||
import NotFound from './pages/404'
|
||||
|
||||
|
|
@ -16,15 +16,13 @@ ReactDOM.render(
|
|||
<Header />
|
||||
<div className='main'>
|
||||
<Switch>
|
||||
<Route exact path='/' component={Subreddit} />
|
||||
<Route exact path='/' component={About} />
|
||||
<Route path='/about' component={About} />
|
||||
<Route path='/r/:subreddit/comments/:threadID/:junk/:commentID' component={Thread} />
|
||||
<Route path='/r/:subreddit/comments/:threadID' component={Thread} />
|
||||
<Route path='/r/:subreddit' component={Subreddit} />
|
||||
<Redirect from='/user/:username/comments/:threadID/:junk/:commentID'
|
||||
to='/r/u_:username/comments/:threadID/:junk/:commentID' />
|
||||
<Redirect from='/user/:username/comments/:threadID' to='/r/u_:username/comments/:threadID' />
|
||||
<Redirect from='/user/:username' to='/r/u_:username' />
|
||||
<Route component={NotFound} />
|
||||
</Switch>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ const Header = props => (
|
|||
<Link to='/'>Unddit</Link>
|
||||
</h1>
|
||||
<nav>
|
||||
<Link to='/r/all'>/r/all</Link>
|
||||
<Link to='/about/'>about & FAQ</Link>
|
||||
<Link to='/'>about & FAQ</Link>
|
||||
</nav>
|
||||
</div>
|
||||
<div id='status'>
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ 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 <Link className='subreddit-link author' to={`/r/${props.subreddit}`}>/r/{props.subreddit}</Link>
|
||||
to /r/{props.subreddit}
|
||||
</div>
|
||||
{props.selftext &&
|
||||
<div className='thread-selftext user-text' dangerouslySetInnerHTML={{ __html: parse(props.selftext) }} />}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,25 @@
|
|||
import React from 'react'
|
||||
|
||||
export default (props) => {
|
||||
let pageination = <React.Fragment />
|
||||
|
||||
for (let i = props.start; i <= props.end; i++) {
|
||||
if (props.currentPage === i) {
|
||||
pageination += <span>{i}</span>
|
||||
} else {
|
||||
pageination += <a href={`${props.url + i}`}>{i}</a>
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div id='pagination'>
|
||||
Page:
|
||||
{props.start > 1 &&
|
||||
<React.Fragment>
|
||||
<a href={`${props.url + 1}`}>1</a>
|
||||
<span> ...</span>
|
||||
</React.Fragment>
|
||||
}
|
||||
{pageination}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
//import React from 'react'
|
||||
//
|
||||
//export default (props) => {
|
||||
// let pageination = <React.Fragment />
|
||||
//
|
||||
// for (let i = props.start; i <= props.end; i++) {
|
||||
// if (props.currentPage === i) {
|
||||
// pageination += <span>{i}</span>
|
||||
// } else {
|
||||
// pageination += <a href={`${props.url + i}`}>{i}</a>
|
||||
// }
|
||||
// }
|
||||
// return (
|
||||
// <div id='pagination'>
|
||||
// Page:
|
||||
// {props.start > 1 &&
|
||||
// <React.Fragment>
|
||||
// <a href={`${props.url + 1}`}>1</a>
|
||||
// <span> ...</span>
|
||||
// </React.Fragment>
|
||||
// }
|
||||
// {pageination}
|
||||
// </div>
|
||||
// )
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
import React from 'react'
|
||||
|
||||
export default (props) => {
|
||||
const isSelected = time => props.time === time
|
||||
|
||||
return (
|
||||
<div className='subreddit-info'>
|
||||
top post of <a href={`https://www.reddit.com/r/${props.subreddit}`}>/r/{props.subreddit}</a> from:
|
||||
<select>
|
||||
<option value='hour' selected={isSelected('hour')}>past hour</option>
|
||||
<option value='12hour' selected={isSelected('12hour')}>past 12 hours</option>
|
||||
<option value='day' selected={isSelected('day')}>past day</option>
|
||||
<option value='week' selected={isSelected('week')}>past week</option>
|
||||
<option value='month' selected={isSelected('month')}>past month</option>
|
||||
<option value='6month' selected={isSelected('6month')}>past 6 months</option>
|
||||
<option value='year' selected={isSelected('year')}>past year</option>
|
||||
<option value='all' selected={isSelected('all')}>all time</option>
|
||||
</select>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
//import React from 'react'
|
||||
//
|
||||
//export default (props) => {
|
||||
// const isSelected = time => props.time === time
|
||||
//
|
||||
// return (
|
||||
// <div className='subreddit-info'>
|
||||
// top post of <a href={`https://www.reddit.com/r/${props.subreddit}`}>/r/{props.subreddit}</a> from:
|
||||
// <select>
|
||||
// <option value='hour' selected={isSelected('hour')}>past hour</option>
|
||||
// <option value='12hour' selected={isSelected('12hour')}>past 12 hours</option>
|
||||
// <option value='day' selected={isSelected('day')}>past day</option>
|
||||
// <option value='week' selected={isSelected('week')}>past week</option>
|
||||
// <option value='month' selected={isSelected('month')}>past month</option>
|
||||
// <option value='6month' selected={isSelected('6month')}>past 6 months</option>
|
||||
// <option value='year' selected={isSelected('year')}>past year</option>
|
||||
// <option value='all' selected={isSelected('all')}>all time</option>
|
||||
// </select>
|
||||
// </div>
|
||||
// )
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -1,73 +1,73 @@
|
|||
import React from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { getRemovedThreadIDs } from '../../api/removeddit'
|
||||
import { getThreads } from '../../api/reddit'
|
||||
import Post from '../common/Post'
|
||||
import { connect } from '../../state'
|
||||
|
||||
class Subreddit extends React.Component {
|
||||
state = {
|
||||
threads: [],
|
||||
loading: true
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { subreddit = 'all' } = this.props.match.params
|
||||
this.getRemovedThreads(subreddit)
|
||||
}
|
||||
|
||||
// Check if the subreddit has changed in the url, and fetch threads accordingly
|
||||
componentDidUpdate(prevProps) {
|
||||
const { subreddit: newSubreddit = 'all' } = this.props.match.params
|
||||
const { subreddit = 'all' } = prevProps.match.params
|
||||
|
||||
if (subreddit !== newSubreddit) {
|
||||
this.getRemovedThreads(newSubreddit)
|
||||
}
|
||||
}
|
||||
|
||||
// Download thread IDs from removeddit API, then thread info from reddit API
|
||||
getRemovedThreads(subreddit) {
|
||||
document.title = `/r/${subreddit}`
|
||||
this.setState({ threads: [], loading: true })
|
||||
this.props.global.setLoading('Loading removed threads...')
|
||||
|
||||
getRemovedThreadIDs(subreddit)
|
||||
.then(threadIDs => getThreads(threadIDs))
|
||||
.then(threads => {
|
||||
threads.forEach(thread => {
|
||||
thread.removed = true
|
||||
thread.selftext = ''
|
||||
})
|
||||
this.setState({ threads, loading: false })
|
||||
this.props.global.setSuccess()
|
||||
})
|
||||
.catch(this.props.global.setError)
|
||||
}
|
||||
|
||||
render() {
|
||||
const { subreddit = 'all' } = this.props.match.params
|
||||
const noThreadsFound = this.state.threads.length === 0 && !this.state.loading
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<div className='subreddit-box'>
|
||||
<Link to={`/r/${subreddit}`} className='subreddit-title'>/r/{subreddit}</Link>
|
||||
<span className='space' />
|
||||
<a href={`https://www.reddit.com/r/${subreddit}`} className='subreddit-title-link'>reddit</a>
|
||||
<span className='space' />
|
||||
<a href={`https://reveddit.com/r/${subreddit}`} className='subreddit-title-link'>reveddit</a>
|
||||
</div>
|
||||
{
|
||||
noThreadsFound
|
||||
? <p>No removed threads found for /r/{subreddit}</p>
|
||||
: this.state.threads.map(thread => (
|
||||
<Post key={thread.id} {...thread} />
|
||||
))
|
||||
}
|
||||
</React.Fragment>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(Subreddit)
|
||||
//import React from 'react'
|
||||
//import { Link } from 'react-router-dom'
|
||||
//import { getRemovedThreadIDs } from '../../api/removeddit'
|
||||
//import { getThreads } from '../../api/reddit'
|
||||
//import Post from '../common/Post'
|
||||
//import { connect } from '../../state'
|
||||
//
|
||||
//class Subreddit extends React.Component {
|
||||
// state = {
|
||||
// threads: [],
|
||||
// loading: true
|
||||
// }
|
||||
//
|
||||
// componentDidMount() {
|
||||
// const { subreddit = 'all' } = this.props.match.params
|
||||
// this.getRemovedThreads(subreddit)
|
||||
// }
|
||||
//
|
||||
// // Check if the subreddit has changed in the url, and fetch threads accordingly
|
||||
// componentDidUpdate(prevProps) {
|
||||
// const { subreddit: newSubreddit = 'all' } = this.props.match.params
|
||||
// const { subreddit = 'all' } = prevProps.match.params
|
||||
//
|
||||
// if (subreddit !== newSubreddit) {
|
||||
// this.getRemovedThreads(newSubreddit)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Download thread IDs from removeddit API, then thread info from reddit API
|
||||
// getRemovedThreads(subreddit) {
|
||||
// document.title = `/r/${subreddit}`
|
||||
// this.setState({ threads: [], loading: true })
|
||||
// this.props.global.setLoading('Loading removed threads...')
|
||||
//
|
||||
// getRemovedThreadIDs(subreddit)
|
||||
// .then(threadIDs => getThreads(threadIDs))
|
||||
// .then(threads => {
|
||||
// threads.forEach(thread => {
|
||||
// thread.removed = true
|
||||
// thread.selftext = ''
|
||||
// })
|
||||
// this.setState({ threads, loading: false })
|
||||
// this.props.global.setSuccess()
|
||||
// })
|
||||
// .catch(this.props.global.setError)
|
||||
// }
|
||||
//
|
||||
// render() {
|
||||
// const { subreddit = 'all' } = this.props.match.params
|
||||
// const noThreadsFound = this.state.threads.length === 0 && !this.state.loading
|
||||
//
|
||||
// return (
|
||||
// <React.Fragment>
|
||||
// <div className='subreddit-box'>
|
||||
// <Link to={`/r/${subreddit}`} className='subreddit-title'>/r/{subreddit}</Link>
|
||||
// <span className='space' />
|
||||
// <a href={`https://www.reddit.com/r/${subreddit}`} className='subreddit-title-link'>reddit</a>
|
||||
// <span className='space' />
|
||||
// <a href={`https://reveddit.com/r/${subreddit}`} className='subreddit-title-link'>reveddit</a>
|
||||
// </div>
|
||||
// {
|
||||
// noThreadsFound
|
||||
// ? <p>No removed threads found for /r/{subreddit}</p>
|
||||
// : this.state.threads.map(thread => (
|
||||
// <Post key={thread.id} {...thread} />
|
||||
// ))
|
||||
// }
|
||||
// </React.Fragment>
|
||||
// )
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//export default connect(Subreddit)
|
||||
|
|
|
|||
Loading…
Reference in a new issue