add instant mod edits

This commit is contained in:
plebeius.eth
2023-09-16 17:29:14 +02:00
parent 6f2e8dcaa8
commit e8b42786e1
11 changed files with 90 additions and 14 deletions
+1 -1
View File
@@ -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);
+5
View File
@@ -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 = [];
+1 -1
View File
@@ -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);
+27 -2
View File
@@ -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 ? (
<Virtuoso
increaseViewportBy={{bottom: 600, top: 600}}
data={selectedFeed}
data={filteredFeed}
itemContent={(index, thread) => {
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 = () => {
</span>) : null}
</span>
{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 = () => {
</div>
</div>
{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 (
+1 -1
View File
@@ -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}`);
+21 -3
View File
@@ -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}
<Virtuoso
increaseViewportBy={{bottom: 600, top: 600}}
data={selectedFeed}
data={filteredFeed}
itemContent={(index, thread) => {
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}
</span>
{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);
+2 -2
View File
@@ -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) {
+27 -2
View File
@@ -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 = () => {
) : (
<Virtuoso
increaseViewportBy={{bottom: 600, top: 600}}
data={selectedFeed}
data={filteredFeed}
itemContent={(index, thread) => {
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 = () => {
</span>) : null}
</span>
{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 = () => {
</div>
</div>
{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 (
@@ -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}`);
+1 -1
View File
@@ -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}`);
+3
View File
@@ -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: {