update moderation

This commit is contained in:
Tom
2023-05-21 16:36:03 +02:00
parent 4f0f6a9471
commit 0b7606eecb
3 changed files with 187 additions and 293 deletions
+86 -145
View File
@@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { Helmet } from 'react-helmet-async';
import { Link, useNavigate, useParams } from 'react-router-dom';
import { Tooltip } from 'react-tooltip';
import { useAccount, useAccountComments, useComment, usePublishComment, usePublishCommentEdit, useSubplebbit } from '@plebbit/plebbit-react-hooks';
import { useAccount, useAccountComments, useComment, usePublishComment, useSubplebbit } from '@plebbit/plebbit-react-hooks';
import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/utils'
import { debounce } from 'lodash';
import useGeneralStore from '../../hooks/stores/useGeneralStore';
@@ -63,7 +63,7 @@ const Thread = () => {
const replyMenuRefs = useRef({});
const [triggerPublishComment, setTriggerPublishComment] = useState(false);
const [triggerPublishCommentEdit, setTriggerPublishCommentEdit] = useState(false);
const [deletePost, setDeletePost] = useState(false);
const [errorMessage, setErrorMessage] = useState(null);
const [successMessage, setSuccessMessage] = useState(null);
const [isReplyOpen, setIsReplyOpen] = useState(false);
@@ -73,7 +73,6 @@ const Thread = () => {
const [isImageSearchOpen, setIsImageSearchOpen] = useState(false);
const [isModerator, setIsModerator] = useState(false);
const [isModToolsOpen, setIsModToolsOpen] = useState(false);
const [commentCid, setCommentCid] = useState(null);
useError(errorMessage, [errorMessage]);
useSuccess(successMessage, [successMessage]);
@@ -332,76 +331,6 @@ const Thread = () => {
};
const [publishCommentEditOptions, setPublishCommentEditOptions] = useState({
commentCid: commentCid,
subplebbitAddress: selectedAddress,
onChallenge,
onChallengeVerification,
onError: (error) => {
setErrorMessage(error);
},
});
const {error, publishCommentEdit } = usePublishCommentEdit(publishCommentEditOptions);
useEffect(() => {
if (error) {
setErrorMessage(error);
}
}, [error]);
const handleModToolClick = (tool, commentCid, currentState) => {
setCommentCid(commentCid);
handleOptionClick(commentCid);
switch (tool) {
case 'Pin':
case 'Unpin':
setPublishCommentEditOptions(prevOptions => ({
...prevOptions,
pinned: !currentState.pinned,
}));
break;
case 'Close':
case 'Reopen':
setPublishCommentEditOptions(prevOptions => ({
...prevOptions,
locked: !currentState.locked,
}));
break;
case 'Delete':
setPublishCommentEditOptions(prevOptions => ({
...prevOptions,
removed: true,
}));
break;
default:
break;
}
setTriggerPublishCommentEdit(true);
};
useEffect(() => {
setPublishCommentEditOptions((prevOptions) => ({
...prevOptions,
commentCid: commentCid,
}));
}, [commentCid]);
useEffect(() => {
if (publishCommentEditOptions && triggerPublishCommentEdit) {
(async () => {
await publishCommentEdit();
setTriggerPublishCommentEdit(false);
})();
}
}, [publishCommentEditOptions, triggerPublishCommentEdit, publishCommentEdit]);
// mobile navbar board select functionality
const handleSelectChange = (event) => {
const selected = event.target.value;
@@ -444,7 +373,8 @@ const Thread = () => {
<ModerationModal
selectedStyle={selectedStyle}
isOpen={isModerationOpen}
closeModal={() => setIsModerationOpen(false)} />
closeModal={() => setIsModerationOpen(false)}
deletePost={deletePost} />
<NavBar selectedStyle={selectedStyle}>
<>
<span className="boardList">
@@ -782,8 +712,39 @@ const Thread = () => {
<div id="post-menu" className={`post-menu-thread post-menu-thread-${comment.cid}`}
style={{ display: rotatedStates[comment.cid] ? 'block' : 'none' }}>
<ul>
{/* <li>Edit post</li> */}
<li onClick={() => {handleOptionClick(comment.cid)}}>Hide thread</li>
<li onClick={() => handleOptionClick(comment.cid)}>Hide thread</li>
{comment.author.shortAddress === account.author.shortAddress ? (
<>
<li onClick={() => handleOptionClick(comment.cid)}>Edit post</li>
<li onClick={() => handleOptionClick(comment.cid)}>Delete post</li>
</>
) : null}
{isModerator ? (
<>
{comment.author.shortAddress === account.author.shortAddress ? (
null
) : (
<li onClick={() => {
setModeratingCommentCid(comment.cid)
setIsModerationOpen(true);
handleOptionClick(comment.cid);
setDeletePost(true);
}}>
Delete post
</li>
)}
<li
onMouseOver={() => {setIsModToolsOpen(true)}}
onMouseLeave={() => {setIsModToolsOpen(false)}}
onClick={() => {
setModeratingCommentCid(comment.cid)
setIsModerationOpen(true);
handleOptionClick(comment.cid);
}}>
Mod tools
</li>
</>
) : null}
{(commentMediaInfo && (
commentMediaInfo.type === 'image' ||
(commentMediaInfo.type === 'webpage' &&
@@ -794,19 +755,19 @@ const Thread = () => {
Image search »
<ul className="dropdown-menu"
style={{display: isImageSearchOpen ? 'block': 'none'}}>
<li>
<li onClick={() => handleOptionClick(comment.cid)}>
<a
href={`https://lens.google.com/uploadbyurl?url=${commentMediaInfo.url}`}
target="_blank" rel="noreferrer"
>Google</a>
</li>
<li>
<li onClick={() => handleOptionClick(comment.cid)}>
<a
href={`https://yandex.com/images/search?url=${commentMediaInfo.url}`}
target="_blank" rel="noreferrer"
>Yandex</a>
</li>
<li>
<li onClick={() => handleOptionClick(comment.cid)}>
<a
href={`https://saucenao.com/search.php?url=${commentMediaInfo.url}`}
target="_blank" rel="noreferrer"
@@ -816,42 +777,6 @@ const Thread = () => {
</li>
) : null
}
{isModerator ? (
<li
onMouseOver={() => {setIsModToolsOpen(true)}}
onMouseLeave={() => {setIsModToolsOpen(false)}}>
Mod tools »
<ul className="dropdown-menu"
style={{display: isModToolsOpen ? 'block': 'none'}}>
<li onClick={() => {
setModeratingCommentCid(comment.cid);
setIsModerationOpen(true);
handleOptionClick(comment.cid);
}}>
Open tools
</li>
<li onClick={() => handleModToolClick(
comment.pinned ? 'Unpin' : 'Pin',
comment.cid,
{ pinned: comment.pinned, locked: comment.locked }
)}>
{comment.pinned ? 'Unpin' : 'Pin'}
</li>
<li onClick={() => handleModToolClick(
comment.locked ? 'Reopen' : 'Close',
comment.cid,
{ pinned: comment.pinned, locked: comment.locked }
)}>
{comment.locked ? 'Reopen' : 'Close'}
</li>
<li onClick={() => handleModToolClick(
'Delete', comment.cid
)}>
Delete
</li>
</ul>
</li>
) : null}
</ul>
</div>
<div id="backlink-id" className="backlink">
@@ -958,34 +883,65 @@ const Thread = () => {
>
</PostMenu>
<div id="post-menu" className={`post-menu-reply post-menu-reply-${reply.cid}`}
<div id="post-menu" className={`post-menu-reply post-menu-reply-${reply.cid}`}
style={{ display: rotatedStates[reply.cid] ? 'block' : 'none' }}>
<ul>
{/* <li>Edit post</li> */}
<li onClick={() => handleOptionClick(reply.cid)}>Hide post</li>
{(replyMediaInfo && (
replyMediaInfo.type === 'image' ||
(replyMediaInfo.type === 'webpage' &&
replyMediaInfo.thumbnail))) ? (
<ul>
<li onClick={() => handleOptionClick(reply.cid)}>Hide post</li>
{reply.author.shortAddress === account.author.shortAddress ? (
<>
<li onClick={() => handleOptionClick(reply.cid)}>Edit post</li>
<li onClick={() => handleOptionClick(reply.cid)}>Delete post</li>
</>
) : null}
{isModerator ? (
<>
{reply.author.shortAddress === account.author.shortAddress ? (
null
) : (
<li onClick={() => {
setModeratingCommentCid(reply.cid)
setIsModerationOpen(true);
handleOptionClick(reply.cid);
setDeletePost(true);
}}>
Delete post
</li>
)}
<li
onMouseOver={() => {setIsModToolsOpen(true)}}
onMouseLeave={() => {setIsModToolsOpen(false)}}
onClick={() => {
setModeratingCommentCid(reply.cid)
setIsModerationOpen(true);
handleOptionClick(reply.cid);
}}>
Mod tools
</li>
</>
) : null}
{(replyMediaInfo && (
replyMediaInfo.type === 'image' ||
(replyMediaInfo.type === 'webpage' &&
replyMediaInfo.thumbnail))) ? (
<li
onMouseOver={() => {setIsImageSearchOpen(true)}}
onMouseLeave={() => {setIsImageSearchOpen(false)}}>
Image search »
<ul className="dropdown-menu"
style={{display: isImageSearchOpen ? 'block': 'none'}}>
<li>
<li onClick={() => handleOptionClick(reply.cid)}>
<a
href={`https://lens.google.com/uploadbyurl?url=${commentMediaInfo.url}`}
target="_blank" rel="noreferrer"
>Google</a>
</li>
<li>
<li onClick={() => handleOptionClick(reply.cid)}>
<a
href={`https://yandex.com/images/search?url=${commentMediaInfo.url}`}
target="_blank" rel="noreferrer"
>Yandex</a>
</li>
<li>
<li onClick={() => handleOptionClick(reply.cid)}>
<a
href={`https://saucenao.com/search.php?url=${commentMediaInfo.url}`}
target="_blank" rel="noreferrer"
@@ -993,25 +949,10 @@ const Thread = () => {
</li>
</ul>
</li>
) : null
}
{isModerator ? (
<li
onMouseOver={() => {setIsModToolsOpen(true)}}
onMouseLeave={() => {setIsModToolsOpen(false)}}>
Mod tools »
<ul className="dropdown-menu"
style={{display: isModToolsOpen ? 'block': 'none'}}>
<li onClick={() => handleModToolClick(
'Delete', reply.cid
)}>
Delete
</li>
</ul>
</li>
) : null}
</ul>
</div>
) : null
}
</ul>
</div>
<div id="backlink-id" className="backlink">
{reply.replies?.pages?.topAll.comments
.sort((a, b) => a.timestamp - b.timestamp)