- {comment.replies?.pages.topAll.comments
+ {comment?.replies?.pages?.topAll.comments
.sort((a, b) => a.timestamp - b.timestamp)
.map((reply) => (
: null}
{comment.replyCount > 0 &&
- Object.keys(comment.replies.pages.topAll.comments).map(() => {
- const renderedComments = renderThreadComments(comment.replies.pages.topAll.comments);
+ Object.keys(comment?.replies?.pages?.topAll.comments).map(() => {
+ const renderedComments = renderThreadComments(comment?.replies?.pages?.topAll.comments);
return renderedComments.map(reply => {
const replyMediaInfo = getCommentMediaInfo(reply);
const fallbackImgUrl = "/assets/filedeleted-res.gif";
@@ -548,7 +548,7 @@ const Thread = () => {
- {reply.replies?.pages.topAll.comments
+ {reply.replies?.pages?.topAll.comments
.sort((a, b) => a.timestamp - b.timestamp)
.map((reply) => (
@@ -711,8 +711,8 @@ const Thread = () => {
{comment.replyCount === undefined ?
: null}
{comment.replyCount > 0 &&
- Object.keys(comment.replies.pages.topAll.comments).map(() => {
- const renderedComments = renderThreadComments(comment.replies.pages.topAll.comments);
+ Object.keys(comment?.replies?.pages?.topAll.comments).map(() => {
+ const renderedComments = renderThreadComments(comment?.replies?.pages?.topAll.comments);
return renderedComments.map(reply => {
return (
diff --git a/src/utils/getCommentMediaInfo.js b/src/utils/getCommentMediaInfo.js
index 8415eebe..57e6d0b0 100644
--- a/src/utils/getCommentMediaInfo.js
+++ b/src/utils/getCommentMediaInfo.js
@@ -4,12 +4,12 @@ const getCommentMediaInfo = (comment) => {
if (!comment?.thumbnailUrl && !comment?.link) {
return;
}
- if (comment?.thumbnailUrl) {
- return {
- url: comment.link,
- type: 'webpage'
- };
- }
+ // if (comment?.thumbnailUrl) {
+ // return {
+ // url: comment.link,
+ // type: 'webpage'
+ // };
+ // }
if (comment?.link) {
try {
new URL(comment.link);
diff --git a/src/utils/renderComments.js b/src/utils/renderComments.js
index 4f99e185..d47827fb 100644
--- a/src/utils/renderComments.js
+++ b/src/utils/renderComments.js
@@ -3,7 +3,7 @@ function renderComments(comments) {
let omittedCount = 0;
const renderComment = (comment) => {
- const { replyCount, replies: { pages: { topAll: { comments: nestedComments } } } } = comment;
+ const { replyCount, replies: { pages: { topAll: { comments: nestedComments = [] } = {} } = {} } = {} } = comment;
let renderedNestedComments = [];
if (replyCount > 0 && nestedComments.length > 0) {
@@ -21,8 +21,8 @@ function renderComments(comments) {
return displayedComments;
};
- const renderedComments = comments.flatMap(renderComment);
- renderedComments.sort((a, b) => a.timestamp - b.timestamp);
+ const renderedComments = comments?.flatMap(renderComment);
+ renderedComments?.sort((a, b) => a.timestamp - b.timestamp);
return { renderedComments, omittedCount };
}
diff --git a/src/utils/renderThreadComments.js b/src/utils/renderThreadComments.js
index 58b5b874..05efd097 100644
--- a/src/utils/renderThreadComments.js
+++ b/src/utils/renderThreadComments.js
@@ -2,7 +2,7 @@ function renderThreadComments(comments) {
const commentKeys = Object.keys(comments);
const renderedComments = commentKeys.map(key => {
const comment = comments[key];
- const { replies: { pages: { topAll: { comments: nestedComments } } } } = comment;
+ const { replies: { pages: { topAll: { comments: nestedComments = [] } = {} } = {} } = {} } = comment;
if (comment.replyCount > 0 && nestedComments) {
const renderedNestedComments = renderThreadComments(nestedComments);
return [comment, ...renderedNestedComments];