mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
implement virtuoso in catalog views
This commit is contained in:
+348
-349
@@ -5,7 +5,7 @@ import { Link, useNavigate} from 'react-router-dom';
|
|||||||
import { confirmAlert } from 'react-confirm-alert';
|
import { confirmAlert } from 'react-confirm-alert';
|
||||||
import { Tooltip } from 'react-tooltip';
|
import { Tooltip } from 'react-tooltip';
|
||||||
import { Virtuoso } from 'react-virtuoso';
|
import { Virtuoso } from 'react-virtuoso';
|
||||||
import { useAccount, useFeed, usePublishCommentEdit, useSubplebbits } from '@plebbit/plebbit-react-hooks';
|
import { useAccount, useFeed, usePublishCommentEdit, useSubplebbit, useSubplebbits } from '@plebbit/plebbit-react-hooks';
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
import { Container, NavBar, Header, Break, PostMenu, BoardForm } from '../styled/views/Board.styled';
|
import { Container, NavBar, Header, Break, PostMenu, BoardForm } from '../styled/views/Board.styled';
|
||||||
import { Threads, PostMenuCatalog } from '../styled/views/Catalog.styled';
|
import { Threads, PostMenuCatalog } from '../styled/views/Catalog.styled';
|
||||||
@@ -32,103 +32,130 @@ const {version} = packageJson
|
|||||||
let lastVirtuosoStates = {}
|
let lastVirtuosoStates = {}
|
||||||
|
|
||||||
|
|
||||||
const AllCatalog = () => {
|
const CatalogPost = ({post}) => {
|
||||||
const {
|
const {
|
||||||
setCaptchaResponse,
|
|
||||||
setChallengesArray,
|
|
||||||
defaultSubplebbits,
|
|
||||||
editedComment,
|
editedComment,
|
||||||
|
setDeletePost,
|
||||||
setIsAuthorDelete,
|
setIsAuthorDelete,
|
||||||
|
captchaResponse, setCaptchaResponse,
|
||||||
|
setIsModerationOpen,
|
||||||
|
setChallengesArray,
|
||||||
setIsAuthorEdit,
|
setIsAuthorEdit,
|
||||||
setIsCaptchaOpen,
|
setIsCaptchaOpen,
|
||||||
isModerationOpen, setIsModerationOpen,
|
setIsEditModalOpen,
|
||||||
isSettingsOpen, setIsSettingsOpen,
|
|
||||||
setModeratingCommentCid,
|
setModeratingCommentCid,
|
||||||
|
setOriginalCommentContent,
|
||||||
|
setPendingComment,
|
||||||
setResolveCaptchaPromise,
|
setResolveCaptchaPromise,
|
||||||
selectedAddress, setSelectedAddress,
|
selectedAddress, setSelectedAddress,
|
||||||
selectedStyle,
|
selectedStyle,
|
||||||
setSelectedThread,
|
setSelectedThread,
|
||||||
setSelectedTitle,
|
|
||||||
} = useGeneralStore(state => state);
|
} = useGeneralStore(state => state);
|
||||||
|
|
||||||
|
|
||||||
|
const thread = post;
|
||||||
|
const commentMediaInfo = getCommentMediaInfo(thread);
|
||||||
|
const linkCount = countLinks(thread);
|
||||||
|
const fallbackImgUrl = "assets/filedeleted-res.gif";
|
||||||
|
const [isHoveringOnThread, setIsHoveringOnThread] = useState(false);
|
||||||
|
const [menuPosition, setMenuPosition] = useState({top: 0, left: 0});
|
||||||
|
const [openMenuCid, setOpenMenuCid] = useState(null);
|
||||||
|
const [triggerPublishCommentEdit, setTriggerPublishCommentEdit] = useState(false);
|
||||||
|
const [isImageSearchOpen, setIsImageSearchOpen] = useState(false);
|
||||||
|
const [commentCid, setCommentCid] = useState(null);
|
||||||
|
const [isModerator, setIsModerator] = useState(false);
|
||||||
|
|
||||||
|
const [, setNewErrorMessage] = useError();
|
||||||
|
const [, setNewSuccessMessage] = useSuccess();
|
||||||
|
|
||||||
|
const account = useAccount();
|
||||||
|
const subplebbit = useSubplebbit({subplebbitAddress: thread.subplebbitAddress});
|
||||||
const threadMenuRefs = useRef({});
|
const threadMenuRefs = useRef({});
|
||||||
const postMenuRef = useRef(null);
|
const postMenuRef = useRef(null);
|
||||||
const postMenuCatalogRef = useRef(null);
|
const postMenuCatalogRef = useRef(null);
|
||||||
const virtuosoRef = useRef();
|
|
||||||
|
|
||||||
const account = useAccount();
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const [, setNewErrorMessage] = useError();
|
|
||||||
const [, setNewSuccessMessage] = useSuccess();
|
|
||||||
|
|
||||||
const [prevScrollPos, setPrevScrollPos] = useState(0);
|
|
||||||
const [visible, setVisible] = useState(true);
|
|
||||||
|
|
||||||
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
|
|
||||||
const [originalCommentContent, setOriginalCommentContent] = useState(null);
|
|
||||||
const [triggerPublishCommentEdit, setTriggerPublishCommentEdit] = useState(false);
|
|
||||||
const [deletePost, setDeletePost] = useState(false);
|
|
||||||
const [isImageSearchOpen, setIsImageSearchOpen] = useState(false);
|
|
||||||
const [commentCid, setCommentCid] = useState(null);
|
|
||||||
const [moderatorPermissions, setModeratorPermissions] = useState({});
|
|
||||||
const [isCreateBoardOpen, setIsCreateBoardOpen] = useState(false);
|
|
||||||
|
|
||||||
const addresses = defaultSubplebbits.map(subplebbit => subplebbit.address);
|
|
||||||
const { feed, hasMore, loadMore } = useFeed({subplebbitAddresses: addresses, sortType: 'active'});
|
|
||||||
const {subplebbits} = useSubplebbits({subplebbitAddresses: addresses, sortType: 'active'});
|
|
||||||
const [selectedFeed, setSelectedFeed] = useState(feed.sort((a, b) => b.timestamp - a.timestamp));
|
|
||||||
|
|
||||||
const stateString = useFeedStateString(subplebbits);
|
|
||||||
|
|
||||||
const columnWidth = 180;
|
|
||||||
const windowWidth = useWindowWidth();
|
|
||||||
const columnCount = Math.floor(windowWidth / columnWidth);
|
|
||||||
const rows = useFeedRows(selectedFeed, columnCount);
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let permissions = {};
|
if (subplebbit.roles !== undefined) {
|
||||||
|
const role = subplebbit.roles[account?.author.address]?.role;
|
||||||
|
|
||||||
selectedFeed.forEach(thread => {
|
if (role === 'moderator' || role === 'admin' || role === 'owner') {
|
||||||
const subplebbit = subplebbits.find(s => s && s.address === thread.subplebbitAddress);
|
setIsModerator(true);
|
||||||
|
} else {
|
||||||
if (subplebbit && subplebbit.roles) {
|
setIsModerator(false);
|
||||||
const role = subplebbit.roles[account?.author.address]?.role;
|
}
|
||||||
|
}
|
||||||
|
}, [account?.author.address, subplebbit.roles]);
|
||||||
|
|
||||||
|
|
||||||
|
const handleOutsideClick = useCallback((e) => {
|
||||||
|
if (openMenuCid !== null && !postMenuRef.current.contains(e.target) && !postMenuCatalogRef.current.contains(e.target)) {
|
||||||
|
setOpenMenuCid(null);
|
||||||
|
}
|
||||||
|
}, [openMenuCid]);
|
||||||
|
|
||||||
|
const handleOptionClick = () => {
|
||||||
|
setOpenMenuCid(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (openMenuCid !== null) {
|
||||||
|
document.addEventListener('click', handleOutsideClick);
|
||||||
|
} else {
|
||||||
|
document.removeEventListener('click', handleOutsideClick);
|
||||||
|
}
|
||||||
|
|
||||||
if (role === 'moderator' || role === 'admin' || role === 'owner') {
|
return () => {
|
||||||
permissions[thread.subplebbitAddress] = true;
|
document.removeEventListener('click', handleOutsideClick);
|
||||||
} else {
|
};
|
||||||
permissions[thread.subplebbitAddress] = false;
|
}, [openMenuCid, handleOutsideClick]);
|
||||||
}
|
|
||||||
|
const handleAuthorDeleteClick = (comment) => {
|
||||||
|
handleOptionClick(comment.cid);
|
||||||
|
|
||||||
|
confirmAlert({
|
||||||
|
customUI: ({ onClose }) => {
|
||||||
|
return (
|
||||||
|
<AuthorDeleteAlert selectedStyle={selectedStyle}>
|
||||||
|
<div className='author-delete-alert'>
|
||||||
|
<p>Are you sure you want to delete this post?</p>
|
||||||
|
<div className="author-delete-buttons">
|
||||||
|
<button onClick={onClose}>No</button>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
setIsAuthorDelete(true);
|
||||||
|
setIsAuthorEdit(false);
|
||||||
|
setPublishCommentEditOptions(prevOptions => ({
|
||||||
|
...prevOptions,
|
||||||
|
commentCid: comment.cid,
|
||||||
|
subplebbitAddress: comment.subplebbitAddress,
|
||||||
|
deleted: true,
|
||||||
|
}));
|
||||||
|
setTriggerPublishCommentEdit(true);
|
||||||
|
onClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Yes
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</AuthorDeleteAlert>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setModeratorPermissions(permissions);
|
|
||||||
}, [account?.author.address, selectedFeed, subplebbits]);
|
|
||||||
|
|
||||||
|
|
||||||
// mobile navbar scroll effect
|
|
||||||
useEffect(() => {
|
|
||||||
const debouncedHandleScroll = debounce(() => {
|
|
||||||
const currentScrollPos = window.pageYOffset;
|
|
||||||
setVisible(prevScrollPos > currentScrollPos || currentScrollPos < 10);
|
|
||||||
setPrevScrollPos(currentScrollPos);
|
|
||||||
}, 50);
|
|
||||||
|
|
||||||
window.addEventListener('scroll', debouncedHandleScroll);
|
|
||||||
|
|
||||||
return () => window.removeEventListener('scroll', debouncedHandleScroll);
|
|
||||||
}, [prevScrollPos, visible]);
|
|
||||||
|
|
||||||
|
|
||||||
const tryLoadMore = async () => {
|
|
||||||
try {loadMore()}
|
|
||||||
catch (e)
|
|
||||||
{await new Promise(resolve => setTimeout(resolve, 1000))}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const handleAuthorEditClick = (comment) => {
|
||||||
|
handleOptionClick(comment.cid);
|
||||||
|
setIsAuthorEdit(true);
|
||||||
|
setIsAuthorDelete(false);
|
||||||
|
setCommentCid(comment.cid);
|
||||||
|
setOriginalCommentContent(comment.content);
|
||||||
|
setIsEditModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const onChallengeVerification = (challengeVerification) => {
|
const onChallengeVerification = (challengeVerification) => {
|
||||||
if (challengeVerification.challengeSuccess === true) {
|
if (challengeVerification.challengeSuccess === true) {
|
||||||
setNewSuccessMessage('Challenge Success');
|
setNewSuccessMessage('Challenge Success');
|
||||||
@@ -141,6 +168,7 @@ const AllCatalog = () => {
|
|||||||
|
|
||||||
|
|
||||||
const onChallenge = async (challenges, comment) => {
|
const onChallenge = async (challenges, comment) => {
|
||||||
|
setPendingComment(comment);
|
||||||
let challengeAnswers = [];
|
let challengeAnswers = [];
|
||||||
try {
|
try {
|
||||||
challengeAnswers = await getChallengeAnswersFromUser(challenges)
|
challengeAnswers = await getChallengeAnswersFromUser(challenges)
|
||||||
@@ -168,7 +196,7 @@ const AllCatalog = () => {
|
|||||||
|
|
||||||
const handleKeyDown = async (event) => {
|
const handleKeyDown = async (event) => {
|
||||||
if (event.key === 'Enter') {
|
if (event.key === 'Enter') {
|
||||||
const currentCaptchaResponse = useGeneralStore.getState().captchaResponse;
|
const currentCaptchaResponse = captchaResponse;
|
||||||
resolve(currentCaptchaResponse);
|
resolve(currentCaptchaResponse);
|
||||||
setIsCaptchaOpen(false);
|
setIsCaptchaOpen(false);
|
||||||
document.removeEventListener('keydown', handleKeyDown);
|
document.removeEventListener('keydown', handleKeyDown);
|
||||||
@@ -202,7 +230,7 @@ const AllCatalog = () => {
|
|||||||
|
|
||||||
const { publishCommentEdit } = usePublishCommentEdit(publishCommentEditOptions);
|
const { publishCommentEdit } = usePublishCommentEdit(publishCommentEditOptions);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPublishCommentEditOptions((prevOptions) => ({
|
setPublishCommentEditOptions((prevOptions) => ({
|
||||||
...prevOptions,
|
...prevOptions,
|
||||||
@@ -236,6 +264,250 @@ const AllCatalog = () => {
|
|||||||
}, [triggerPublishCommentEdit, publishCommentEdit, publishCommentEditOptions]);
|
}, [triggerPublishCommentEdit, publishCommentEdit, publishCommentEditOptions]);
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div key={`thread-`} className="thread"
|
||||||
|
onMouseOver={() => {setIsHoveringOnThread(thread.cid)}}
|
||||||
|
onMouseLeave={() => {setIsHoveringOnThread('')}}>
|
||||||
|
{commentMediaInfo?.url ? (
|
||||||
|
<Link style={{all: "unset", cursor: "pointer"}} key={`link-`} to={`/p/${thread.subplebbitAddress}/c/${thread.cid}`}
|
||||||
|
onClick={() => setSelectedThread(thread.cid)}>
|
||||||
|
{commentMediaInfo?.type === "webpage" ? (
|
||||||
|
thread.thumbnailUrl ? (
|
||||||
|
<img className="card" key={`img-`}
|
||||||
|
src={commentMediaInfo.thumbnail} alt={commentMediaInfo.type}
|
||||||
|
onError={(e) => {
|
||||||
|
e.target.src = fallbackImgUrl
|
||||||
|
e.target.onerror = null;
|
||||||
|
}} />
|
||||||
|
) : null
|
||||||
|
) : null}
|
||||||
|
{commentMediaInfo?.type === "image" ? (
|
||||||
|
<img className="card" key={`img-`}
|
||||||
|
src={commentMediaInfo.url} alt={commentMediaInfo.type}
|
||||||
|
onError={(e) => {
|
||||||
|
e.target.src = fallbackImgUrl
|
||||||
|
e.target.onerror = null;}} />
|
||||||
|
) : null}
|
||||||
|
{commentMediaInfo?.type === "video" ? (
|
||||||
|
<video className="card" key={`fti-`}
|
||||||
|
src={commentMediaInfo.url}
|
||||||
|
alt={commentMediaInfo.type}
|
||||||
|
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||||
|
) : null}
|
||||||
|
{commentMediaInfo?.type === "audio" ? (
|
||||||
|
<audio className="card" controls
|
||||||
|
key={`fti-`}
|
||||||
|
src={commentMediaInfo.url}
|
||||||
|
alt={commentMediaInfo.type}
|
||||||
|
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||||
|
) : null}
|
||||||
|
</Link>
|
||||||
|
) : null}
|
||||||
|
<div key={`ti-`} className="thread-icons" >
|
||||||
|
{(commentMediaInfo && (
|
||||||
|
commentMediaInfo.type === 'image' ||
|
||||||
|
commentMediaInfo.type === 'video' ||
|
||||||
|
(commentMediaInfo.type === 'webpage' &&
|
||||||
|
commentMediaInfo.thumbnail))) ? (
|
||||||
|
<OfflineIndicator
|
||||||
|
address={thread.subplebbitAddress}
|
||||||
|
className="thread-icon offline-icon"
|
||||||
|
tooltipPlace="top" />
|
||||||
|
) : (
|
||||||
|
<OfflineIndicator
|
||||||
|
address={thread.subplebbitAddress}
|
||||||
|
className="thread-icon offline-icon-no-link"
|
||||||
|
tooltipPlace="top" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<BoardForm selectedStyle={selectedStyle}
|
||||||
|
style={{ all: "unset"}}>
|
||||||
|
<div key={`meta-`} className="meta" title="(R)eplies / (L)ink Replies" >
|
||||||
|
R: <b key={`b-`}>{thread.replyCount}</b>
|
||||||
|
{linkCount > 0 ? (
|
||||||
|
<>
|
||||||
|
/
|
||||||
|
L: <b key={`i-`}>{linkCount}</b>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
<PostMenu
|
||||||
|
style={{ display: isHoveringOnThread === thread.cid ? 'inline-block' : 'none',
|
||||||
|
position: 'absolute', lineHeight: '1em', marginTop: '-1px', outline: 'none',
|
||||||
|
zIndex: '999'}}
|
||||||
|
key={`pmb-`}
|
||||||
|
title="Post menu"
|
||||||
|
ref={el => {
|
||||||
|
threadMenuRefs.current[thread.cid] = el;
|
||||||
|
postMenuRef.current = el;
|
||||||
|
}}
|
||||||
|
className='post-menu-button'
|
||||||
|
id='post-menu-button-catalog'
|
||||||
|
rotated={openMenuCid === thread.cid}
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
const rect = threadMenuRefs.current[thread.cid].getBoundingClientRect();
|
||||||
|
setMenuPosition({top: rect.top + window.scrollY, left: rect.left});
|
||||||
|
setOpenMenuCid(prevCid => (prevCid === thread.cid ? null : thread.cid));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
▶
|
||||||
|
</PostMenu>
|
||||||
|
</div>
|
||||||
|
{createPortal(
|
||||||
|
<PostMenuCatalog selectedStyle={selectedStyle}
|
||||||
|
ref={el => {postMenuCatalogRef.current = el}}
|
||||||
|
onClick={(event) => event.stopPropagation()}
|
||||||
|
style={{position: "absolute",
|
||||||
|
top: menuPosition.top + 7,
|
||||||
|
left: menuPosition.left}}>
|
||||||
|
<div className={`post-menu-thread post-menu-thread-${thread.cid}`}
|
||||||
|
style={{ display: openMenuCid === thread.cid ? 'block' : 'none' }}
|
||||||
|
>
|
||||||
|
<ul className="post-menu-catalog">
|
||||||
|
<li onClick={() => handleOptionClick(thread.cid)}>Hide thread</li>
|
||||||
|
<VerifiedAuthor commentCid={thread.cid}>{({ authorAddress }) => (
|
||||||
|
<>
|
||||||
|
{authorAddress === account?.author.address ||
|
||||||
|
authorAddress === account?.signer.address ? (
|
||||||
|
<>
|
||||||
|
<li onClick={() => handleAuthorEditClick(thread)}>Edit post</li>
|
||||||
|
<li onClick={() => handleAuthorDeleteClick(thread)}>Delete post</li>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
{isModerator ? (
|
||||||
|
<>
|
||||||
|
{authorAddress === account?.author.address ||
|
||||||
|
authorAddress === account?.signer.address ? (
|
||||||
|
null
|
||||||
|
) : (
|
||||||
|
<li onClick={() => {
|
||||||
|
setSelectedAddress(thread.subplebbitAddress);
|
||||||
|
setModeratingCommentCid(thread.cid)
|
||||||
|
setIsModerationOpen(true);
|
||||||
|
handleOptionClick(thread.cid);
|
||||||
|
setDeletePost(true);
|
||||||
|
}}>
|
||||||
|
Delete post
|
||||||
|
</li>
|
||||||
|
)}
|
||||||
|
<li
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedAddress(thread.subplebbitAddress);
|
||||||
|
setModeratingCommentCid(thread.cid)
|
||||||
|
setIsModerationOpen(true);
|
||||||
|
handleOptionClick(thread.cid);
|
||||||
|
}}>
|
||||||
|
Mod tools
|
||||||
|
</li>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
)}</VerifiedAuthor>
|
||||||
|
{(commentMediaInfo && (
|
||||||
|
commentMediaInfo.type === 'image' ||
|
||||||
|
(commentMediaInfo.type === 'webpage' &&
|
||||||
|
commentMediaInfo.thumbnail))) ? (
|
||||||
|
<li
|
||||||
|
onMouseOver={() => {setIsImageSearchOpen(true)}}
|
||||||
|
onMouseLeave={() => {setIsImageSearchOpen(false)}}>
|
||||||
|
Image search »
|
||||||
|
<ul className="dropdown-menu post-menu-catalog"
|
||||||
|
style={{display: isImageSearchOpen ? 'block': 'none'}}>
|
||||||
|
<li onClick={() => handleOptionClick(thread.cid)}>
|
||||||
|
<a
|
||||||
|
href={`https://lens.google.com/uploadbyurl?url=${commentMediaInfo.url}`}
|
||||||
|
target="_blank" rel="noreferrer"
|
||||||
|
>Google</a>
|
||||||
|
</li>
|
||||||
|
<li onClick={() => handleOptionClick(thread.cid)}>
|
||||||
|
<a
|
||||||
|
href={`https://yandex.com/images/search?url=${commentMediaInfo.url}`}
|
||||||
|
target="_blank" rel="noreferrer"
|
||||||
|
>Yandex</a>
|
||||||
|
</li>
|
||||||
|
<li onClick={() => handleOptionClick(thread.cid)}>
|
||||||
|
<a
|
||||||
|
href={`https://saucenao.com/search.php?url=${commentMediaInfo.url}`}
|
||||||
|
target="_blank" rel="noreferrer"
|
||||||
|
>SauceNAO</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</PostMenuCatalog>, document.body
|
||||||
|
)}
|
||||||
|
</BoardForm>
|
||||||
|
<Link style={{all: "unset", cursor: "pointer"}} key={`link2-`} to={`/p/${thread.subplebbitAddress}/c/${thread.cid}`}
|
||||||
|
onClick={() => setSelectedThread(thread.cid)}>
|
||||||
|
<div key={`t-`} className="teaser">
|
||||||
|
<b key={`b2-`}>{thread.title ? `${thread.title}` : null}</b>
|
||||||
|
{thread.content ? `: ${thread.content}` : null}
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const CatalogRow = ({row}) => {
|
||||||
|
const posts = []
|
||||||
|
for (const post of row) {
|
||||||
|
posts.push(<CatalogPost key={post?.cid} post={post} />)
|
||||||
|
}
|
||||||
|
return <div>{posts}</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const AllCatalog = () => {
|
||||||
|
const {
|
||||||
|
defaultSubplebbits,
|
||||||
|
isModerationOpen, setIsModerationOpen,
|
||||||
|
isSettingsOpen, setIsSettingsOpen,
|
||||||
|
originalCommentContent,
|
||||||
|
selectedAddress, setSelectedAddress,
|
||||||
|
selectedStyle,
|
||||||
|
setSelectedTitle,
|
||||||
|
} = useGeneralStore(state => state);
|
||||||
|
|
||||||
|
const virtuosoRef = useRef();
|
||||||
|
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const [prevScrollPos, setPrevScrollPos] = useState(0);
|
||||||
|
const [visible, setVisible] = useState(true);
|
||||||
|
|
||||||
|
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
|
||||||
|
const [deletePost, setDeletePost] = useState(false);
|
||||||
|
const [isCreateBoardOpen, setIsCreateBoardOpen] = useState(false);
|
||||||
|
|
||||||
|
const addresses = defaultSubplebbits.map(subplebbit => subplebbit.address);
|
||||||
|
const { feed, hasMore, loadMore } = useFeed({subplebbitAddresses: addresses, sortType: 'active'});
|
||||||
|
const {subplebbits} = useSubplebbits({subplebbitAddresses: addresses, sortType: 'active'});
|
||||||
|
const [selectedFeed, setSelectedFeed] = useState(feed.sort((a, b) => b.timestamp - a.timestamp));
|
||||||
|
|
||||||
|
const stateString = useFeedStateString(subplebbits);
|
||||||
|
|
||||||
|
const columnWidth = 180;
|
||||||
|
const windowWidth = useWindowWidth();
|
||||||
|
const columnCount = Math.floor(windowWidth / columnWidth);
|
||||||
|
const rows = useFeedRows(selectedFeed, columnCount);
|
||||||
|
|
||||||
|
// mobile navbar scroll effect
|
||||||
|
useEffect(() => {
|
||||||
|
const debouncedHandleScroll = debounce(() => {
|
||||||
|
const currentScrollPos = window.pageYOffset;
|
||||||
|
setVisible(prevScrollPos > currentScrollPos || currentScrollPos < 10);
|
||||||
|
setPrevScrollPos(currentScrollPos);
|
||||||
|
}, 50);
|
||||||
|
|
||||||
|
window.addEventListener('scroll', debouncedHandleScroll);
|
||||||
|
|
||||||
|
return () => window.removeEventListener('scroll', debouncedHandleScroll);
|
||||||
|
}, [prevScrollPos, visible]);
|
||||||
|
|
||||||
// mobile navbar board select functionality
|
// mobile navbar board select functionality
|
||||||
const handleSelectChange = (event) => {
|
const handleSelectChange = (event) => {
|
||||||
const selected = event.target.value;
|
const selected = event.target.value;
|
||||||
@@ -262,279 +534,6 @@ const AllCatalog = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const CatalogPost = ({post}) => {
|
|
||||||
const thread = post;
|
|
||||||
const commentMediaInfo = getCommentMediaInfo(thread);
|
|
||||||
const linkCount = countLinks(thread);
|
|
||||||
const fallbackImgUrl = "assets/filedeleted-res.gif";
|
|
||||||
const [isHoveringOnThread, setIsHoveringOnThread] = useState(false);
|
|
||||||
const [menuPosition, setMenuPosition] = useState({top: 0, left: 0});
|
|
||||||
const [openMenuCid, setOpenMenuCid] = useState(null);
|
|
||||||
const isModerator = moderatorPermissions[thread.subplebbitAddress];
|
|
||||||
|
|
||||||
const handleOutsideClick = useCallback((e) => {
|
|
||||||
if (openMenuCid !== null && !postMenuRef.current.contains(e.target) && !postMenuCatalogRef.current.contains(e.target)) {
|
|
||||||
setOpenMenuCid(null);
|
|
||||||
}
|
|
||||||
}, [openMenuCid]);
|
|
||||||
|
|
||||||
const handleOptionClick = () => {
|
|
||||||
setOpenMenuCid(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (openMenuCid !== null) {
|
|
||||||
document.addEventListener('click', handleOutsideClick);
|
|
||||||
} else {
|
|
||||||
document.removeEventListener('click', handleOutsideClick);
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
document.removeEventListener('click', handleOutsideClick);
|
|
||||||
};
|
|
||||||
}, [openMenuCid, handleOutsideClick]);
|
|
||||||
|
|
||||||
const handleAuthorDeleteClick = (comment) => {
|
|
||||||
handleOptionClick(comment.cid);
|
|
||||||
|
|
||||||
confirmAlert({
|
|
||||||
customUI: ({ onClose }) => {
|
|
||||||
return (
|
|
||||||
<AuthorDeleteAlert selectedStyle={selectedStyle}>
|
|
||||||
<div className='author-delete-alert'>
|
|
||||||
<p>Are you sure you want to delete this post?</p>
|
|
||||||
<div className="author-delete-buttons">
|
|
||||||
<button onClick={onClose}>No</button>
|
|
||||||
<button
|
|
||||||
onClick={() => {
|
|
||||||
setIsAuthorDelete(true);
|
|
||||||
setIsAuthorEdit(false);
|
|
||||||
setPublishCommentEditOptions(prevOptions => ({
|
|
||||||
...prevOptions,
|
|
||||||
commentCid: comment.cid,
|
|
||||||
subplebbitAddress: comment.subplebbitAddress,
|
|
||||||
deleted: true,
|
|
||||||
}));
|
|
||||||
setTriggerPublishCommentEdit(true);
|
|
||||||
onClose();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Yes
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</AuthorDeleteAlert>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const handleAuthorEditClick = (comment) => {
|
|
||||||
handleOptionClick(comment.cid);
|
|
||||||
setIsAuthorEdit(true);
|
|
||||||
setIsAuthorDelete(false);
|
|
||||||
setCommentCid(comment.cid);
|
|
||||||
setOriginalCommentContent(comment.content);
|
|
||||||
setIsEditModalOpen(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div key={`thread-`} className="thread"
|
|
||||||
onMouseOver={() => {setIsHoveringOnThread(thread.cid)}}
|
|
||||||
onMouseLeave={() => {setIsHoveringOnThread('')}}>
|
|
||||||
{commentMediaInfo?.url ? (
|
|
||||||
<Link style={{all: "unset", cursor: "pointer"}} key={`link-`} to={`/p/${thread.subplebbitAddress}/c/${thread.cid}`}
|
|
||||||
onClick={() => setSelectedThread(thread.cid)}>
|
|
||||||
{commentMediaInfo?.type === "webpage" ? (
|
|
||||||
thread.thumbnailUrl ? (
|
|
||||||
<img className="card" key={`img-`}
|
|
||||||
src={commentMediaInfo.thumbnail} alt={commentMediaInfo.type}
|
|
||||||
onError={(e) => {
|
|
||||||
e.target.src = fallbackImgUrl
|
|
||||||
e.target.onerror = null;
|
|
||||||
}} />
|
|
||||||
) : null
|
|
||||||
) : null}
|
|
||||||
{commentMediaInfo?.type === "image" ? (
|
|
||||||
<img className="card" key={`img-`}
|
|
||||||
src={commentMediaInfo.url} alt={commentMediaInfo.type}
|
|
||||||
onError={(e) => {
|
|
||||||
e.target.src = fallbackImgUrl
|
|
||||||
e.target.onerror = null;}} />
|
|
||||||
) : null}
|
|
||||||
{commentMediaInfo?.type === "video" ? (
|
|
||||||
<video className="card" key={`fti-`}
|
|
||||||
src={commentMediaInfo.url}
|
|
||||||
alt={commentMediaInfo.type}
|
|
||||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
|
||||||
) : null}
|
|
||||||
{commentMediaInfo?.type === "audio" ? (
|
|
||||||
<audio className="card" controls
|
|
||||||
key={`fti-`}
|
|
||||||
src={commentMediaInfo.url}
|
|
||||||
alt={commentMediaInfo.type}
|
|
||||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
|
||||||
) : null}
|
|
||||||
</Link>
|
|
||||||
) : null}
|
|
||||||
<div key={`ti-`} className="thread-icons" >
|
|
||||||
{(commentMediaInfo && (
|
|
||||||
commentMediaInfo.type === 'image' ||
|
|
||||||
commentMediaInfo.type === 'video' ||
|
|
||||||
(commentMediaInfo.type === 'webpage' &&
|
|
||||||
commentMediaInfo.thumbnail))) ? (
|
|
||||||
<OfflineIndicator
|
|
||||||
address={thread.subplebbitAddress}
|
|
||||||
className="thread-icon offline-icon"
|
|
||||||
tooltipPlace="top" />
|
|
||||||
) : (
|
|
||||||
<OfflineIndicator
|
|
||||||
address={thread.subplebbitAddress}
|
|
||||||
className="thread-icon offline-icon-no-link"
|
|
||||||
tooltipPlace="top" />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<BoardForm selectedStyle={selectedStyle}
|
|
||||||
style={{ all: "unset"}}>
|
|
||||||
<div key={`meta-`} className="meta" title="(R)eplies / (L)ink Replies" >
|
|
||||||
R: <b key={`b-`}>{thread.replyCount}</b>
|
|
||||||
{linkCount > 0 ? (
|
|
||||||
<>
|
|
||||||
/
|
|
||||||
L: <b key={`i-`}>{linkCount}</b>
|
|
||||||
</>
|
|
||||||
) : null}
|
|
||||||
<PostMenu
|
|
||||||
style={{ display: isHoveringOnThread === thread.cid ? 'inline-block' : 'none',
|
|
||||||
position: 'absolute', lineHeight: '1em', marginTop: '-1px', outline: 'none',
|
|
||||||
zIndex: '999'}}
|
|
||||||
key={`pmb-`}
|
|
||||||
title="Post menu"
|
|
||||||
ref={el => {
|
|
||||||
threadMenuRefs.current[thread.cid] = el;
|
|
||||||
postMenuRef.current = el;
|
|
||||||
}}
|
|
||||||
className='post-menu-button'
|
|
||||||
id='post-menu-button-catalog'
|
|
||||||
rotated={openMenuCid === thread.cid}
|
|
||||||
onClick={(event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
const rect = threadMenuRefs.current[thread.cid].getBoundingClientRect();
|
|
||||||
setMenuPosition({top: rect.top + window.scrollY, left: rect.left});
|
|
||||||
setOpenMenuCid(prevCid => (prevCid === thread.cid ? null : thread.cid));
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
▶
|
|
||||||
</PostMenu>
|
|
||||||
</div>
|
|
||||||
{createPortal(
|
|
||||||
<PostMenuCatalog selectedStyle={selectedStyle}
|
|
||||||
ref={el => {postMenuCatalogRef.current = el}}
|
|
||||||
onClick={(event) => event.stopPropagation()}
|
|
||||||
style={{position: "absolute",
|
|
||||||
top: menuPosition.top + 7,
|
|
||||||
left: menuPosition.left}}>
|
|
||||||
<div className={`post-menu-thread post-menu-thread-${thread.cid}`}
|
|
||||||
style={{ display: openMenuCid === thread.cid ? 'block' : 'none' }}
|
|
||||||
>
|
|
||||||
<ul className="post-menu-catalog">
|
|
||||||
<li onClick={() => handleOptionClick(thread.cid)}>Hide thread</li>
|
|
||||||
<VerifiedAuthor commentCid={thread.cid}>{({ authorAddress }) => (
|
|
||||||
<>
|
|
||||||
{authorAddress === account?.author.address ||
|
|
||||||
authorAddress === account?.signer.address ? (
|
|
||||||
<>
|
|
||||||
<li onClick={() => handleAuthorEditClick(thread)}>Edit post</li>
|
|
||||||
<li onClick={() => handleAuthorDeleteClick(thread)}>Delete post</li>
|
|
||||||
</>
|
|
||||||
) : null}
|
|
||||||
{isModerator ? (
|
|
||||||
<>
|
|
||||||
{authorAddress === account?.author.address ||
|
|
||||||
authorAddress === account?.signer.address ? (
|
|
||||||
null
|
|
||||||
) : (
|
|
||||||
<li onClick={() => {
|
|
||||||
setSelectedAddress(thread.subplebbitAddress);
|
|
||||||
setModeratingCommentCid(thread.cid)
|
|
||||||
setIsModerationOpen(true);
|
|
||||||
handleOptionClick(thread.cid);
|
|
||||||
setDeletePost(true);
|
|
||||||
}}>
|
|
||||||
Delete post
|
|
||||||
</li>
|
|
||||||
)}
|
|
||||||
<li
|
|
||||||
onClick={() => {
|
|
||||||
setSelectedAddress(thread.subplebbitAddress);
|
|
||||||
setModeratingCommentCid(thread.cid)
|
|
||||||
setIsModerationOpen(true);
|
|
||||||
handleOptionClick(thread.cid);
|
|
||||||
}}>
|
|
||||||
Mod tools
|
|
||||||
</li>
|
|
||||||
</>
|
|
||||||
) : null}
|
|
||||||
</>
|
|
||||||
)}</VerifiedAuthor>
|
|
||||||
{(commentMediaInfo && (
|
|
||||||
commentMediaInfo.type === 'image' ||
|
|
||||||
(commentMediaInfo.type === 'webpage' &&
|
|
||||||
commentMediaInfo.thumbnail))) ? (
|
|
||||||
<li
|
|
||||||
onMouseOver={() => {setIsImageSearchOpen(true)}}
|
|
||||||
onMouseLeave={() => {setIsImageSearchOpen(false)}}>
|
|
||||||
Image search »
|
|
||||||
<ul className="dropdown-menu post-menu-catalog"
|
|
||||||
style={{display: isImageSearchOpen ? 'block': 'none'}}>
|
|
||||||
<li onClick={() => handleOptionClick(thread.cid)}>
|
|
||||||
<a
|
|
||||||
href={`https://lens.google.com/uploadbyurl?url=${commentMediaInfo.url}`}
|
|
||||||
target="_blank" rel="noreferrer"
|
|
||||||
>Google</a>
|
|
||||||
</li>
|
|
||||||
<li onClick={() => handleOptionClick(thread.cid)}>
|
|
||||||
<a
|
|
||||||
href={`https://yandex.com/images/search?url=${commentMediaInfo.url}`}
|
|
||||||
target="_blank" rel="noreferrer"
|
|
||||||
>Yandex</a>
|
|
||||||
</li>
|
|
||||||
<li onClick={() => handleOptionClick(thread.cid)}>
|
|
||||||
<a
|
|
||||||
href={`https://saucenao.com/search.php?url=${commentMediaInfo.url}`}
|
|
||||||
target="_blank" rel="noreferrer"
|
|
||||||
>SauceNAO</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
) : null
|
|
||||||
}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</PostMenuCatalog>, document.body
|
|
||||||
)}
|
|
||||||
</BoardForm>
|
|
||||||
<Link style={{all: "unset", cursor: "pointer"}} key={`link2-`} to={`/p/${thread.subplebbitAddress}/c/${thread.cid}`}
|
|
||||||
onClick={() => setSelectedThread(thread.cid)}>
|
|
||||||
<div key={`t-`} className="teaser">
|
|
||||||
<b key={`b2-`}>{thread.title ? `${thread.title}` : null}</b>
|
|
||||||
{thread.content ? `: ${thread.content}` : null}
|
|
||||||
</div>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const CatalogRow = ({row}) => {
|
|
||||||
const posts = []
|
|
||||||
for (const post of row) {
|
|
||||||
posts.push(<CatalogPost key={post?.cid} post={post} />)
|
|
||||||
}
|
|
||||||
return <div>{posts}</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const setLastVirtuosoState = () => {
|
const setLastVirtuosoState = () => {
|
||||||
virtuosoRef.current?.getState((snapshot) => {
|
virtuosoRef.current?.getState((snapshot) => {
|
||||||
@@ -702,7 +701,7 @@ const AllCatalog = () => {
|
|||||||
itemContent={(index, row) => <CatalogRow index={index} row={row} />}
|
itemContent={(index, row) => <CatalogRow index={index} row={row} />}
|
||||||
useWindowScroll={true}
|
useWindowScroll={true}
|
||||||
components={{ Footer: () => hasMore ? <CatalogLoader /> : null}}
|
components={{ Footer: () => hasMore ? <CatalogLoader /> : null}}
|
||||||
endReached={tryLoadMore}
|
endReached={loadMore}
|
||||||
ref={virtuosoRef}
|
ref={virtuosoRef}
|
||||||
restoreStateFrom={lastVirtuosoState}
|
restoreStateFrom={lastVirtuosoState}
|
||||||
initialScrollTop={lastVirtuosoState?.scrollTop}
|
initialScrollTop={lastVirtuosoState?.scrollTop}
|
||||||
|
|||||||
+630
-536
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@ import { Link, useNavigate} from 'react-router-dom';
|
|||||||
import { confirmAlert } from 'react-confirm-alert';
|
import { confirmAlert } from 'react-confirm-alert';
|
||||||
import { Tooltip } from 'react-tooltip';
|
import { Tooltip } from 'react-tooltip';
|
||||||
import { Virtuoso } from 'react-virtuoso';
|
import { Virtuoso } from 'react-virtuoso';
|
||||||
import { useAccount, useFeed, usePublishCommentEdit, useSubplebbits } from '@plebbit/plebbit-react-hooks';
|
import { useAccount, useFeed, usePublishCommentEdit, useSubplebbit, useSubplebbits } from '@plebbit/plebbit-react-hooks';
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
import { Container, NavBar, Header, Break, PostMenu, BoardForm } from '../styled/views/Board.styled';
|
import { Container, NavBar, Header, Break, PostMenu, BoardForm } from '../styled/views/Board.styled';
|
||||||
import { Threads, PostMenuCatalog } from '../styled/views/Catalog.styled';
|
import { Threads, PostMenuCatalog } from '../styled/views/Catalog.styled';
|
||||||
@@ -32,92 +32,128 @@ const {version} = packageJson
|
|||||||
let lastVirtuosoStates = {}
|
let lastVirtuosoStates = {}
|
||||||
|
|
||||||
|
|
||||||
const SubscriptionsCatalog = () => {
|
const CatalogPost = ({post}) => {
|
||||||
const {
|
const {
|
||||||
setCaptchaResponse,
|
|
||||||
setChallengesArray,
|
|
||||||
defaultSubplebbits,
|
|
||||||
editedComment,
|
editedComment,
|
||||||
|
setDeletePost,
|
||||||
setIsAuthorDelete,
|
setIsAuthorDelete,
|
||||||
|
captchaResponse, setCaptchaResponse,
|
||||||
|
setIsModerationOpen,
|
||||||
|
setChallengesArray,
|
||||||
setIsAuthorEdit,
|
setIsAuthorEdit,
|
||||||
setIsCaptchaOpen,
|
setIsCaptchaOpen,
|
||||||
isModerationOpen, setIsModerationOpen,
|
setIsEditModalOpen,
|
||||||
isSettingsOpen, setIsSettingsOpen,
|
|
||||||
setModeratingCommentCid,
|
setModeratingCommentCid,
|
||||||
|
setOriginalCommentContent,
|
||||||
|
setPendingComment,
|
||||||
setResolveCaptchaPromise,
|
setResolveCaptchaPromise,
|
||||||
selectedAddress, setSelectedAddress,
|
selectedAddress, setSelectedAddress,
|
||||||
selectedStyle,
|
selectedStyle,
|
||||||
setSelectedThread,
|
setSelectedThread,
|
||||||
setSelectedTitle,
|
|
||||||
} = useGeneralStore(state => state);
|
} = useGeneralStore(state => state);
|
||||||
|
|
||||||
const threadMenuRefs = useRef({});
|
const thread = post;
|
||||||
const postMenuRef = useRef(null);
|
const commentMediaInfo = getCommentMediaInfo(thread);
|
||||||
const postMenuCatalogRef = useRef(null);
|
const linkCount = countLinks(thread);
|
||||||
const virtuosoRef = useRef();
|
const fallbackImgUrl = "assets/filedeleted-res.gif";
|
||||||
|
const [isHoveringOnThread, setIsHoveringOnThread] = useState(false);
|
||||||
|
const [menuPosition, setMenuPosition] = useState({top: 0, left: 0});
|
||||||
|
const [openMenuCid, setOpenMenuCid] = useState(null);
|
||||||
|
const [triggerPublishCommentEdit, setTriggerPublishCommentEdit] = useState(false);
|
||||||
|
const [isImageSearchOpen, setIsImageSearchOpen] = useState(false);
|
||||||
|
const [commentCid, setCommentCid] = useState(null);
|
||||||
|
const [isModerator, setIsModerator] = useState(false);
|
||||||
|
|
||||||
const account = useAccount();
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const [, setNewErrorMessage] = useError();
|
const [, setNewErrorMessage] = useError();
|
||||||
const [, setNewSuccessMessage] = useSuccess();
|
const [, setNewSuccessMessage] = useSuccess();
|
||||||
|
|
||||||
const [prevScrollPos, setPrevScrollPos] = useState(0);
|
const account = useAccount();
|
||||||
const [visible, setVisible] = useState(true);
|
const subplebbit = useSubplebbit({subplebbitAddress: thread.subplebbitAddress});
|
||||||
|
const threadMenuRefs = useRef({});
|
||||||
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
|
const postMenuRef = useRef(null);
|
||||||
const [originalCommentContent, setOriginalCommentContent] = useState(null);
|
const postMenuCatalogRef = useRef(null);
|
||||||
const [triggerPublishCommentEdit, setTriggerPublishCommentEdit] = useState(false);
|
|
||||||
const [deletePost, setDeletePost] = useState(false);
|
|
||||||
const [isImageSearchOpen, setIsImageSearchOpen] = useState(false);
|
|
||||||
const [commentCid, setCommentCid] = useState(null);
|
|
||||||
const [moderatorPermissions, setModeratorPermissions] = useState({});
|
|
||||||
const [isCreateBoardOpen, setIsCreateBoardOpen] = useState(false);
|
|
||||||
|
|
||||||
const { feed, hasMore, loadMore } = useFeed({subplebbitAddresses: account?.subscriptions, sortType: 'active'});
|
|
||||||
const [selectedFeed, setSelectedFeed] = useState(feed.sort((a, b) => b.timestamp - a.timestamp));
|
|
||||||
const {subplebbits} = useSubplebbits({subplebbitAddresses: account?.subscriptions, sortType: 'active'});
|
|
||||||
|
|
||||||
const stateString = useFeedStateString(subplebbits);
|
|
||||||
|
|
||||||
const columnWidth = 180;
|
|
||||||
const windowWidth = useWindowWidth();
|
|
||||||
const columnCount = Math.floor(windowWidth / columnWidth);
|
|
||||||
const rows = useFeedRows(feed, columnCount);
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let permissions = {};
|
if (subplebbit.roles !== undefined) {
|
||||||
|
const role = subplebbit.roles[account?.author.address]?.role;
|
||||||
|
|
||||||
selectedFeed.forEach(thread => {
|
if (role === 'moderator' || role === 'admin' || role === 'owner') {
|
||||||
const subplebbit = subplebbits.find(s => s && s.address === thread.subplebbitAddress);
|
setIsModerator(true);
|
||||||
|
} else {
|
||||||
if (subplebbit && subplebbit.roles) {
|
setIsModerator(false);
|
||||||
const role = subplebbit.roles[account?.author.address]?.role;
|
}
|
||||||
|
}
|
||||||
|
}, [account?.author.address, subplebbit.roles]);
|
||||||
|
|
||||||
|
|
||||||
|
const handleOutsideClick = useCallback((e) => {
|
||||||
|
if (openMenuCid !== null && !postMenuRef.current.contains(e.target) && !postMenuCatalogRef.current.contains(e.target)) {
|
||||||
|
setOpenMenuCid(null);
|
||||||
|
}
|
||||||
|
}, [openMenuCid]);
|
||||||
|
|
||||||
|
const handleOptionClick = () => {
|
||||||
|
setOpenMenuCid(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (openMenuCid !== null) {
|
||||||
|
document.addEventListener('click', handleOutsideClick);
|
||||||
|
} else {
|
||||||
|
document.removeEventListener('click', handleOutsideClick);
|
||||||
|
}
|
||||||
|
|
||||||
if (role === 'moderator' || role === 'admin' || role === 'owner') {
|
return () => {
|
||||||
permissions[thread.subplebbitAddress] = true;
|
document.removeEventListener('click', handleOutsideClick);
|
||||||
} else {
|
};
|
||||||
permissions[thread.subplebbitAddress] = false;
|
}, [openMenuCid, handleOutsideClick]);
|
||||||
}
|
|
||||||
|
const handleAuthorDeleteClick = (comment) => {
|
||||||
|
handleOptionClick(comment.cid);
|
||||||
|
|
||||||
|
confirmAlert({
|
||||||
|
customUI: ({ onClose }) => {
|
||||||
|
return (
|
||||||
|
<AuthorDeleteAlert selectedStyle={selectedStyle}>
|
||||||
|
<div className='author-delete-alert'>
|
||||||
|
<p>Are you sure you want to delete this post?</p>
|
||||||
|
<div className="author-delete-buttons">
|
||||||
|
<button onClick={onClose}>No</button>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
setIsAuthorDelete(true);
|
||||||
|
setIsAuthorEdit(false);
|
||||||
|
setPublishCommentEditOptions(prevOptions => ({
|
||||||
|
...prevOptions,
|
||||||
|
commentCid: comment.cid,
|
||||||
|
subplebbitAddress: comment.subplebbitAddress,
|
||||||
|
deleted: true,
|
||||||
|
}));
|
||||||
|
setTriggerPublishCommentEdit(true);
|
||||||
|
onClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Yes
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</AuthorDeleteAlert>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
setModeratorPermissions(permissions);
|
|
||||||
}, [account?.author.address, selectedFeed, subplebbits]);
|
|
||||||
|
|
||||||
|
|
||||||
// mobile navbar scroll effect
|
const handleAuthorEditClick = (comment) => {
|
||||||
useEffect(() => {
|
handleOptionClick(comment.cid);
|
||||||
const debouncedHandleScroll = debounce(() => {
|
setIsAuthorEdit(true);
|
||||||
const currentScrollPos = window.pageYOffset;
|
setIsAuthorDelete(false);
|
||||||
setVisible(prevScrollPos > currentScrollPos || currentScrollPos < 10);
|
setCommentCid(comment.cid);
|
||||||
setPrevScrollPos(currentScrollPos);
|
setOriginalCommentContent(comment.content);
|
||||||
}, 50);
|
setIsEditModalOpen(true);
|
||||||
|
}
|
||||||
window.addEventListener('scroll', debouncedHandleScroll);
|
|
||||||
|
|
||||||
return () => window.removeEventListener('scroll', debouncedHandleScroll);
|
|
||||||
}, [prevScrollPos, visible]);
|
|
||||||
|
|
||||||
|
|
||||||
const onChallengeVerification = (challengeVerification) => {
|
const onChallengeVerification = (challengeVerification) => {
|
||||||
@@ -132,6 +168,7 @@ const SubscriptionsCatalog = () => {
|
|||||||
|
|
||||||
|
|
||||||
const onChallenge = async (challenges, comment) => {
|
const onChallenge = async (challenges, comment) => {
|
||||||
|
setPendingComment(comment);
|
||||||
let challengeAnswers = [];
|
let challengeAnswers = [];
|
||||||
try {
|
try {
|
||||||
challengeAnswers = await getChallengeAnswersFromUser(challenges)
|
challengeAnswers = await getChallengeAnswersFromUser(challenges)
|
||||||
@@ -159,7 +196,7 @@ const SubscriptionsCatalog = () => {
|
|||||||
|
|
||||||
const handleKeyDown = async (event) => {
|
const handleKeyDown = async (event) => {
|
||||||
if (event.key === 'Enter') {
|
if (event.key === 'Enter') {
|
||||||
const currentCaptchaResponse = useGeneralStore.getState().captchaResponse;
|
const currentCaptchaResponse = captchaResponse;
|
||||||
resolve(currentCaptchaResponse);
|
resolve(currentCaptchaResponse);
|
||||||
setIsCaptchaOpen(false);
|
setIsCaptchaOpen(false);
|
||||||
document.removeEventListener('keydown', handleKeyDown);
|
document.removeEventListener('keydown', handleKeyDown);
|
||||||
@@ -226,6 +263,253 @@ const SubscriptionsCatalog = () => {
|
|||||||
};
|
};
|
||||||
}, [triggerPublishCommentEdit, publishCommentEdit, publishCommentEditOptions]);
|
}, [triggerPublishCommentEdit, publishCommentEdit, publishCommentEditOptions]);
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div key={`thread-`} className="thread"
|
||||||
|
onMouseOver={() => {setIsHoveringOnThread(thread.cid)}}
|
||||||
|
onMouseLeave={() => {setIsHoveringOnThread('')}}>
|
||||||
|
{commentMediaInfo?.url ? (
|
||||||
|
<Link style={{all: "unset", cursor: "pointer"}} key={`link-`} to={`/p/${thread.subplebbitAddress}/c/${thread.cid}`}
|
||||||
|
onClick={() => setSelectedThread(thread.cid)}>
|
||||||
|
{commentMediaInfo?.type === "webpage" ? (
|
||||||
|
thread.thumbnailUrl ? (
|
||||||
|
<img className="card" key={`img-`}
|
||||||
|
src={commentMediaInfo.thumbnail} alt={commentMediaInfo.type}
|
||||||
|
onError={(e) => {
|
||||||
|
e.target.src = fallbackImgUrl
|
||||||
|
e.target.onerror = null;
|
||||||
|
}} />
|
||||||
|
) : null
|
||||||
|
) : null}
|
||||||
|
{commentMediaInfo?.type === "image" ? (
|
||||||
|
<img className="card" key={`img-`}
|
||||||
|
src={commentMediaInfo.url} alt={commentMediaInfo.type}
|
||||||
|
onError={(e) => {
|
||||||
|
e.target.src = fallbackImgUrl
|
||||||
|
e.target.onerror = null;}} />
|
||||||
|
) : null}
|
||||||
|
{commentMediaInfo?.type === "video" ? (
|
||||||
|
<video className="card" key={`fti-`}
|
||||||
|
src={commentMediaInfo.url}
|
||||||
|
alt={commentMediaInfo.type}
|
||||||
|
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||||
|
) : null}
|
||||||
|
{commentMediaInfo?.type === "audio" ? (
|
||||||
|
<audio className="card" controls
|
||||||
|
key={`fti-`}
|
||||||
|
src={commentMediaInfo.url}
|
||||||
|
alt={commentMediaInfo.type}
|
||||||
|
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||||
|
) : null}
|
||||||
|
</Link>
|
||||||
|
) : null}
|
||||||
|
<div key={`ti-`} className="thread-icons" >
|
||||||
|
{(commentMediaInfo && (
|
||||||
|
commentMediaInfo.type === 'image' ||
|
||||||
|
commentMediaInfo.type === 'video' ||
|
||||||
|
(commentMediaInfo.type === 'webpage' &&
|
||||||
|
commentMediaInfo.thumbnail))) ? (
|
||||||
|
<OfflineIndicator
|
||||||
|
address={thread.subplebbitAddress}
|
||||||
|
className="thread-icon offline-icon"
|
||||||
|
tooltipPlace="top" />
|
||||||
|
) : (
|
||||||
|
<OfflineIndicator
|
||||||
|
address={thread.subplebbitAddress}
|
||||||
|
className="thread-icon offline-icon-no-link"
|
||||||
|
tooltipPlace="top" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<BoardForm selectedStyle={selectedStyle}
|
||||||
|
style={{ all: "unset"}}>
|
||||||
|
<div key={`meta-`} className="meta" title="(R)eplies / (L)ink Replies" >
|
||||||
|
R: <b key={`b-`}>{thread.replyCount}</b>
|
||||||
|
{linkCount > 0 ? (
|
||||||
|
<>
|
||||||
|
/
|
||||||
|
L: <b key={`i-`}>{linkCount}</b>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
<PostMenu
|
||||||
|
style={{ display: isHoveringOnThread === thread.cid ? 'inline-block' : 'none',
|
||||||
|
position: 'absolute', lineHeight: '1em', marginTop: '-1px', outline: 'none',
|
||||||
|
zIndex: '999'}}
|
||||||
|
key={`pmb-`}
|
||||||
|
title="Post menu"
|
||||||
|
ref={el => {
|
||||||
|
threadMenuRefs.current[thread.cid] = el;
|
||||||
|
postMenuRef.current = el;
|
||||||
|
}}
|
||||||
|
className='post-menu-button'
|
||||||
|
id='post-menu-button-catalog'
|
||||||
|
rotated={openMenuCid === thread.cid}
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
const rect = threadMenuRefs.current[thread.cid].getBoundingClientRect();
|
||||||
|
setMenuPosition({top: rect.top + window.scrollY, left: rect.left});
|
||||||
|
setOpenMenuCid(prevCid => (prevCid === thread.cid ? null : thread.cid));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
▶
|
||||||
|
</PostMenu>
|
||||||
|
</div>
|
||||||
|
{createPortal(
|
||||||
|
<PostMenuCatalog selectedStyle={selectedStyle}
|
||||||
|
ref={el => {postMenuCatalogRef.current = el}}
|
||||||
|
onClick={(event) => event.stopPropagation()}
|
||||||
|
style={{position: "absolute",
|
||||||
|
top: menuPosition.top + 7,
|
||||||
|
left: menuPosition.left}}>
|
||||||
|
<div className={`post-menu-thread post-menu-thread-${thread.cid}`}
|
||||||
|
style={{ display: openMenuCid === thread.cid ? 'block' : 'none' }}
|
||||||
|
>
|
||||||
|
<ul className="post-menu-catalog">
|
||||||
|
<li onClick={() => handleOptionClick(thread.cid)}>Hide thread</li>
|
||||||
|
<VerifiedAuthor commentCid={thread.cid}>{({ authorAddress }) => (
|
||||||
|
<>
|
||||||
|
{authorAddress === account?.author.address ||
|
||||||
|
authorAddress === account?.signer.address ? (
|
||||||
|
<>
|
||||||
|
<li onClick={() => handleAuthorEditClick(thread)}>Edit post</li>
|
||||||
|
<li onClick={() => handleAuthorDeleteClick(thread)}>Delete post</li>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
{isModerator ? (
|
||||||
|
<>
|
||||||
|
{authorAddress === account?.author.address ||
|
||||||
|
authorAddress === account?.signer.address ? (
|
||||||
|
null
|
||||||
|
) : (
|
||||||
|
<li onClick={() => {
|
||||||
|
setSelectedAddress(thread.subplebbitAddress);
|
||||||
|
setModeratingCommentCid(thread.cid)
|
||||||
|
setIsModerationOpen(true);
|
||||||
|
handleOptionClick(thread.cid);
|
||||||
|
setDeletePost(true);
|
||||||
|
}}>
|
||||||
|
Delete post
|
||||||
|
</li>
|
||||||
|
)}
|
||||||
|
<li
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedAddress(thread.subplebbitAddress);
|
||||||
|
setModeratingCommentCid(thread.cid)
|
||||||
|
setIsModerationOpen(true);
|
||||||
|
handleOptionClick(thread.cid);
|
||||||
|
}}>
|
||||||
|
Mod tools
|
||||||
|
</li>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
)}</VerifiedAuthor>
|
||||||
|
{(commentMediaInfo && (
|
||||||
|
commentMediaInfo.type === 'image' ||
|
||||||
|
(commentMediaInfo.type === 'webpage' &&
|
||||||
|
commentMediaInfo.thumbnail))) ? (
|
||||||
|
<li
|
||||||
|
onMouseOver={() => {setIsImageSearchOpen(true)}}
|
||||||
|
onMouseLeave={() => {setIsImageSearchOpen(false)}}>
|
||||||
|
Image search »
|
||||||
|
<ul className="dropdown-menu post-menu-catalog"
|
||||||
|
style={{display: isImageSearchOpen ? 'block': 'none'}}>
|
||||||
|
<li onClick={() => handleOptionClick(thread.cid)}>
|
||||||
|
<a
|
||||||
|
href={`https://lens.google.com/uploadbyurl?url=${commentMediaInfo.url}`}
|
||||||
|
target="_blank" rel="noreferrer"
|
||||||
|
>Google</a>
|
||||||
|
</li>
|
||||||
|
<li onClick={() => handleOptionClick(thread.cid)}>
|
||||||
|
<a
|
||||||
|
href={`https://yandex.com/images/search?url=${commentMediaInfo.url}`}
|
||||||
|
target="_blank" rel="noreferrer"
|
||||||
|
>Yandex</a>
|
||||||
|
</li>
|
||||||
|
<li onClick={() => handleOptionClick(thread.cid)}>
|
||||||
|
<a
|
||||||
|
href={`https://saucenao.com/search.php?url=${commentMediaInfo.url}`}
|
||||||
|
target="_blank" rel="noreferrer"
|
||||||
|
>SauceNAO</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</PostMenuCatalog>, document.body
|
||||||
|
)}
|
||||||
|
</BoardForm>
|
||||||
|
<Link style={{all: "unset", cursor: "pointer"}} key={`link2-`} to={`/p/${thread.subplebbitAddress}/c/${thread.cid}`}
|
||||||
|
onClick={() => setSelectedThread(thread.cid)}>
|
||||||
|
<div key={`t-`} className="teaser">
|
||||||
|
<b key={`b2-`}>{thread.title ? `${thread.title}` : null}</b>
|
||||||
|
{thread.content ? `: ${thread.content}` : null}
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const CatalogRow = ({row}) => {
|
||||||
|
const posts = []
|
||||||
|
for (const post of row) {
|
||||||
|
posts.push(<CatalogPost key={post?.cid} post={post} />)
|
||||||
|
}
|
||||||
|
return <div>{posts}</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const SubscriptionsCatalog = () => {
|
||||||
|
const {
|
||||||
|
defaultSubplebbits,
|
||||||
|
isModerationOpen, setIsModerationOpen,
|
||||||
|
isSettingsOpen, setIsSettingsOpen,
|
||||||
|
originalCommentContent,
|
||||||
|
selectedAddress, setSelectedAddress,
|
||||||
|
selectedStyle,
|
||||||
|
setSelectedTitle,
|
||||||
|
} = useGeneralStore(state => state);
|
||||||
|
|
||||||
|
const virtuosoRef = useRef();
|
||||||
|
|
||||||
|
const account = useAccount();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const [prevScrollPos, setPrevScrollPos] = useState(0);
|
||||||
|
const [visible, setVisible] = useState(true);
|
||||||
|
|
||||||
|
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
|
||||||
|
const [deletePost, setDeletePost] = useState(false);
|
||||||
|
const [isCreateBoardOpen, setIsCreateBoardOpen] = useState(false);
|
||||||
|
|
||||||
|
const { feed, hasMore, loadMore } = useFeed({subplebbitAddresses: account?.subscriptions, sortType: 'active'});
|
||||||
|
const [selectedFeed, setSelectedFeed] = useState(feed.sort((a, b) => b.timestamp - a.timestamp));
|
||||||
|
const {subplebbits} = useSubplebbits({subplebbitAddresses: account?.subscriptions, sortType: 'active'});
|
||||||
|
|
||||||
|
const stateString = useFeedStateString(subplebbits);
|
||||||
|
|
||||||
|
const columnWidth = 180;
|
||||||
|
const windowWidth = useWindowWidth();
|
||||||
|
const columnCount = Math.floor(windowWidth / columnWidth);
|
||||||
|
const rows = useFeedRows(selectedFeed, columnCount);
|
||||||
|
|
||||||
|
|
||||||
|
// mobile navbar scroll effect
|
||||||
|
useEffect(() => {
|
||||||
|
const debouncedHandleScroll = debounce(() => {
|
||||||
|
const currentScrollPos = window.pageYOffset;
|
||||||
|
setVisible(prevScrollPos > currentScrollPos || currentScrollPos < 10);
|
||||||
|
setPrevScrollPos(currentScrollPos);
|
||||||
|
}, 50);
|
||||||
|
|
||||||
|
window.addEventListener('scroll', debouncedHandleScroll);
|
||||||
|
|
||||||
|
return () => window.removeEventListener('scroll', debouncedHandleScroll);
|
||||||
|
}, [prevScrollPos, visible]);
|
||||||
|
|
||||||
|
|
||||||
// desktop navbar board select functionality
|
// desktop navbar board select functionality
|
||||||
const handleClickTitle = (title, address) => {
|
const handleClickTitle = (title, address) => {
|
||||||
setSelectedTitle(title);
|
setSelectedTitle(title);
|
||||||
@@ -252,279 +536,6 @@ const SubscriptionsCatalog = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const CatalogPost = ({post}) => {
|
|
||||||
const thread = post;
|
|
||||||
const commentMediaInfo = getCommentMediaInfo(thread);
|
|
||||||
const linkCount = countLinks(thread);
|
|
||||||
const fallbackImgUrl = "assets/filedeleted-res.gif";
|
|
||||||
const [isHoveringOnThread, setIsHoveringOnThread] = useState(false);
|
|
||||||
const [menuPosition, setMenuPosition] = useState({top: 0, left: 0});
|
|
||||||
const [openMenuCid, setOpenMenuCid] = useState(null);
|
|
||||||
const isModerator = moderatorPermissions[thread.subplebbitAddress];
|
|
||||||
|
|
||||||
const handleOutsideClick = useCallback((e) => {
|
|
||||||
if (openMenuCid !== null && !postMenuRef.current.contains(e.target) && !postMenuCatalogRef.current.contains(e.target)) {
|
|
||||||
setOpenMenuCid(null);
|
|
||||||
}
|
|
||||||
}, [openMenuCid]);
|
|
||||||
|
|
||||||
const handleOptionClick = () => {
|
|
||||||
setOpenMenuCid(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (openMenuCid !== null) {
|
|
||||||
document.addEventListener('click', handleOutsideClick);
|
|
||||||
} else {
|
|
||||||
document.removeEventListener('click', handleOutsideClick);
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
document.removeEventListener('click', handleOutsideClick);
|
|
||||||
};
|
|
||||||
}, [openMenuCid, handleOutsideClick]);
|
|
||||||
|
|
||||||
const handleAuthorDeleteClick = (comment) => {
|
|
||||||
handleOptionClick(comment.cid);
|
|
||||||
|
|
||||||
confirmAlert({
|
|
||||||
customUI: ({ onClose }) => {
|
|
||||||
return (
|
|
||||||
<AuthorDeleteAlert selectedStyle={selectedStyle}>
|
|
||||||
<div className='author-delete-alert'>
|
|
||||||
<p>Are you sure you want to delete this post?</p>
|
|
||||||
<div className="author-delete-buttons">
|
|
||||||
<button onClick={onClose}>No</button>
|
|
||||||
<button
|
|
||||||
onClick={() => {
|
|
||||||
setIsAuthorDelete(true);
|
|
||||||
setIsAuthorEdit(false);
|
|
||||||
setPublishCommentEditOptions(prevOptions => ({
|
|
||||||
...prevOptions,
|
|
||||||
commentCid: comment.cid,
|
|
||||||
subplebbitAddress: comment.subplebbitAddress,
|
|
||||||
deleted: true,
|
|
||||||
}));
|
|
||||||
setTriggerPublishCommentEdit(true);
|
|
||||||
onClose();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Yes
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</AuthorDeleteAlert>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const handleAuthorEditClick = (comment) => {
|
|
||||||
handleOptionClick(comment.cid);
|
|
||||||
setIsAuthorEdit(true);
|
|
||||||
setIsAuthorDelete(false);
|
|
||||||
setCommentCid(comment.cid);
|
|
||||||
setOriginalCommentContent(comment.content);
|
|
||||||
setIsEditModalOpen(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div key={`thread-`} className="thread"
|
|
||||||
onMouseOver={() => {setIsHoveringOnThread(thread.cid)}}
|
|
||||||
onMouseLeave={() => {setIsHoveringOnThread('')}}>
|
|
||||||
{commentMediaInfo?.url ? (
|
|
||||||
<Link style={{all: "unset", cursor: "pointer"}} key={`link-`} to={`/p/${thread.subplebbitAddress}/c/${thread.cid}`}
|
|
||||||
onClick={() => setSelectedThread(thread.cid)}>
|
|
||||||
{commentMediaInfo?.type === "webpage" ? (
|
|
||||||
thread.thumbnailUrl ? (
|
|
||||||
<img className="card" key={`img-`}
|
|
||||||
src={commentMediaInfo.thumbnail} alt={commentMediaInfo.type}
|
|
||||||
onError={(e) => {
|
|
||||||
e.target.src = fallbackImgUrl
|
|
||||||
e.target.onerror = null;
|
|
||||||
}} />
|
|
||||||
) : null
|
|
||||||
) : null}
|
|
||||||
{commentMediaInfo?.type === "image" ? (
|
|
||||||
<img className="card" key={`img-`}
|
|
||||||
src={commentMediaInfo.url} alt={commentMediaInfo.type}
|
|
||||||
onError={(e) => {
|
|
||||||
e.target.src = fallbackImgUrl
|
|
||||||
e.target.onerror = null;}} />
|
|
||||||
) : null}
|
|
||||||
{commentMediaInfo?.type === "video" ? (
|
|
||||||
<video className="card" key={`fti-`}
|
|
||||||
src={commentMediaInfo.url}
|
|
||||||
alt={commentMediaInfo.type}
|
|
||||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
|
||||||
) : null}
|
|
||||||
{commentMediaInfo?.type === "audio" ? (
|
|
||||||
<audio className="card" controls
|
|
||||||
key={`fti-`}
|
|
||||||
src={commentMediaInfo.url}
|
|
||||||
alt={commentMediaInfo.type}
|
|
||||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
|
||||||
) : null}
|
|
||||||
</Link>
|
|
||||||
) : null}
|
|
||||||
<div key={`ti-`} className="thread-icons" >
|
|
||||||
{(commentMediaInfo && (
|
|
||||||
commentMediaInfo.type === 'image' ||
|
|
||||||
commentMediaInfo.type === 'video' ||
|
|
||||||
(commentMediaInfo.type === 'webpage' &&
|
|
||||||
commentMediaInfo.thumbnail))) ? (
|
|
||||||
<OfflineIndicator
|
|
||||||
address={thread.subplebbitAddress}
|
|
||||||
className="thread-icon offline-icon"
|
|
||||||
tooltipPlace="top" />
|
|
||||||
) : (
|
|
||||||
<OfflineIndicator
|
|
||||||
address={thread.subplebbitAddress}
|
|
||||||
className="thread-icon offline-icon-no-link"
|
|
||||||
tooltipPlace="top" />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<BoardForm selectedStyle={selectedStyle}
|
|
||||||
style={{ all: "unset"}}>
|
|
||||||
<div key={`meta-`} className="meta" title="(R)eplies / (L)ink Replies" >
|
|
||||||
R: <b key={`b-`}>{thread.replyCount}</b>
|
|
||||||
{linkCount > 0 ? (
|
|
||||||
<>
|
|
||||||
/
|
|
||||||
L: <b key={`i-`}>{linkCount}</b>
|
|
||||||
</>
|
|
||||||
) : null}
|
|
||||||
<PostMenu
|
|
||||||
style={{ display: isHoveringOnThread === thread.cid ? 'inline-block' : 'none',
|
|
||||||
position: 'absolute', lineHeight: '1em', marginTop: '-1px', outline: 'none',
|
|
||||||
zIndex: '999'}}
|
|
||||||
key={`pmb-`}
|
|
||||||
title="Post menu"
|
|
||||||
ref={el => {
|
|
||||||
threadMenuRefs.current[thread.cid] = el;
|
|
||||||
postMenuRef.current = el;
|
|
||||||
}}
|
|
||||||
className='post-menu-button'
|
|
||||||
id='post-menu-button-catalog'
|
|
||||||
rotated={openMenuCid === thread.cid}
|
|
||||||
onClick={(event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
const rect = threadMenuRefs.current[thread.cid].getBoundingClientRect();
|
|
||||||
setMenuPosition({top: rect.top + window.scrollY, left: rect.left});
|
|
||||||
setOpenMenuCid(prevCid => (prevCid === thread.cid ? null : thread.cid));
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
▶
|
|
||||||
</PostMenu>
|
|
||||||
</div>
|
|
||||||
{createPortal(
|
|
||||||
<PostMenuCatalog selectedStyle={selectedStyle}
|
|
||||||
ref={el => {postMenuCatalogRef.current = el}}
|
|
||||||
onClick={(event) => event.stopPropagation()}
|
|
||||||
style={{position: "absolute",
|
|
||||||
top: menuPosition.top + 7,
|
|
||||||
left: menuPosition.left}}>
|
|
||||||
<div className={`post-menu-thread post-menu-thread-${thread.cid}`}
|
|
||||||
style={{ display: openMenuCid === thread.cid ? 'block' : 'none' }}
|
|
||||||
>
|
|
||||||
<ul className="post-menu-catalog">
|
|
||||||
<li onClick={() => handleOptionClick(thread.cid)}>Hide thread</li>
|
|
||||||
<VerifiedAuthor commentCid={thread.cid}>{({ authorAddress }) => (
|
|
||||||
<>
|
|
||||||
{authorAddress === account?.author.address ||
|
|
||||||
authorAddress === account?.signer.address ? (
|
|
||||||
<>
|
|
||||||
<li onClick={() => handleAuthorEditClick(thread)}>Edit post</li>
|
|
||||||
<li onClick={() => handleAuthorDeleteClick(thread)}>Delete post</li>
|
|
||||||
</>
|
|
||||||
) : null}
|
|
||||||
{isModerator ? (
|
|
||||||
<>
|
|
||||||
{authorAddress === account?.author.address ||
|
|
||||||
authorAddress === account?.signer.address ? (
|
|
||||||
null
|
|
||||||
) : (
|
|
||||||
<li onClick={() => {
|
|
||||||
setSelectedAddress(thread.subplebbitAddress);
|
|
||||||
setModeratingCommentCid(thread.cid)
|
|
||||||
setIsModerationOpen(true);
|
|
||||||
handleOptionClick(thread.cid);
|
|
||||||
setDeletePost(true);
|
|
||||||
}}>
|
|
||||||
Delete post
|
|
||||||
</li>
|
|
||||||
)}
|
|
||||||
<li
|
|
||||||
onClick={() => {
|
|
||||||
setSelectedAddress(thread.subplebbitAddress);
|
|
||||||
setModeratingCommentCid(thread.cid)
|
|
||||||
setIsModerationOpen(true);
|
|
||||||
handleOptionClick(thread.cid);
|
|
||||||
}}>
|
|
||||||
Mod tools
|
|
||||||
</li>
|
|
||||||
</>
|
|
||||||
) : null}
|
|
||||||
</>
|
|
||||||
)}</VerifiedAuthor>
|
|
||||||
{(commentMediaInfo && (
|
|
||||||
commentMediaInfo.type === 'image' ||
|
|
||||||
(commentMediaInfo.type === 'webpage' &&
|
|
||||||
commentMediaInfo.thumbnail))) ? (
|
|
||||||
<li
|
|
||||||
onMouseOver={() => {setIsImageSearchOpen(true)}}
|
|
||||||
onMouseLeave={() => {setIsImageSearchOpen(false)}}>
|
|
||||||
Image search »
|
|
||||||
<ul className="dropdown-menu post-menu-catalog"
|
|
||||||
style={{display: isImageSearchOpen ? 'block': 'none'}}>
|
|
||||||
<li onClick={() => handleOptionClick(thread.cid)}>
|
|
||||||
<a
|
|
||||||
href={`https://lens.google.com/uploadbyurl?url=${commentMediaInfo.url}`}
|
|
||||||
target="_blank" rel="noreferrer"
|
|
||||||
>Google</a>
|
|
||||||
</li>
|
|
||||||
<li onClick={() => handleOptionClick(thread.cid)}>
|
|
||||||
<a
|
|
||||||
href={`https://yandex.com/images/search?url=${commentMediaInfo.url}`}
|
|
||||||
target="_blank" rel="noreferrer"
|
|
||||||
>Yandex</a>
|
|
||||||
</li>
|
|
||||||
<li onClick={() => handleOptionClick(thread.cid)}>
|
|
||||||
<a
|
|
||||||
href={`https://saucenao.com/search.php?url=${commentMediaInfo.url}`}
|
|
||||||
target="_blank" rel="noreferrer"
|
|
||||||
>SauceNAO</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
) : null
|
|
||||||
}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</PostMenuCatalog>, document.body
|
|
||||||
)}
|
|
||||||
</BoardForm>
|
|
||||||
<Link style={{all: "unset", cursor: "pointer"}} key={`link2-`} to={`/p/${thread.subplebbitAddress}/c/${thread.cid}`}
|
|
||||||
onClick={() => setSelectedThread(thread.cid)}>
|
|
||||||
<div key={`t-`} className="teaser">
|
|
||||||
<b key={`b2-`}>{thread.title ? `${thread.title}` : null}</b>
|
|
||||||
{thread.content ? `: ${thread.content}` : null}
|
|
||||||
</div>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const CatalogRow = ({row}) => {
|
|
||||||
const posts = []
|
|
||||||
for (const post of row) {
|
|
||||||
posts.push(<CatalogPost key={post?.cid} post={post} />)
|
|
||||||
}
|
|
||||||
return <div>{posts}</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const setLastVirtuosoState = () => {
|
const setLastVirtuosoState = () => {
|
||||||
virtuosoRef.current?.getState((snapshot) => {
|
virtuosoRef.current?.getState((snapshot) => {
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ const useGeneralStore = create((set) => ({
|
|||||||
defaultSubplebbits: [],
|
defaultSubplebbits: [],
|
||||||
setDefaultSubplebbits: (subplebbits) => set({ defaultSubplebbits: subplebbits }),
|
setDefaultSubplebbits: (subplebbits) => set({ defaultSubplebbits: subplebbits }),
|
||||||
|
|
||||||
|
deletePost: false,
|
||||||
|
setDeletePost: (deletePost) => set({ deletePost }),
|
||||||
|
|
||||||
editedComment: '',
|
editedComment: '',
|
||||||
setEditedComment: (comment) => set({ editedComment: comment }),
|
setEditedComment: (comment) => set({ editedComment: comment }),
|
||||||
|
|
||||||
@@ -40,6 +43,12 @@ const useGeneralStore = create((set) => ({
|
|||||||
isCaptchaOpen: false,
|
isCaptchaOpen: false,
|
||||||
setIsCaptchaOpen: (isOpen) => set({ isCaptchaOpen: isOpen }),
|
setIsCaptchaOpen: (isOpen) => set({ isCaptchaOpen: isOpen }),
|
||||||
|
|
||||||
|
isEditModalOpen: false,
|
||||||
|
setIsEditModalOpen: (isOpen) => set({ isEditModalOpen: isOpen }),
|
||||||
|
|
||||||
|
isModerator: false,
|
||||||
|
setIsModerator: (isModerator) => set({ isModerator }),
|
||||||
|
|
||||||
isModerationOpen: false,
|
isModerationOpen: false,
|
||||||
setIsModerationOpen: (isOpen) => set({ isModerationOpen: isOpen }),
|
setIsModerationOpen: (isOpen) => set({ isModerationOpen: isOpen }),
|
||||||
|
|
||||||
@@ -52,6 +61,9 @@ const useGeneralStore = create((set) => ({
|
|||||||
moderatingCommentCid: '',
|
moderatingCommentCid: '',
|
||||||
setModeratingCommentCid: (cid) => set({ moderatingCommentCid: cid }),
|
setModeratingCommentCid: (cid) => set({ moderatingCommentCid: cid }),
|
||||||
|
|
||||||
|
originalCommentContent: null,
|
||||||
|
setOriginalCommentContent: (content) => set({ originalCommentContent: content }),
|
||||||
|
|
||||||
pendingComment: '',
|
pendingComment: '',
|
||||||
setPendingComment: (comment) => set({ pendingComment: comment }),
|
setPendingComment: (comment) => set({ pendingComment: comment }),
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user