diff --git a/.gitignore b/.gitignore index 65340cc..92dd8c7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ node_modules/ # Generated JS/CSS files -static/main.* +dist/main.* # Log files *.log \ No newline at end of file diff --git a/static/404.html b/dist/404.html similarity index 100% rename from static/404.html rename to dist/404.html diff --git a/static/images/error.png b/dist/images/error.png similarity index 100% rename from static/images/error.png rename to dist/images/error.png diff --git a/static/images/favicon.ico b/dist/images/favicon.ico similarity index 100% rename from static/images/favicon.ico rename to dist/images/favicon.ico diff --git a/static/images/loading.gif b/dist/images/loading.gif similarity index 100% rename from static/images/loading.gif rename to dist/images/loading.gif diff --git a/static/images/success.png b/dist/images/success.png similarity index 100% rename from static/images/success.png rename to dist/images/success.png diff --git a/static/index.html b/dist/index.html similarity index 100% rename from static/index.html rename to dist/index.html diff --git a/package.json b/package.json index e16c8ad..a1b4c2d 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "start": "webpack-dev-server --mode development", "build-dev": "webpack --mode development", "build-prod": "webpack --mode production", - "build-sass": "node-sass --style compressed src/sass/index.sass static/main.css" + "build-sass": "node-sass --style compressed src/sass/index.sass dist/main.css" }, "dependencies": { "babel-polyfill": "^6.26.0", diff --git a/src/js/App.js b/src/App.js similarity index 98% rename from src/js/App.js rename to src/App.js index 9a83f74..03c8f1e 100644 --- a/src/js/App.js +++ b/src/App.js @@ -2,7 +2,7 @@ import React from 'react' import { BrowserRouter, Switch, - Route, + Route } from 'react-router-dom' import Header from 'components/Header' @@ -19,10 +19,8 @@ export default () => ( - ) - diff --git a/src/js/api/pushshift/index.js b/src/api/pushshift/index.js similarity index 87% rename from src/js/api/pushshift/index.js rename to src/api/pushshift/index.js index 6138606..38a6461 100644 --- a/src/js/api/pushshift/index.js +++ b/src/api/pushshift/index.js @@ -8,13 +8,13 @@ export const getPost = threadID => { const elasticQuery = { query: { term: { - id: toBase10(threadID), - }, - }, + id: toBase10(threadID) + } + } } return ( - fetch(postURL + JSON.stringify(elasticQuery)) + window.fetch(postURL + JSON.stringify(elasticQuery)) .then(json) .then(jsonData => jsonData.hits.hits[0]._source) .then(post => { @@ -41,17 +41,17 @@ export const getComments = threadID => { const elasticQuery = { query: { match: { - link_id: toBase10(threadID), - }, + link_id: toBase10(threadID) + } }, size: 10000, _source: [ - 'author', 'body', 'created_utc', 'parent_id', 'score', 'subreddit', 'link_id', - ], + 'author', 'body', 'created_utc', 'parent_id', 'score', 'subreddit', 'link_id' + ] } return ( - fetch(commentURL + JSON.stringify(elasticQuery)) + window.fetch(commentURL + JSON.stringify(elasticQuery)) .then(json) .then(jsonData => jsonData.hits.hits) .then(comments => comments.map(comment => { diff --git a/src/js/api/reddit/auth.js b/src/api/reddit/auth.js similarity index 75% rename from src/js/api/reddit/auth.js rename to src/api/reddit/auth.js index ab825c2..3feedb4 100644 --- a/src/js/api/reddit/auth.js +++ b/src/api/reddit/auth.js @@ -5,7 +5,7 @@ export const getAuth = () => ( getToken() .then(token => ({ headers: { - Authorization: `bearer ${token}`, - }, + Authorization: `bearer ${token}` + } })) ) diff --git a/src/js/api/reddit/clientID.js b/src/api/reddit/clientID.js similarity index 100% rename from src/js/api/reddit/clientID.js rename to src/api/reddit/clientID.js diff --git a/src/js/api/reddit/comment.js b/src/api/reddit/comment.js similarity index 81% rename from src/js/api/reddit/comment.js rename to src/api/reddit/comment.js index f1e4dbc..6cc163a 100644 --- a/src/js/api/reddit/comment.js +++ b/src/api/reddit/comment.js @@ -9,7 +9,7 @@ export const getComments = commentIDs => ( ) export const fetchComments = (commentIDs, auth) => ( - fetch(`https://oauth.reddit.com/api/info?id=${commentIDs.map(id => `t1_${id}`).join()}`, auth) + window.fetch(`https://oauth.reddit.com/api/info?id=${commentIDs.map(id => `t1_${id}`).join()}`, auth) .then(json) .then(results => results.data.children) .then(commentsData => commentsData.map(commentData => commentData.data)) diff --git a/src/js/api/reddit/index.js b/src/api/reddit/index.js similarity index 100% rename from src/js/api/reddit/index.js rename to src/api/reddit/index.js diff --git a/src/js/api/reddit/thread.js b/src/api/reddit/thread.js similarity index 90% rename from src/js/api/reddit/thread.js rename to src/api/reddit/thread.js index 45a057c..64f4a0e 100644 --- a/src/js/api/reddit/thread.js +++ b/src/api/reddit/thread.js @@ -22,7 +22,7 @@ export const getThread = (subreddit, threadID, commentID = '') => { // Fetch thread from reddit return ( getAuth() - .then(auth => fetch(url, auth)) + .then(auth => window.fetch(url, auth)) .then(json) .then(thread => { // Create cache object for thread if it doesn't exists @@ -39,13 +39,12 @@ export const getThread = (subreddit, threadID, commentID = '') => { ) } - export const getThreads = threadIDs => { const threadString = threadIDs.map(id => `t3_${id}`).join() return ( getAuth() - .then(auth => fetch(`https://oauth.reddit.com/api/info?id=${threadString}`, auth)) + .then(auth => window.fetch(`https://oauth.reddit.com/api/info?id=${threadString}`, auth)) .then(json) .then(response => { const threads = response.data.children diff --git a/src/js/api/reddit/token.js b/src/api/reddit/token.js similarity index 81% rename from src/js/api/reddit/token.js rename to src/api/reddit/token.js index 86385bd..9237f5f 100644 --- a/src/js/api/reddit/token.js +++ b/src/api/reddit/token.js @@ -7,11 +7,11 @@ let token = null // Headers for getting reddit api token const tokenInit = { headers: { - Authorization: `Basic ${btoa(`${clientID}:`)}`, - 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', + Authorization: `Basic ${window.btoa(`${clientID}:`)}`, + 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' }, method: 'POST', - body: `grant_type=${encodeURIComponent('https://oauth.reddit.com/grants/installed_client')}&device_id=DO_NOT_TRACK_THIS_DEVICE`, + body: `grant_type=${encodeURIComponent('https://oauth.reddit.com/grants/installed_client')}&device_id=DO_NOT_TRACK_THIS_DEVICE` } export const getToken = () => { @@ -20,7 +20,7 @@ export const getToken = () => { } return ( - fetch('https://www.reddit.com/api/v1/access_token', tokenInit) + window.fetch('https://www.reddit.com/api/v1/access_token', tokenInit) .then(json) .then(response => { token = response.access_token diff --git a/src/js/api/removeddit/index.js b/src/api/removeddit/index.js similarity index 67% rename from src/js/api/removeddit/index.js rename to src/api/removeddit/index.js index 94d5ffc..583c3de 100644 --- a/src/js/api/removeddit/index.js +++ b/src/api/removeddit/index.js @@ -3,6 +3,6 @@ import { json } from 'utils' const baseURL = 'https://removeddit.com/api' export const getRemovedThreadIDs = (subreddit = '', page = 1) => ( - fetch(`${baseURL}/threads?subreddit=${subreddit}&page=${page - 1}`) + window.fetch(`${baseURL}/threads?subreddit=${subreddit}&page=${page - 1}`) .then(json) ) diff --git a/src/js/components/Comment.js b/src/components/Comment.js similarity index 100% rename from src/js/components/Comment.js rename to src/components/Comment.js diff --git a/src/js/components/CommentInfo.js b/src/components/CommentInfo.js similarity index 100% rename from src/js/components/CommentInfo.js rename to src/components/CommentInfo.js diff --git a/src/js/components/CommentSection.js b/src/components/CommentSection.js similarity index 95% rename from src/js/components/CommentSection.js rename to src/components/CommentSection.js index 6531934..5886cc5 100644 --- a/src/js/components/CommentSection.js +++ b/src/components/CommentSection.js @@ -5,11 +5,11 @@ import SortBy from 'components/SortBy' import { connect } from 'react-redux' import { SORT_TOP, SORT_BOTTOM, SORT_NEW, SORT_OLD, - SHOW_ALL, SHOW_REMOVED_DELETED, SHOW_REMOVED, SHOW_DELETED, + SHOW_ALL, SHOW_REMOVED_DELETED, SHOW_REMOVED, SHOW_DELETED } from 'state' import { topSort, bottomSort, newSort, oldSort, - showRemovedAndDeleted, showRemoved, showDeleted, + showRemovedAndDeleted, showRemoved, showDeleted } from 'utils' const arrayToLookup = (commentList, removed, deleted) => { @@ -134,8 +134,7 @@ const commentSection = (props) => { const mapStateToProps = state => ({ sort: state.commentSection.sort, - show: state.commentSection.show, + show: state.commentSection.show }) - export default connect(mapStateToProps)(commentSection) diff --git a/src/js/components/Header.js b/src/components/Header.js similarity index 100% rename from src/js/components/Header.js rename to src/components/Header.js diff --git a/src/js/components/Post.js b/src/components/Post.js similarity index 100% rename from src/js/components/Post.js rename to src/components/Post.js diff --git a/src/js/components/SortBy.js b/src/components/SortBy.js similarity index 86% rename from src/js/components/SortBy.js rename to src/components/SortBy.js index 026d5b5..6c859c9 100644 --- a/src/js/components/SortBy.js +++ b/src/components/SortBy.js @@ -3,11 +3,10 @@ import { setCommentSort, setCommentShow, SORT_TOP, SORT_BOTTOM, SORT_NEW, SORT_OLD, - SHOW_ALL, SHOW_REMOVED_DELETED, SHOW_REMOVED, SHOW_DELETED, + SHOW_ALL, SHOW_REMOVED_DELETED, SHOW_REMOVED, SHOW_DELETED } from 'state' import { connect } from 'react-redux' - const sortBy = props => (
sorted by: @@ -32,16 +31,15 @@ const sortBy = props => ( const mapStateToProps = state => ({ sort: state.commentSection.sort, - show: state.commentSection.show, + show: state.commentSection.show }) const mapDispatchToProps = dispatch => ({ setSort: sortString => dispatch(setCommentSort(sortString)), - setShow: showString => dispatch(setCommentShow(showString)), + setShow: showString => dispatch(setCommentShow(showString)) }) export default connect( mapStateToProps, - mapDispatchToProps, + mapDispatchToProps )(sortBy) - diff --git a/src/js/components/SubredditPagination.js b/src/components/SubredditPagination.js similarity index 98% rename from src/js/components/SubredditPagination.js rename to src/components/SubredditPagination.js index 22ede00..624a45f 100644 --- a/src/js/components/SubredditPagination.js +++ b/src/components/SubredditPagination.js @@ -18,7 +18,7 @@ export default (props) => { 1 ... - } + } {pageination}
) diff --git a/src/js/components/SubredditSort.js b/src/components/SubredditSort.js similarity index 100% rename from src/js/components/SubredditSort.js rename to src/components/SubredditSort.js diff --git a/src/js/components/ThreadInfo.js b/src/components/ThreadInfo.js similarity index 100% rename from src/js/components/ThreadInfo.js rename to src/components/ThreadInfo.js diff --git a/src/js/containers/StatusBox.js b/src/containers/StatusBox.js similarity index 93% rename from src/js/containers/StatusBox.js rename to src/containers/StatusBox.js index 98f4460..e1df31e 100644 --- a/src/js/containers/StatusBox.js +++ b/src/containers/StatusBox.js @@ -12,7 +12,7 @@ const StatusBox = props => ( const mapStateToProps = state => ({ text: state.status.text, - image: state.status.image, + image: state.status.image }) export default connect(mapStateToProps)(StatusBox) diff --git a/src/js/index.js b/src/index.js similarity index 100% rename from src/js/index.js rename to src/index.js diff --git a/src/js/pages/About.js b/src/pages/About.js similarity index 100% rename from src/js/pages/About.js rename to src/pages/About.js diff --git a/src/js/pages/Search.js b/src/pages/Search.js similarity index 96% rename from src/js/pages/Search.js rename to src/pages/Search.js index 0f6ef4a..86ead70 100644 --- a/src/js/pages/Search.js +++ b/src/pages/Search.js @@ -1,7 +1,7 @@ // var radioInput = function(name, displayNames, values) { // var inputs = ""; - + // for(var i = 0, len = displayNames.length; i < len; i++){ // inputs += ''; // inputs += ''; +// return ''; // }; // var label = function(name, display) { @@ -37,7 +37,7 @@ // var select = function(name, display, values){ // var html = ''; // html += ''; // searchBox.innerHTML = html; - -// mainDiv.appendChild(searchBox); \ No newline at end of file + +// mainDiv.appendChild(searchBox); diff --git a/src/js/pages/Subreddit.js b/src/pages/Subreddit.js similarity index 86% rename from src/js/pages/Subreddit.js rename to src/pages/Subreddit.js index 278184b..b41a8c2 100644 --- a/src/js/pages/Subreddit.js +++ b/src/pages/Subreddit.js @@ -12,21 +12,20 @@ const getSubredditForAPI = props => { return subreddit.toLowerCase() } - export default class Subreddit extends React.Component { - constructor(props) { + constructor (props) { super(props) this.state = { threads: [], - subreddit: '', + subreddit: '' } } - componentDidMount() { + componentDidMount () { this.updateThreads(this.props) } - componentWillReceiveProps(nextProps) { + componentWillReceiveProps (nextProps) { const newSubreddit = getSubredditForAPI(nextProps) if (this.state.subreddit !== newSubreddit) { @@ -34,7 +33,7 @@ export default class Subreddit extends React.Component { } } - updateThreads(props) { + updateThreads (props) { const subreddit = getSubredditForAPI(props) getRemovedThreadIDs(subreddit) .then(threadIDs => getThreads(threadIDs)) @@ -47,7 +46,7 @@ export default class Subreddit extends React.Component { }) } - render() { + render () { const { subreddit = 'all' } = this.props.match.params const subredditLink = `/r/${subreddit}` @@ -61,9 +60,9 @@ export default class Subreddit extends React.Component { ceddit { - this.state.threads.map(thread => ( - - )) + this.state.threads.map(thread => ( + + )) } ) diff --git a/src/js/pages/Thread.js b/src/pages/Thread.js similarity index 92% rename from src/js/pages/Thread.js rename to src/pages/Thread.js index 357022a..43288cf 100644 --- a/src/js/pages/Thread.js +++ b/src/pages/Thread.js @@ -3,16 +3,16 @@ import Post from 'components/Post' import CommentSection from 'components/CommentSection' import { getPost, - getComments as getRedditComments, + getComments as getRedditComments } from 'api/reddit' import { getPost as getRemovedPost, - getComments as getPushshiftComments, + getComments as getPushshiftComments } from 'api/pushshift' import { isDeleted, isRemoved } from 'utils' export default class Thread extends React.Component { - constructor(props) { + constructor (props) { super(props) this.state = { @@ -20,11 +20,11 @@ export default class Thread extends React.Component { pushshiftComments: [], removed: [], deleted: [], - loadingComments: true, + loadingComments: true } } - componentDidMount() { + componentDidMount () { const { subreddit, threadID } = this.props.match.params Promise.all([ @@ -42,7 +42,7 @@ export default class Thread extends React.Component { } }), // Get comment ids from pushshift - getPushshiftComments(threadID), + getPushshiftComments(threadID) ]) .then(results => { const pushshiftComments = results[1] @@ -90,12 +90,12 @@ export default class Thread extends React.Component { this.setState({ removed, deleted, - loadingComments: false, + loadingComments: false }) }) } - render() { + render () { let root = this.state.post.id if (this.props.match.params.commentID !== undefined) { diff --git a/src/js/pages/index.js b/src/pages/index.js similarity index 100% rename from src/js/pages/index.js rename to src/pages/index.js diff --git a/src/js/state/commentSection.js b/src/state/commentSection.js similarity index 91% rename from src/js/state/commentSection.js rename to src/state/commentSection.js index 6a9f2fa..756f8f0 100644 --- a/src/js/state/commentSection.js +++ b/src/state/commentSection.js @@ -26,7 +26,7 @@ const filterKey = 'commentFilter' // Init state const initialStatusState = { sort: get(sortKey, SORT_TOP), - show: get(filterKey, SHOW_REMOVED_DELETED), + show: get(filterKey, SHOW_REMOVED_DELETED) } export const commentSectionReducer = (state = initialStatusState, action) => { @@ -35,13 +35,13 @@ export const commentSectionReducer = (state = initialStatusState, action) => { put(sortKey, action.payload) return { ...state, - sort: action.payload, + sort: action.payload } case COMMENT_SHOW: put(filterKey, action.payload) return { ...state, - show: action.payload, + show: action.payload } default: return state diff --git a/src/js/state/index.js b/src/state/index.js similarity index 91% rename from src/js/state/index.js rename to src/state/index.js index 0d5fd58..639760c 100644 --- a/src/js/state/index.js +++ b/src/state/index.js @@ -8,7 +8,7 @@ export * from './commentSection' const reducer = combineReducers({ status: statusReducer, - commentSection: commentSectionReducer, + commentSection: commentSectionReducer }) export const store = createStore(reducer, applyMiddleware(logger)) diff --git a/src/js/state/status.js b/src/state/status.js similarity index 88% rename from src/js/state/status.js rename to src/state/status.js index 3408c62..35290df 100644 --- a/src/js/state/status.js +++ b/src/state/status.js @@ -1,7 +1,7 @@ const images = { loading: '/images/loading.gif', error: '/images/error.png', - success: '/images/done.png', + success: '/images/done.png' } // Action types @@ -17,7 +17,7 @@ export const setStatusError = (payload = '') => ({ type: STATUS_SET_ERROR, paylo // Init state const initialStatusState = { text: null, - image: null, + image: null } export const statusReducer = (state = initialStatusState, action) => { @@ -26,19 +26,19 @@ export const statusReducer = (state = initialStatusState, action) => { return { ...state, text: action.payload, - image: images.success, + image: images.success } case STATUS_SET_LOADING: return { ...state, text: action.payload, - image: images.loading, + image: images.loading } case STATUS_SET_ERROR: return { ...state, text: action.payload, - image: images.error, + image: images.error } default: return state diff --git a/src/js/utils/index.js b/src/utils/index.js similarity index 93% rename from src/js/utils/index.js rename to src/utils/index.js index 192c5fc..27ac69b 100644 --- a/src/js/utils/index.js +++ b/src/utils/index.js @@ -31,7 +31,7 @@ export const json = x => x.json() export const fetchMultiple = (url, arr, header, size = 100) => { const subArrays = chunk(arr, size) - return Promise.all(subArrays.map(subArr => fetch(url + subArr.join(), header))) + return Promise.all(subArrays.map(subArr => window.fetch(url + subArr.join(), header))) } export const jsonMultiple = responses => Promise.all(responses.map(json)) @@ -86,11 +86,10 @@ export const prettyScore = score => { // Retrieve, store and delete stuff in the local storage export const get = (key, defaultValue) => ( - localStorage.getItem(key) !== null ? JSON.parse(localStorage.getItem(key)) : defaultValue + window.localStorage.getItem(key) !== null ? JSON.parse(window.localStorage.getItem(key)) : defaultValue ) -export const put = (key, value) => localStorage.setItem(key, JSON.stringify(value)) - +export const put = (key, value) => window.localStorage.setItem(key, JSON.stringify(value)) // Sorting for comments export const topSort = (commentA, commentB) => { diff --git a/webpack.config.js b/webpack.config.js index e3e9108..8cc3233 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -4,34 +4,25 @@ module.exports = { entry: [ 'babel-polyfill', 'whatwg-fetch', - './src/js/index.js', + './src/index.js' ], - output: { - path: path.resolve(__dirname, 'static'), - publicPath: '/', - }, devServer: { - contentBase: path.resolve(__dirname, 'static'), - historyApiFallback: true, + contentBase: path.resolve(__dirname, 'dist'), + historyApiFallback: true }, devtool: 'cheap-module-eval-source-map', resolve: { modules: [ - path.resolve('./src/js'), - path.resolve('./node_modules'), - ], + path.resolve(__dirname, 'src'), + path.resolve(__dirname, 'node_modules') + ] }, module: { rules: [ { test: /\.js$/, exclude: /node_modules/, - use: { - loader: 'babel-loader', - options: { - cacheDirectory: true, - }, - }, + use: 'babel-loader' } ] }