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
+19 -7
View File
@@ -8,7 +8,7 @@ import useError from "../hooks/useError";
import useSuccess from "../hooks/useSuccess";
const ModerationModal = ({ isOpen, closeModal }) => {
const ModerationModal = ({ isOpen, closeModal, deletePost }) => {
const {
selectedAddress,
selectedStyle,
@@ -20,7 +20,7 @@ const ModerationModal = ({ isOpen, closeModal }) => {
} = useGeneralStore(state => state);
const [pin, setPin] = useState(false);
const [deleteThread, setDeleteThread] = useState(false);
const [deleteThread, setDeleteThread] = useState(deletePost);
const [close, setClose] = useState(false);
const [reason, setReason] = useState('');
const [triggerPublishCommentEdit, setTriggerPublishCommentEdit] = useState(false);
@@ -30,7 +30,19 @@ const ModerationModal = ({ isOpen, closeModal }) => {
useError(errorMessage, [errorMessage]);
useSuccess(successMessage, [successMessage]);
useEffect(() => {
setDeleteThread(deletePost);
}, [deletePost]);
useEffect(() => {
if (!isOpen) {
setDeleteThread(deletePost);
}
}, [isOpen, deletePost]);
const handleCloseModal = () => {
setDeleteThread(false);
closeModal();
};
@@ -155,11 +167,11 @@ const ModerationModal = ({ isOpen, closeModal }) => {
<label>
<input type="checkbox" style={{marginRight: "10px"}}
checked={pin} onChange={() => setPin(!pin)} />
Pin thread
Pin post
</label>
</li>
<li className="settings-tip">
Pin the thread to make it a sticky, showed at the top of the board even as new posts are submitted.
Pin the post to make it a sticky, showed at the top of the board even as new posts are submitted.
</li>
</ul>
<ul className="settings-cat">
@@ -167,7 +179,7 @@ const ModerationModal = ({ isOpen, closeModal }) => {
<label>
<input type="checkbox" style={{marginRight: "10px"}}
checked={deleteThread} onChange={() => setDeleteThread(!deleteThread)} />
Delete thread
Delete post
</label>
</li>
<li className="settings-tip">
@@ -179,11 +191,11 @@ const ModerationModal = ({ isOpen, closeModal }) => {
<label>
<input type="checkbox" style={{marginRight: "10px"}}
checked={close} onChange={() => setClose(!close)} />
Close thread
Close post
</label>
</li>
<li className="settings-tip">
Closing a thread allows users to still see the content, but they cannot add any new replies to it.
Closing a post allows users to still see the content, but they cannot add any new replies to it.
</li>
</ul>
<ul className="settings-cat">
+82 -141
View File
@@ -3,7 +3,7 @@ import { Helmet } from 'react-helmet-async';
import { Link, useNavigate, useParams } from 'react-router-dom';
import { Tooltip } from 'react-tooltip';
import { Virtuoso } from 'react-virtuoso';
import { useAccount, useAccountComments, useFeed, usePublishComment, usePublishCommentEdit, useSubplebbit, useSubscribe } from '@plebbit/plebbit-react-hooks';
import { useAccount, useAccountComments, useFeed, usePublishComment, useSubplebbit, useSubscribe } 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';
@@ -73,13 +73,12 @@ const Board = () => {
const [prevScrollPos, setPrevScrollPos] = useState(0);
const [visible, setVisible] = useState(true);
const [triggerPublishComment, setTriggerPublishComment] = useState(false);
const [triggerPublishCommentEdit, setTriggerPublishCommentEdit] = useState(false);
const [selectedFeed, setSelectedFeed] = useState(feed);
const [deletePost, setDeletePost] = useState(false);
const [rotatedStates, setRotatedStates] = useState({});
const [isImageSearchOpen, setIsImageSearchOpen] = useState(false);
const [isModerator, setIsModerator] = useState(false);
const [isModToolsOpen, setIsModToolsOpen] = useState(false);
const [commentCid, setCommentCid] = useState(null);
const [errorMessage, setErrorMessage] = useState(null);
const [successMessage, setSuccessMessage] = useState(null);
@@ -361,76 +360,6 @@ const Board = () => {
};
});
};
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]);
// desktop navbar board select functionality
@@ -493,7 +422,8 @@ const Board = () => {
<ModerationModal
selectedStyle={selectedStyle}
isOpen={isModerationOpen}
closeModal={() => setIsModerationOpen(false)} />
closeModal={() => setIsModerationOpen(false)}
deletePost={deletePost} />
<NavBar selectedStyle={selectedStyle}>
<>
<span className="boardList">
@@ -828,8 +758,39 @@ const Board = () => {
<div id="post-menu" className={`post-menu-thread post-menu-thread-${thread.cid}`}
style={{ display: rotatedStates[thread.cid] ? 'block' : 'none' }}>
<ul>
{/* <li onClick={() => handleOptionClick(thread.cid)}>Edit post</li> */}
<li onClick={() => handleOptionClick(thread.cid)}>Hide thread</li>
{thread.author.shortAddress === account.author.shortAddress ? (
<>
<li onClick={() => handleOptionClick(thread.cid)}>Edit post</li>
<li onClick={() => handleOptionClick(thread.cid)}>Delete post</li>
</>
) : null}
{isModerator ? (
<>
{thread.author.shortAddress === account.author.shortAddress ? (
null
) : (
<li onClick={() => {
setModeratingCommentCid(thread.cid)
setIsModerationOpen(true);
handleOptionClick(thread.cid);
setDeletePost(true);
}}>
Delete post
</li>
)}
<li
onMouseOver={() => {setIsModToolsOpen(true)}}
onMouseLeave={() => {setIsModToolsOpen(false)}}
onClick={() => {
setModeratingCommentCid(thread.cid)
setIsModerationOpen(true);
handleOptionClick(thread.cid);
}}>
Mod tools
</li>
</>
) : null}
{(commentMediaInfo && (
commentMediaInfo.type === 'image' ||
(commentMediaInfo.type === 'webpage' &&
@@ -862,42 +823,6 @@ const Board = () => {
</li>
) : null
}
{isModerator ? (
<li
onMouseOver={() => {setIsModToolsOpen(true)}}
onMouseLeave={() => {setIsModToolsOpen(false)}}>
Mod tools »
<ul className="dropdown-menu"
style={{display: isModToolsOpen ? 'block': 'none'}}>
<li onClick={() => {
setModeratingCommentCid(thread.cid);
setIsModerationOpen(true);
handleOptionClick(thread.cid);
}}>
Open tools
</li>
<li onClick={() => handleModToolClick(
thread.pinned ? 'Unpin' : 'Pin',
thread.cid,
{ pinned: thread.pinned, locked: thread.locked }
)}>
{thread.pinned ? 'Unpin' : 'Pin'}
</li>
<li onClick={() => handleModToolClick(
thread.locked ? 'Reopen' : 'Close',
thread.cid,
{ pinned: thread.pinned, locked: thread.locked }
)}>
{thread.locked ? 'Reopen' : 'Close'}
</li>
<li onClick={() => handleModToolClick(
'Delete', thread.cid
)}>
Delete
</li>
</ul>
</li>
) : null}
</ul>
</div>
<div key={`bi-${index}`} id="backlink-id" className="backlink">
@@ -1031,15 +956,46 @@ const Board = () => {
>
</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 onClick={() => handleOptionClick(reply.cid)}>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)}}>
@@ -1048,43 +1004,28 @@ const Board = () => {
style={{display: isImageSearchOpen ? 'block': 'none'}}>
<li onClick={() => handleOptionClick(reply.cid)}>
<a
href={`https://lens.google.com/uploadbyurl?url=${commentMediaInfo?.url}`}
href={`https://lens.google.com/uploadbyurl?url=${commentMediaInfo.url}`}
target="_blank" rel="noreferrer"
>Google</a>
</li>
<li onClick={() => handleOptionClick(reply.cid)}>
<a
href={`https://yandex.com/images/search?url=${commentMediaInfo?.url}`}
href={`https://yandex.com/images/search?url=${commentMediaInfo.url}`}
target="_blank" rel="noreferrer"
>Yandex</a>
</li>
<li onClick={() => handleOptionClick(reply.cid)}>
<a
href={`https://saucenao.com/search.php?url=${commentMediaInfo?.url}`}
href={`https://saucenao.com/search.php?url=${commentMediaInfo.url}`}
target="_blank" rel="noreferrer"
>SauceNAO</a>
</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)
+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)