From a6a0e62ccf8cae77387e152df4a56020adf957e5 Mon Sep 17 00:00:00 2001 From: plebbitor Date: Mon, 17 Apr 2023 10:20:35 +0200 Subject: [PATCH] added custom parentShortCid --- src/components/views/Board.jsx | 7 +++++++ src/utils/findParentShortCid.js | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/utils/findParentShortCid.js diff --git a/src/components/views/Board.jsx b/src/components/views/Board.jsx index 4dbcda44..dd3e9658 100644 --- a/src/components/views/Board.jsx +++ b/src/components/views/Board.jsx @@ -11,6 +11,7 @@ import Post from '../Post'; import PostLoader from '../PostLoader'; import ReplyModal from '../ReplyModal'; import SettingsModal from '../SettingsModal'; +import findParentShortCid from '../../utils/findParentShortCid'; import getCommentMediaInfo from '../../utils/getCommentMediaInfo'; import getDate from '../../utils/getDate'; import handleQuoteClick from '../../utils/handleQuoteClick'; @@ -57,6 +58,8 @@ const Board = () => { useError(errorMessage, [errorMessage]); useSuccess(successMessage, [successMessage]); + console.log(selectedFeed); + // temporary title from JSON, gets subplebbitAddress from URL useEffect(() => { @@ -518,6 +521,7 @@ const Board = () => { {renderedComments?.map((reply) => { const replyMediaInfo = getCommentMediaInfo(reply); const fallbackImgUrl = "/assets/filedeleted-res.gif"; + const parentShortCid = findParentShortCid(reply.parentCid, selectedFeed); return (
{'>>'}
@@ -632,6 +636,9 @@ const Board = () => { :
+ {}}> + {`c/${parentShortCid}`}{
} +
) : null} diff --git a/src/utils/findParentShortCid.js b/src/utils/findParentShortCid.js new file mode 100644 index 00000000..3f18b5f3 --- /dev/null +++ b/src/utils/findParentShortCid.js @@ -0,0 +1,16 @@ +function findParentShortCid(parentCid, selectedFeed) { + for (const thread of selectedFeed) { + if (thread.cid === parentCid) { + return thread.shortCid; + } + if (thread.replyCount > 0 && thread.replies.pages.topAll.comments) { + const shortCid = findParentShortCid(parentCid, thread.replies.pages.topAll.comments); + if (shortCid) { + return shortCid; + } + } + } + return null; +} + +export default findParentShortCid; \ No newline at end of file