diff --git a/src/components/BoardSettings.jsx b/src/components/BoardSettings.jsx index 846d9cff..a183737b 100644 --- a/src/components/BoardSettings.jsx +++ b/src/components/BoardSettings.jsx @@ -138,7 +138,7 @@ const BoardSettings = ({ subplebbit }) => { const onChallengeVerification = (challengeVerification) => { if (challengeVerification.challengeSuccess === true) { - setNewSuccessMessage('Challenge Success'); + setNewSuccessMessage('Challenge Success'); console.log('challenge success', challengeVerification); } else if (challengeVerification.challengeSuccess === false) { setNewErrorMessage(`Challenge Failed, reason: ${challengeVerification.reason}. Errors: ${challengeVerification.errors}`); console.log('challenge failed', challengeVerification); diff --git a/src/components/EditLabel.jsx b/src/components/EditLabel.jsx index 0ccd2f3b..aa3e3b76 100644 --- a/src/components/EditLabel.jsx +++ b/src/components/EditLabel.jsx @@ -3,14 +3,19 @@ import { useComment, useEditedComment } from "@plebbit/plebbit-react-hooks"; import { Link } from "react-router-dom"; import OriginalCommentModal from "./modals/OriginalCommentModal"; import getDate from "../utils/getDate"; +import useGeneralStore from "../hooks/stores/useGeneralStore"; const EditLabel = ({ commentCid, className }) => { + const { editedComments, setEditedComments } = useGeneralStore(state => state); const [isOriginalCommentModalOpen, setIsOriginalCommentModalOpen] = useState(false); const comment = useComment({commentCid}); const timestamp = getDate(comment.edit?.timestamp); const {state: editedCommentState, editedComment} = useEditedComment({comment}); + if (editedCommentState === 'pending' && !(commentCid in editedComments)) { + setEditedComments({...editedComments, [commentCid]: editedComment}) + } const conditionsCheck = () => { let conditions = []; diff --git a/src/components/modals/ModerationModal.jsx b/src/components/modals/ModerationModal.jsx index 1d03b46c..e50dc005 100755 --- a/src/components/modals/ModerationModal.jsx +++ b/src/components/modals/ModerationModal.jsx @@ -58,7 +58,7 @@ const ModerationModal = ({ isOpen, closeModal, deletePost }) => { const onChallengeVerification = (challengeVerification) => { if (challengeVerification.challengeSuccess === true) { - setNewSuccessMessage('Challenge Success'); + setNewSuccessMessage('Challenge Success'); console.log('challenge success', challengeVerification); } else if (challengeVerification.challengeSuccess === false) { setNewErrorMessage(`Challenge Failed, reason: ${challengeVerification.reason}. Errors: ${challengeVerification.errors}`); console.log('challenge failed', challengeVerification); diff --git a/src/components/views/All.jsx b/src/components/views/All.jsx index 00a605ec..f578aaa4 100755 --- a/src/components/views/All.jsx +++ b/src/components/views/All.jsx @@ -54,6 +54,7 @@ const All = () => { const { defaultSubplebbits, editedComment, + editedComments, feedCacheStates, setFeedCacheState, isSettingsOpen, setIsSettingsOpen, @@ -331,6 +332,13 @@ const All = () => { return selectedFeed.flatMap(thread => filteredRepliesByThread[thread.cid]?.displayedReplies || []); }, [selectedFeed, filteredRepliesByThread]); + const filteredFeed = useMemo(() => { + return selectedFeed.filter(thread => { + const editedThread = editedComments[thread.cid]; + return !(editedThread && editedThread.removed); + }); + }, [selectedFeed, editedComments]); + // let post.jsx access full cid of user-typed short cid useEffect(() => { const newCidTracker = {}; @@ -364,7 +372,7 @@ const All = () => { const onChallengeVerification = (challengeVerification) => { if (challengeVerification.challengeSuccess === true) { - setNewSuccessMessage('Challenge Success'); + setNewSuccessMessage('Challenge Success'); console.log('challenge success', challengeVerification); } else if (challengeVerification.challengeSuccess === false) { setNewErrorMessage(`Challenge Failed, reason: ${challengeVerification.reason}. Errors: ${challengeVerification.errors}`); @@ -713,8 +721,11 @@ const All = () => { {feed ? ( { + if (editedComments[thread.cid]) { + thread = editedComments[thread.cid]; + }; const { displayedReplies, omittedCount } = filteredRepliesByThread[thread.cid] || {}; const commentMediaInfo = getCommentMediaInfo(thread); const fallbackImgUrl = "assets/filedeleted-res.gif"; @@ -1157,6 +1168,13 @@ const All = () => { ) : null} {displayedReplies?.map((reply, index) => { + if (editedComments[reply.cid]) { + reply = editedComments[reply.cid]; + if (reply.removed) { + reply.content = "[removed]"; + reply.link = undefined; + } + } const replyMediaInfo = getCommentMediaInfo(reply); const fallbackImgUrl = "assets/filedeleted-res.gif"; const shortParentCid = findShortParentCid(reply.parentCid, selectedFeed); @@ -2099,6 +2117,13 @@ const All = () => { {displayedReplies?.map((reply, index) => { + if (editedComments[reply.cid]) { + reply = editedComments[reply.cid]; + if (reply.removed) { + reply.content = "[removed]"; + reply.link = undefined; + } + } const replyMediaInfo = getCommentMediaInfo(reply); const shortParentCid = findShortParentCid(reply.parentCid, selectedFeed); return ( diff --git a/src/components/views/AllCatalog.jsx b/src/components/views/AllCatalog.jsx index 49640a77..5bc17307 100755 --- a/src/components/views/AllCatalog.jsx +++ b/src/components/views/AllCatalog.jsx @@ -241,7 +241,7 @@ const CatalogPost = ({post}) => { const onChallengeVerification = (challengeVerification) => { if (challengeVerification.challengeSuccess === true) { - setNewSuccessMessage('Challenge Success'); + setNewSuccessMessage('Challenge Success'); console.log('challenge success', challengeVerification); } else if (challengeVerification.challengeSuccess === false) { setNewErrorMessage(`Challenge Failed, reason: ${challengeVerification.reason}. Errors: ${challengeVerification.errors}`); diff --git a/src/components/views/Board.jsx b/src/components/views/Board.jsx index 7abefaff..3e40909f 100755 --- a/src/components/views/Board.jsx +++ b/src/components/views/Board.jsx @@ -60,6 +60,7 @@ const Board = () => { setChallengesArray, defaultSubplebbits, editedComment, + editedComments, feedCacheStates, setFeedCacheState, setIsAuthorDelete, @@ -339,6 +340,13 @@ const Board = () => { return selectedFeed.flatMap(thread => filteredRepliesByThread[thread.cid]?.displayedReplies || []); }, [selectedFeed, filteredRepliesByThread]); + const filteredFeed = useMemo(() => { + return selectedFeed.filter(thread => { + const editedThread = editedComments[thread.cid]; + return !(editedThread && editedThread.removed); + }); + }, [selectedFeed, editedComments]); + // let post.jsx access full cid of user-typed short cid useEffect(() => { const newCidTracker = {}; @@ -397,7 +405,7 @@ const Board = () => { navigate(`/p/${subplebbitAddress}/c/${challengeVerification.publication?.cid}`); console.log('challenge success'); } else { - setNewSuccessMessage('Challenge Success'); + setNewSuccessMessage('Challenge Success'); console.log('challenge success', challengeVerification); } } else if (challengeVerification.challengeSuccess === false) { @@ -587,7 +595,7 @@ const Board = () => { const [publishCommentEditOptions, setPublishCommentEditOptions] = useState({ commentCid: commentCid, content: editedComment || undefined, - subplebbitAddress: selectedAddress, + subplebbitAddress, onChallenge, onChallengeVerification, onError: (error) => { @@ -1628,8 +1636,11 @@ const Board = () => { : null} { + if (editedComments[thread.cid]) { + thread = editedComments[thread.cid]; + }; const { displayedReplies, omittedCount } = filteredRepliesByThread[thread.cid] || {}; const commentMediaInfo = getCommentMediaInfo(thread); const fallbackImgUrl = "assets/filedeleted-res.gif"; @@ -2079,6 +2090,13 @@ const Board = () => { ) : null} {displayedReplies?.map((reply, index) => { + if (editedComments[reply.cid]) { + reply = editedComments[reply.cid]; + if (reply.removed) { + reply.content = "[removed]"; + reply.link = undefined; + } + } const replyMediaInfo = getCommentMediaInfo(reply); const fallbackImgUrl = "assets/filedeleted-res.gif"; const shortParentCid = findShortParentCid(reply.parentCid, selectedFeed); diff --git a/src/components/views/Catalog.jsx b/src/components/views/Catalog.jsx index 1053f280..47af8353 100755 --- a/src/components/views/Catalog.jsx +++ b/src/components/views/Catalog.jsx @@ -235,7 +235,7 @@ const CatalogPost = ({post}) => { const onChallengeVerification = (challengeVerification) => { if (challengeVerification.challengeSuccess === true) { - setNewSuccessMessage('Challenge Success'); + setNewSuccessMessage('Challenge Success'); console.log('challenge success', challengeVerification); } else if (challengeVerification.challengeSuccess === false) { setNewErrorMessage(`Challenge Failed, reason: ${challengeVerification.reason}. Errors: ${challengeVerification.errors}`); @@ -1093,7 +1093,7 @@ const Catalog = () => { navigate(`/p/${subplebbitAddress}/c/${challengeVerification.publication?.cid}`); console.log('challenge success'); } else { - setNewSuccessMessage('Challenge Success'); + setNewSuccessMessage('Challenge Success'); console.log('challenge success', challengeVerification); } } else if (challengeVerification.challengeSuccess === false) { diff --git a/src/components/views/Subscriptions.jsx b/src/components/views/Subscriptions.jsx index 3184702e..4c2f93ef 100755 --- a/src/components/views/Subscriptions.jsx +++ b/src/components/views/Subscriptions.jsx @@ -54,6 +54,7 @@ const Subscriptions = () => { const { defaultSubplebbits, editedComment, + editedComments, feedCacheStates, setFeedCacheState, isSettingsOpen, setIsSettingsOpen, @@ -332,6 +333,13 @@ const Subscriptions = () => { return selectedFeed.flatMap(thread => filteredRepliesByThread[thread.cid]?.displayedReplies || []); }, [selectedFeed, filteredRepliesByThread]); + const filteredFeed = useMemo(() => { + return selectedFeed.filter(thread => { + const editedThread = editedComments[thread.cid]; + return !(editedThread && editedThread.removed); + }); + }, [selectedFeed, editedComments]); + // let post.jsx access full cid of user-typed short cid useEffect(() => { const newCidTracker = {}; @@ -366,7 +374,7 @@ const Subscriptions = () => { const onChallengeVerification = (challengeVerification) => { if (challengeVerification.challengeSuccess === true) { - setNewSuccessMessage('Challenge Success'); + setNewSuccessMessage('Challenge Success'); console.log('challenge success', challengeVerification); } else if (challengeVerification.challengeSuccess === false) { setNewErrorMessage(`Challenge Failed, reason: ${challengeVerification.reason}. Errors: ${challengeVerification.errors}`); @@ -721,8 +729,11 @@ const Subscriptions = () => { ) : ( { + if (editedComments[thread.cid]) { + thread = editedComments[thread.cid]; + }; const { displayedReplies, omittedCount } = filteredRepliesByThread[thread.cid] || {}; const commentMediaInfo = getCommentMediaInfo(thread); const fallbackImgUrl = "assets/filedeleted-res.gif"; @@ -1165,6 +1176,13 @@ const Subscriptions = () => { ) : null} {displayedReplies?.map((reply, index) => { + if (editedComments[reply.cid]) { + reply = editedComments[reply.cid]; + if (reply.removed) { + reply.content = "[removed]"; + reply.link = undefined; + } + } const replyMediaInfo = getCommentMediaInfo(reply); const fallbackImgUrl = "assets/filedeleted-res.gif"; const shortParentCid = findShortParentCid(reply.parentCid, selectedFeed); @@ -2107,6 +2125,13 @@ const Subscriptions = () => { {displayedReplies?.map((reply, index) => { + if (editedComments[reply.cid]) { + reply = editedComments[reply.cid]; + if (reply.removed) { + reply.content = "[removed]"; + reply.link = undefined; + } + } const replyMediaInfo = getCommentMediaInfo(reply); const shortParentCid = findShortParentCid(reply.parentCid, selectedFeed); return ( diff --git a/src/components/views/SubscriptionsCatalog.jsx b/src/components/views/SubscriptionsCatalog.jsx index 1e4babea..36709181 100755 --- a/src/components/views/SubscriptionsCatalog.jsx +++ b/src/components/views/SubscriptionsCatalog.jsx @@ -241,7 +241,7 @@ const CatalogPost = ({post}) => { const onChallengeVerification = (challengeVerification) => { if (challengeVerification.challengeSuccess === true) { - setNewSuccessMessage('Challenge Success'); + setNewSuccessMessage('Challenge Success'); console.log('challenge success', challengeVerification); } else if (challengeVerification.challengeSuccess === false) { setNewErrorMessage(`Challenge Failed, reason: ${challengeVerification.reason}. Errors: ${challengeVerification.errors}`); diff --git a/src/components/views/Thread.jsx b/src/components/views/Thread.jsx index e1f9fa8b..5204cda9 100755 --- a/src/components/views/Thread.jsx +++ b/src/components/views/Thread.jsx @@ -347,7 +347,7 @@ const Thread = () => { if (challengeVerification.publication?.cid !== undefined) { return; } else { - setNewSuccessMessage('Challenge Success'); + setNewSuccessMessage('Challenge Success'); console.log('challenge success', challengeVerification); } } else if (challengeVerification.challengeSuccess === false) { setNewErrorMessage(`Challenge Failed, reason: ${challengeVerification.reason}. Errors: ${challengeVerification.errors}`); diff --git a/src/hooks/stores/useGeneralStore.js b/src/hooks/stores/useGeneralStore.js index 1fabcd4a..926446c2 100644 --- a/src/hooks/stores/useGeneralStore.js +++ b/src/hooks/stores/useGeneralStore.js @@ -26,6 +26,9 @@ const useGeneralStore = create((set) => ({ editedComment: '', setEditedComment: (comment) => set({ editedComment: comment }), + editedComments: {}, + setEditedComments: (comments) => set({ editedComments: comments }), + feedCacheStates: {}, setFeedCacheState: (address, isCached) => set((prev) => ({ feedCacheStates: {