diff --git a/src/js/components/CommentSection.js b/src/js/components/CommentSection.js
index ed0fa7c..f06ece7 100644
--- a/src/js/components/CommentSection.js
+++ b/src/js/components/CommentSection.js
@@ -1,7 +1,11 @@
import React from 'react'
-export default (props) => (
-
- {props.children}
-
-)
+export default (props) => {
+ const { children } = props
+ return (
+
+
{props.root}
+ {children}
+
+ )
+}
diff --git a/src/js/components/StatusBox.js b/src/js/components/StatusBox.js
index 90cd20c..98f4460 100644
--- a/src/js/components/StatusBox.js
+++ b/src/js/components/StatusBox.js
@@ -1,18 +1,14 @@
import React from 'react'
import { connect } from 'react-redux'
-class StatusBox extends React.Component {
- render() {
- return (
-
- {this.props.text &&
-
{this.props.text}
}
- {this.props.image &&
-

}
-
- )
- }
-}
+const StatusBox = props => (
+
+ {props.text &&
+
{props.text}
}
+ {props.image &&
+

}
+
+)
const mapStateToProps = state => ({
text: state.status.text,
diff --git a/src/js/components/ThreadHead.js b/src/js/components/ThreadHead.js
index b55c314..06346fa 100644
--- a/src/js/components/ThreadHead.js
+++ b/src/js/components/ThreadHead.js
@@ -1,5 +1,5 @@
import React from 'react'
-import { prettyScore, prettyDate, parse, redditThumbnails } from 'utils'
+import { prettyScore, prettyDate, parse, redditThumbnails, isDeleted } from 'utils'
export default (props) => {
if (!props.title) {
@@ -7,7 +7,7 @@ export default (props) => {
}
const url = props.url.replace('https://www.reddit.com', '')
- const userLink = props.author !== '[deleted]' ? `https://www.reddit.com/user/${props.author}` : undefined
+ const userLink = isDeleted(props.author) ? undefined : `https://www.reddit.com/user/${props.author}`
let thumbnail
const thumbnailWidth = props.thumbnail_width ? props.thumbnail_width * 0.5 : 70
diff --git a/src/js/index.js b/src/js/index.js
index f023132..7a71d0f 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -3,6 +3,7 @@ import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { store } from 'state'
import App from 'App'
+// import { setStatusLoading } from 'state'
import '../sass/main.sass'
@@ -13,8 +14,4 @@ ReactDOM.render(
document.getElementById('app')
)
-// import {setStatusLoading} from 'state'
// store.dispatch(setStatusLoading('hi'))
-
-// import { getThread } from 'reddit'
-// getThread('videos', '7q4vxi')
diff --git a/src/js/pages/Thread.js b/src/js/pages/Thread.js
index 80c59f4..f389911 100644
--- a/src/js/pages/Thread.js
+++ b/src/js/pages/Thread.js
@@ -1,7 +1,14 @@
import React from 'react'
import ThreadHead from 'components/ThreadHead'
-import { getThread } from 'reddit'
-import { getThread as getRemovedThread } from 'pushshift'
+import CommentSection from 'components/CommentSection'
+import {
+ getThread,
+ getCommentIDs,
+} from 'reddit'
+import {
+ getThread as getRemovedThread,
+ getCommentIDs as getAllCommentIDs,
+} from 'pushshift'
import { isDeleted } from 'utils'
export default class Thread extends React.Component {
@@ -10,24 +17,39 @@ export default class Thread extends React.Component {
this.state = {
thread: {},
+ comments: [],
}
}
componentDidMount() {
const { subreddit, threadID } = this.props.match.params
- getThread(subreddit, threadID)
- .then(thread => {
- this.setState({ thread })
+ let pushshiftCommentIDs
- // Fetch the thread from pushshift if it was deleted/removed
- if (isDeleted(thread.selftext)) {
- getRemovedThread(threadID)
- .then(removedThread => {
- removedThread.removed = true
- this.setState({ thread: removedThread })
- })
- }
+ Promise.all([
+ // Get thread from reddit
+ getThread(subreddit, threadID)
+ .then(thread => {
+ this.setState({ thread })
+
+ // Fetch the thread from pushshift if it was deleted/removed
+ if (isDeleted(thread.selftext)) {
+ getRemovedThread(threadID)
+ .then(removedThread => {
+ removedThread.removed = true
+ this.setState({ thread: removedThread })
+ })
+ }
+ }),
+
+ // Get comment ids from pushshift
+ getAllCommentIDs(threadID)
+ .then(commentIDs => { pushshiftCommentIDs = commentIDs }),
+ ])
+ .then(() => {
+ // Get comment ids from reddit
+ getCommentIDs()
+ // .then(console.log)
})
}
@@ -35,7 +57,7 @@ export default class Thread extends React.Component {
return (
-
lol
+
)
}
diff --git a/src/js/pushshift/index.js b/src/js/pushshift/index.js
index b89cd68..f3619b4 100644
--- a/src/js/pushshift/index.js
+++ b/src/js/pushshift/index.js
@@ -25,6 +25,10 @@ export const getThread = threadID => {
fetch(threadURL + JSON.stringify(elasticQuery))
.then(json)
.then(jsonData => jsonData.hits.hits[0]._source)
+ .then(thread => {
+ thread.id = toBase36(thread.id)
+ return thread
+ })
)
}
diff --git a/src/js/reddit/index.js b/src/js/reddit/index.js
index 4cfa197..13561ee 100644
--- a/src/js/reddit/index.js
+++ b/src/js/reddit/index.js
@@ -16,11 +16,11 @@ let baseCommentTree = {}
// Headers for getting reddit api token
const tokenInit = {
headers: {
- Authorization: `Basic ${btoa(clientID + ':')}`,
+ Authorization: `Basic ${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`,
}
const fetchToken = () => {
@@ -59,17 +59,17 @@ export const getCommentIDs = () => {
// return HandleIDs.morechildren()
// .catch(function(error){
// return Promise.reject("Could not get comments from Reddit (moreChildren)");
-// });
+// });
// })
// .then(function(){
-// return Promise.all(_.map(_.uniq(Comments.countinuethread), function(id) {
+// return Promise.all(_.map(_.uniq(Comments.countinuethread), function(id) {
// return fetch(URLs.thread+"/_/"+id.split("_")[1], Reddit.init)
// .then(Fetch2.json)
// .catch(function(error){ return Promise.reject("Could not get comments from Reddit (continueThisThread)") })
// }))
// .catch(function(error){
// return Promise.reject("Could not get comments from Reddit (continueThisThread)");
-// });
+// });
// })
// .then(function(smallerThreads){
// _.forEach(smallerThreads, function(thread){
@@ -81,7 +81,7 @@ export const getCommentIDs = () => {
// return Fetch2.multiple(URLs.format(URLs.pushshiftComments, Comments.removed), null, "data")
// .catch(function(error){
// return Promise.reject("Could not get removed comments");
-// });
+// });
// })
// .then(function(removedComments){
// Status.loading("Generating comments...");
@@ -108,13 +108,13 @@ export const getCommentIDs = () => {
// var lookup = {};
// var toBeCreated = [];
-// var getParentComments = function(toLookup){
+// var getParentComments = function(toLookup){
// var newCommentsToLookup = [];
// var commentsToFetch = [];
// _.forEach(toLookup, function(id){
// var parentID = lookup[id].parent_id.split("_")[1];
-
+
// if(parentID === Reddit.threadID) {} // Has no parent (is parent of thread)
// else if(_.includes(Comments.toBeCreated, parentID)) {} // Parent already exists, do nothing
// else if(_.includes(newCommentsToLookup, parentID)) {} // Parent already exists (this iteration)
@@ -123,11 +123,11 @@ export const getCommentIDs = () => {
// } else{
// commentsToFetch.push(parentID);
// }
-
+
// Comments.toBeCreated.push(id);
// });
-
-// return new Promise(function(resolve, reject){
+
+// return new Promise(function(resolve, reject){
// if(_.uniq(commentsToFetch).length !== 0) {
// fetch(URLs.singleComments + _.join(_.map(_.uniq(commentsToFetch),function(comments){
// return "t1_" + comments;
@@ -142,9 +142,9 @@ export const getCommentIDs = () => {
// .then(function(){
// resolve();
// });
-
+
// } else {
-// resolve();
+// resolve();
// }
// })
// .then(function(){
@@ -152,14 +152,14 @@ export const getCommentIDs = () => {
// return getParentComments(newCommentsToLookup)
// }
// });
-
+
// };
// return {
// ids: [], // The comments we found
// morechildren: [],
// countinuethread: [],
-
+
// allIDs: [], // All the comments that we were suppose to find
// removed: [],
// deleted: [],
@@ -180,7 +180,7 @@ export const getCommentIDs = () => {
// if(_.has(Comments.lookup, Reddit.permalink)) {
// return Comments.lookup[Reddit.permalink].parent_id.split("_")[1];
-// }
+// }
// return "";
// },
// generate: function(removedComments) {
@@ -188,26 +188,25 @@ export const getCommentIDs = () => {
// if(_.includes(Comments.deleted, comment.id)) {
// comment["deleted"] = true;
// } else {
-// comment["removed"] = true;
+// comment["removed"] = true;
// }
-
+
// Comments.lookup[comment.id] = comment;
// });
-
+
// Comments.removed = _.map(removedComments, function(comment){
// return comment.id;
// });
-
+
// return getParentComments(Comments.removed)
-// .then(function(){
-// ThreadHTML.createCommentSection();
+// .then(function(){
+// ThreadHTML.createCommentSection();
// ThreadHTML.createComments();
// })
// }
// }})();
-
// // ------------------------------------------------------------------------------
// // ----------------- Handle comments from different requests --------------------
// // ------------------------------------------------------------------------------
@@ -217,7 +216,7 @@ export const getCommentIDs = () => {
// };
// var morechildren = function(){
-// return Promise.all(_.map(_.uniq(Comments.morechildren), function(idArray){
+// return Promise.all(_.map(_.uniq(Comments.morechildren), function(idArray){
// return Fetch2.multiple(URLs.format(URLs.moreChildren, idArray), Reddit.init);
// }))
// .then(function(responseArrays){
@@ -232,7 +231,7 @@ export const getCommentIDs = () => {
// }).then(function(){
// if(Comments.morechildren.length !== 0) {
// return morechildren();
-// }
+// }
// });
// };
@@ -243,7 +242,7 @@ export const getCommentIDs = () => {
// if(! _.has(Comments.lookup, id)) {
// return;
// }
-
+
// if(Comments.lookup[id].body === "[removed]") {
// Comments.removed.push(id);
// } else if (Comments.lookup[id].body === "[deleted]"){
@@ -269,8 +268,8 @@ export const getCommentIDs = () => {
// var Extract = (function(){
// var normal = function(comment){
// var data = comment.data;
-
-// if(comment.kind == "more") { // "Show more"-comment
+
+// if(comment.kind == "more") { // "Show more"-comment
// if(data.id === "_") { // = "continue this thread" comment
// Comments.countinuethread.push(data.parent_id);
// } else if(data.children.length < data.count){ // "Load more"-comment (that is missing some of its children)
@@ -284,15 +283,15 @@ export const getCommentIDs = () => {
// });
// delete data.replies;
// }
-
+
// Comments.ids.push(data.id);
// Comments.lookup[data.id] = data;
// }
// };
-
+
// return {
// normal: normal
-// };
+// };
// })();
@@ -300,7 +299,7 @@ export const getCommentIDs = () => {
// // ---------------------------- Generating HTML ---------------------------------
// // ------------------------------------------------------------------------------
-
+
// var createComments = function(){
// var commentsToCreate = _.sortBy(_.uniq(Comments.toBeCreated), function(id) {
// return Comments.lookup[id].score;
@@ -308,14 +307,14 @@ export const getCommentIDs = () => {
// var createdComments = [Comments.getRoot()];
// var didSomething = false;
-
+
// while(commentsToCreate.length > 0) {
// didSomething = false;
-
+
// for(var i = commentsToCreate.length - 1; i >= 0; i--) {
// var id = commentsToCreate[i];
// var parentID = Comments.lookup[id].parent_id.split("_")[1];
-
+
// if(_.includes(createdComments, parentID)) {
// document.getElementById(parentID).appendChild(createComment(Comments.lookup[id]));
// createdComments.push(id);
@@ -323,7 +322,7 @@ export const getCommentIDs = () => {
// didSomething = true;
// }
// }
-
+
// // Fail safe (parents missing for the rest of the comments, shouldn't happend but oh well :D)
// if(!didSomething) {
// console.error("Didn't generate all comments correctly");
@@ -332,5 +331,3 @@ export const getCommentIDs = () => {
// }
// };
-
-
\ No newline at end of file