Files
5chan/src/components/views/SubscriptionsCatalog.jsx
T

767 lines
32 KiB
React
Raw Normal View History

2023-07-30 22:15:09 +02:00
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import { Helmet } from 'react-helmet-async';
2023-07-31 08:59:17 +02:00
import { Link, useNavigate} from 'react-router-dom';
import { confirmAlert } from 'react-confirm-alert';
2023-07-30 22:15:09 +02:00
import { Tooltip } from 'react-tooltip';
2023-07-31 08:59:17 +02:00
import { VirtuosoGrid } from 'react-virtuoso';
import { useAccount, useFeed, usePublishCommentEdit, useSubplebbits } from '@plebbit/plebbit-react-hooks';
import { debounce } from 'lodash';
2023-05-07 17:48:38 +02:00
import useGeneralStore from '../../hooks/stores/useGeneralStore';
2023-07-31 08:59:17 +02:00
import { Container, NavBar, Header, Break, PostMenu, BoardForm } from '../styled/views/Board.styled';
import { Threads, PostMenuCatalog, GridContainer } from '../styled/views/Catalog.styled';
import { TopBar, Footer, AuthorDeleteAlert } from '../styled/views/Thread.styled';
import CatalogLoader from '../CatalogLoader';
import EditModal from '../modals/EditModal';
import ImageBanner from '../ImageBanner';
import VerifiedAuthor from '../VerifiedAuthor';
import CreateBoardModal from '../modals/CreateBoardModal';
import ModerationModal from '../modals/ModerationModal';
import OfflineIndicator from '../OfflineIndicator';
import SettingsModal from '../modals/SettingsModal';
2023-07-30 22:15:09 +02:00
import countLinks from '../../utils/countLinks';
import getCommentMediaInfo from '../../utils/getCommentMediaInfo';
import handleStyleChange from '../../utils/handleStyleChange';
2023-07-31 08:59:17 +02:00
import useError from '../../hooks/useError';
import useFeedStateString from '../../hooks/useFeedStateString';
import useSuccess from '../../hooks/useSuccess';
import packageJson from '../../../package.json'
const {version} = packageJson
2023-05-07 17:48:38 +02:00
const SubscriptionsCatalog = () => {
const {
2023-06-14 16:23:44 +02:00
setCaptchaResponse,
setChallengesArray,
2023-05-07 17:48:38 +02:00
defaultSubplebbits,
2023-06-14 16:23:44 +02:00
editedComment,
setIsAuthorDelete,
setIsAuthorEdit,
setIsCaptchaOpen,
isModerationOpen, setIsModerationOpen,
2023-05-07 17:48:38 +02:00
isSettingsOpen, setIsSettingsOpen,
2023-06-14 16:23:44 +02:00
setModeratingCommentCid,
setResolveCaptchaPromise,
selectedAddress, setSelectedAddress,
2023-05-07 17:48:38 +02:00
selectedStyle,
setSelectedThread,
setSelectedTitle,
} = useGeneralStore(state => state);
2023-06-14 16:23:44 +02:00
const threadMenuRefs = useRef({});
const postMenuRef = useRef(null);
const postMenuCatalogRef = useRef(null);
2023-05-07 17:48:38 +02:00
const account = useAccount();
2023-06-07 18:26:03 +02:00
const navigate = useNavigate();
2023-06-14 16:23:44 +02:00
const [, setNewErrorMessage] = useError();
const [, setNewSuccessMessage] = useSuccess();
2023-06-07 21:24:17 +02:00
2023-05-07 17:48:38 +02:00
const [prevScrollPos, setPrevScrollPos] = useState(0);
const [visible, setVisible] = useState(true);
2023-06-14 16:23:44 +02:00
const [isHoveringOnThread, setIsHoveringOnThread] = useState(false);
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);
2023-07-31 08:59:17 +02:00
const [menuPosition, setMenuPosition] = useState({top: 0, left: 0});
2023-06-14 16:23:44 +02:00
const [openMenuCid, setOpenMenuCid] = useState(null);
const [moderatorPermissions, setModeratorPermissions] = useState({});
const [isCreateBoardOpen, setIsCreateBoardOpen] = useState(false);
2023-06-14 16:23:44 +02:00
2023-07-31 08:59:17 +02:00
const { feed, loadMore } = useFeed({subplebbitAddresses: account?.subscriptions, sortType: 'active'});
2023-06-14 16:23:44 +02:00
const [selectedFeed, setSelectedFeed] = useState(feed.sort((a, b) => b.timestamp - a.timestamp));
2023-07-31 08:59:17 +02:00
const {subplebbits} = useSubplebbits({subplebbitAddresses: account?.subscriptions, sortType: 'active'});
2023-05-16 15:15:31 +02:00
const stateString = useFeedStateString(subplebbits);
2023-05-07 17:48:38 +02:00
2023-06-14 16:23:44 +02:00
useEffect(() => {
let permissions = {};
2023-07-31 08:59:17 +02:00
2023-06-14 16:23:44 +02:00
selectedFeed.forEach(thread => {
const subplebbit = subplebbits.find(s => s && s.address === thread.subplebbitAddress);
2023-07-31 08:59:17 +02:00
if (subplebbit && subplebbit.roles) {
2023-06-14 16:23:44 +02:00
const role = subplebbit.roles[account?.author.address]?.role;
2023-07-31 08:59:17 +02:00
2023-06-14 16:23:44 +02:00
if (role === 'moderator' || role === 'admin' || role === 'owner') {
permissions[thread.subplebbitAddress] = true;
} else {
permissions[thread.subplebbitAddress] = false;
}
}
});
2023-07-31 08:59:17 +02:00
2023-06-14 16:23:44 +02:00
setModeratorPermissions(permissions);
2023-07-31 08:59:17 +02:00
}, [account?.author.address, selectedFeed, subplebbits]);
2023-06-14 16:23:44 +02:00
const handleOptionClick = () => {
setOpenMenuCid(null);
};
const handleOutsideClick = useCallback((e) => {
if (openMenuCid !== null && !postMenuRef.current.contains(e.target) && !postMenuCatalogRef.current.contains(e.target)) {
setOpenMenuCid(null);
}
}, [openMenuCid, postMenuRef, postMenuCatalogRef]);
useEffect(() => {
if (openMenuCid !== null) {
document.addEventListener('click', handleOutsideClick);
} else {
document.removeEventListener('click', handleOutsideClick);
}
2023-07-31 08:59:17 +02:00
2023-06-14 16:23:44 +02:00
return () => {
document.removeEventListener('click', handleOutsideClick);
};
}, [openMenuCid, handleOutsideClick]);
2023-05-07 17:48:38 +02:00
// mobile navbar scroll effect
useEffect(() => {
const debouncedHandleScroll = debounce(() => {
const currentScrollPos = window.pageYOffset;
setVisible(prevScrollPos > currentScrollPos || currentScrollPos < 10);
setPrevScrollPos(currentScrollPos);
}, 50);
2023-07-31 08:59:17 +02:00
2023-05-07 17:48:38 +02:00
window.addEventListener('scroll', debouncedHandleScroll);
2023-07-31 08:59:17 +02:00
2023-05-07 17:48:38 +02:00
return () => window.removeEventListener('scroll', debouncedHandleScroll);
}, [prevScrollPos, visible]);
const tryLoadMore = async () => {
2023-07-31 08:59:17 +02:00
try {loadMore()}
catch (e)
{await new Promise(resolve => setTimeout(resolve, 1000))}
2023-05-07 17:48:38 +02:00
};
2023-06-14 16:23:44 +02:00
const onChallengeVerification = (challengeVerification) => {
if (challengeVerification.challengeSuccess === true) {
2023-07-31 08:59:17 +02:00
setNewSuccessMessage('Challenge Success');
}
2023-06-14 16:23:44 +02:00
else if (challengeVerification.challengeSuccess === false) {
setNewErrorMessage(`Challenge Failed, reason: ${challengeVerification.reason}. Errors: ${challengeVerification.errors}`);
console.log('challenge failed', challengeVerification);
2023-06-14 16:23:44 +02:00
}
};
const onChallenge = async (challenges, comment) => {
let challengeAnswers = [];
try {
challengeAnswers = await getChallengeAnswersFromUser(challenges)
}
catch (error) {
2023-07-02 11:45:56 +02:00
setNewErrorMessage(error.message); console.log(error);
2023-06-14 16:23:44 +02:00
}
if (challengeAnswers) {
await comment.publishChallengeAnswers(challengeAnswers)
}
};
const getChallengeAnswersFromUser = async (challenges) => {
setChallengesArray(challenges);
2023-07-31 08:59:17 +02:00
2023-06-14 16:23:44 +02:00
return new Promise((resolve, reject) => {
const imageString = challenges?.challenges[0].challenge;
const imageSource = `data:image/png;base64,${imageString}`;
const challengeImg = new Image();
challengeImg.src = imageSource;
2023-07-31 08:59:17 +02:00
2023-06-14 16:23:44 +02:00
challengeImg.onload = () => {
setIsCaptchaOpen(true);
2023-07-31 08:59:17 +02:00
2023-06-14 16:23:44 +02:00
const handleKeyDown = async (event) => {
if (event.key === 'Enter') {
const currentCaptchaResponse = useGeneralStore.getState().captchaResponse;
resolve(currentCaptchaResponse);
setIsCaptchaOpen(false);
document.removeEventListener('keydown', handleKeyDown);
event.preventDefault();
}
};
setCaptchaResponse('');
document.addEventListener('keydown', handleKeyDown);
setResolveCaptchaPromise(resolve);
};
2023-07-31 08:59:17 +02:00
2023-06-14 16:23:44 +02:00
challengeImg.onerror = () => {
reject(setNewErrorMessage('Could not load challenges'));
};
});
};
const [publishCommentEditOptions, setPublishCommentEditOptions] = useState({
commentCid: commentCid,
content: editedComment || undefined,
subplebbitAddress: selectedAddress,
onChallenge,
onChallengeVerification,
onError: (error) => {
2023-07-02 11:45:56 +02:00
setNewErrorMessage(error.message); console.log(error);
2023-06-14 16:23:44 +02:00
},
});
2023-07-31 08:59:17 +02:00
2023-06-14 16:23:44 +02:00
const { publishCommentEdit } = usePublishCommentEdit(publishCommentEditOptions);
2023-06-14 17:07:00 +02:00
const handleAuthorDeleteClick = (comment) => {
handleOptionClick(comment.cid);
2023-06-14 16:23:44 +02:00
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,
2023-06-14 16:23:44 +02:00
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);
}
2023-07-31 08:59:17 +02:00
2023-06-14 16:23:44 +02:00
useEffect(() => {
setPublishCommentEditOptions((prevOptions) => ({
...prevOptions,
commentCid: commentCid,
content: editedComment || undefined,
}));
}, [commentCid, editedComment]);
useEffect(() => {
if (editedComment !== '') {
setTriggerPublishCommentEdit(true);
}
}, [editedComment, setIsAuthorEdit]);
2023-07-31 08:59:17 +02:00
2023-06-14 16:23:44 +02:00
useEffect(() => {
2023-06-29 16:45:12 +02:00
let isActive = true;
2023-06-14 16:23:44 +02:00
if (publishCommentEditOptions && triggerPublishCommentEdit) {
(async () => {
await publishCommentEdit();
2023-06-29 16:45:12 +02:00
if (isActive) {
setTriggerPublishCommentEdit(false);
}
2023-06-14 16:23:44 +02:00
})();
}
2023-06-29 16:45:12 +02:00
return () => {
isActive = false;
};
}, [triggerPublishCommentEdit, publishCommentEdit, publishCommentEditOptions]);
2023-06-14 16:23:44 +02:00
// desktop navbar board select functionality
const handleClickTitle = (title, address) => {
setSelectedTitle(title);
setSelectedAddress(address);
setSelectedFeed(feed.filter(feed => feed.title === title));
};
2023-05-07 17:48:38 +02:00
// mobile navbar board select functionality
const handleSelectChange = (event) => {
const selected = event.target.value;
if (selected === 'subscriptions') {
2023-05-16 16:37:50 +02:00
navigate(`/p/subscriptions`);
return;
} else if (selected === 'all') {
navigate(`/p/all`);
2023-05-07 17:48:38 +02:00
return;
}
const selectedTitle = defaultSubplebbits.find((subplebbit) => subplebbit.address === selected).title;
setSelectedTitle(selectedTitle);
setSelectedAddress(selected);
navigate(`/p/${selected}`);
};
return (
<>
<Helmet>
2023-07-31 08:59:17 +02:00
<title>Subscriptions - Catalog - plebchan</title>
2023-05-07 17:48:38 +02:00
</Helmet>
<Container>
<CreateBoardModal
2023-07-31 08:59:17 +02:00
selectedStyle={selectedStyle}
isOpen={isCreateBoardOpen}
closeModal={() => setIsCreateBoardOpen(false)} />
2023-05-07 17:48:38 +02:00
<SettingsModal
2023-07-31 08:59:17 +02:00
selectedStyle={selectedStyle}
isOpen={isSettingsOpen}
closeModal={() => setIsSettingsOpen(false)} />
<ModerationModal
selectedStyle={selectedStyle}
isOpen={isModerationOpen}
closeModal={() => {setIsModerationOpen(false); setDeletePost(false)}}
deletePost={deletePost} />
2023-06-14 16:23:44 +02:00
<EditModal
2023-07-31 08:59:17 +02:00
selectedStyle={selectedStyle}
isOpen={isEditModalOpen}
closeModal={() => setIsEditModalOpen(false)}
originalCommentContent={originalCommentContent} />
2023-05-07 17:48:38 +02:00
<NavBar selectedStyle={selectedStyle}>
<>
2023-07-31 08:59:17 +02:00
<span className="boardList">
[
2023-07-14 14:32:33 +02:00
<Link to={`/p/all`} onClick={() => window.scrollTo(0, 0)}>All</Link>
2023-07-31 08:59:17 +02:00
 / 
2023-07-14 14:32:33 +02:00
<Link to={`/p/subscriptions`} onClick={() => window.scrollTo(0, 0)}>Subscriptions</Link>
2023-07-31 08:59:17 +02:00
]&nbsp;[
{defaultSubplebbits.map((subplebbit, index) => (
<span className="boardList" key={`span-${subplebbit.address}`}>
{index === 0 ? null : "\u00a0"}
<Link to={`/p/${subplebbit.address}`} key={`a-${subplebbit.address}`} onClick={() => {
setSelectedTitle(subplebbit.title);
setSelectedAddress(subplebbit.address);
}}
>{subplebbit.title ? subplebbit.title : subplebbit.address}</Link>
{index !== defaultSubplebbits.length - 1 ? " /" : null}
</span>
))}
]
</span>
2023-05-07 17:48:38 +02:00
<span className="nav">
[
2023-07-31 08:59:17 +02:00
<span id="button-span" style={{cursor: 'pointer'}} onClick={
() => {
window.electron && window.electron.isElectron ? (
setIsCreateBoardOpen(true)
) : (
alert(
'You can create a board with the desktop version of plebchan:\nhttps://github.com/plebbit/plebchan/releases/latest\n\nIf you are comfortable with the command line, use plebbit-cli:\nhttps://github.com/plebbit/plebbit-cli\n\n'
2023-05-07 17:48:38 +02:00
)
2023-07-31 08:59:17 +02:00
)
}
2023-05-27 12:33:25 +02:00
}>Create Board</span>
2023-05-07 17:48:38 +02:00
]
[
2023-05-16 13:26:05 +02:00
<Link to={`/p/subscriptions/catalog/settings`} onClick={() => setIsSettingsOpen(true)}>Settings</Link>
2023-05-07 17:48:38 +02:00
]
[
2023-05-27 12:55:16 +02:00
<Link to="/">Home</Link>
2023-05-07 17:48:38 +02:00
]
</span>
<div id="board-nav-mobile" style={{ top: visible ? 0 : '-23px' }}>
2023-05-27 11:04:23 +02:00
<div className="nav-container">
<div className="board-select">
<strong>Board</strong>
&nbsp;
<select id="board-select-mobile" value="subscriptions" onChange={handleSelectChange}>
<option value="all">All</option>
<option value="subscriptions">Subscriptions</option>
{defaultSubplebbits.map(subplebbit => (
2023-07-31 08:59:17 +02:00
<option key={`option-${subplebbit.address}`} value={subplebbit.address}
>{subplebbit.title ? subplebbit.title : subplebbit.address}</option>
))}
</select> 
<span id="button-span" style={{cursor: 'pointer'}} onClick={
() => alert(
'You can create a board with the desktop version of plebchan:\nhttps://github.com/plebbit/plebchan/releases/latest\n\nIf you are comfortable with the command line, use plebbit-cli:\nhttps://github.com/plebbit/plebbit-cli\n\n'
2023-05-07 17:48:38 +02:00
)
2023-05-27 11:04:23 +02:00
}>Create Board</span>
</div>
<div className="page-jump">
<Link to={`/p/subscriptions/catalog/settings`} onClick={() => setIsSettingsOpen(true)}>Settings</Link>
&nbsp;
2023-07-31 08:59:17 +02:00
<Link to="/" onClick={() => {handleStyleChange({target: {value: "Yotsuba"}}); window.scrollTo(0, 0);}}>Home</Link>
2023-05-27 11:04:23 +02:00
</div>
2023-05-07 17:48:38 +02:00
</div>
</div>
<div id="separator-mobile">&nbsp;</div>
<div id="separator-mobile">&nbsp;</div>
</>
</NavBar>
<Header selectedStyle={selectedStyle}>
<>
<div className="banner">
<ImageBanner />
</div>
2023-07-31 08:59:17 +02:00
<>
2023-05-07 17:48:38 +02:00
<div className="board-title">Subscriptions</div>
2023-07-25 20:35:41 +02:00
{account?.subscriptions.length < 1 ? (
2023-05-07 17:48:38 +02:00
<div className="board-address">You haven't subscribed to any board yet.</div>
) : (
<div className="board-address">
2023-07-25 20:35:41 +02:00
You have subscribed to {account?.subscriptions.length} board{account?.subscriptions.length > 1 ? "s" : null}.
2023-05-07 17:48:38 +02:00
</div>
)}
2023-07-31 08:59:17 +02:00
</>
2023-05-07 17:48:38 +02:00
</>
</Header>
<Break selectedStyle={selectedStyle} />
<TopBar selectedStyle={selectedStyle}>
<hr />
<span className="style-changer">
Style:
2023-07-31 08:59:17 +02:00
 
2023-05-07 17:48:38 +02:00
<select id="style-selector" onChange={handleStyleChange} value={selectedStyle}>
<option value="Yotsuba">Yotsuba</option>
<option value="Yotsuba-B">Yotsuba B</option>
<option value="Futaba">Futaba</option>
<option value="Burichan">Burichan</option>
<option value="Tomorrow">Tomorrow</option>
<option value="Photon">Photon</option>
</select>
</span>
<div className="return-button" id="return-button-desktop">
[
<Link to={`/p/subscriptions`}>Return</Link>
]
</div>
<div id="return-button-mobile">
<span className="btn-wrap-catalog btn-wrap">
<Link to={`/p/subscriptions`}>Return</Link>
</span>
</div>
2023-07-13 15:58:04 +02:00
{subplebbits.state === "succeeded" ? (
2023-05-16 15:15:31 +02:00
null
) : (
2023-07-31 08:59:17 +02:00
<div id="stats" style={{float: "right", marginTop: "5px"}}>
2023-05-16 15:15:31 +02:00
<span className={stateString ? "ellipsis" : ""}>{stateString}</span>
</div>
)}
2023-05-07 17:48:38 +02:00
<hr />
</TopBar>
<Tooltip id="tooltip" className="tooltip" />
2023-05-07 17:48:38 +02:00
<Threads selectedStyle={selectedStyle}>
2023-07-31 08:59:17 +02:00
{feed.length > 1 ? (
<VirtuosoGrid
style={{width: '100%', height: '100%'}}
data={feed}
increaseViewportBy={{bottom: 600, top: 600}}
itemContent={(index) => {
const thread = feed[index];
2023-07-25 21:10:22 +02:00
const commentMediaInfo = getCommentMediaInfo(thread);
const fallbackImgUrl = "assets/filedeleted-res.gif";
const isModerator = moderatorPermissions[thread.subplebbitAddress];
const linkCount = countLinks(thread);
return (
2023-07-31 08:59:17 +02:00
<div key={`thread-${index}`} className="thread"
onMouseOver={() => {setIsHoveringOnThread(thread.cid)}}
onMouseLeave={() => {setIsHoveringOnThread('')}}>
2023-06-14 16:23:44 +02:00
{commentMediaInfo?.url ? (
2023-07-31 08:59:17 +02:00
<Link style={{all: "unset", cursor: "pointer"}} key={`link-${index}`} to={`/p/${thread.subplebbitAddress}/c/${thread.cid}`}
onClick={() => setSelectedThread(thread.cid)}>
2023-06-14 16:23:44 +02:00
{commentMediaInfo?.type === "webpage" ? (
thread.thumbnailUrl ? (
2023-07-31 08:59:17 +02:00
<img className="card" key={`img-${index}`}
src={commentMediaInfo.thumbnail} alt={commentMediaInfo.type}
onError={(e) => {
e.target.src = fallbackImgUrl
e.target.onerror = null;
}} />
2023-06-14 16:23:44 +02:00
) : null
2023-05-07 17:48:38 +02:00
) : null}
2023-06-14 16:23:44 +02:00
{commentMediaInfo?.type === "image" ? (
<img className="card" key={`img-${index}`}
2023-07-31 08:59:17 +02:00
src={commentMediaInfo.url} alt={commentMediaInfo.type}
onError={(e) => {
e.target.src = fallbackImgUrl
e.target.onerror = null;}} />
2023-06-14 16:23:44 +02:00
) : null}
{commentMediaInfo?.type === "video" ? (
2023-07-31 08:59:17 +02:00
<video className="card" key={`fti-${index}`}
src={commentMediaInfo.url}
alt={commentMediaInfo.type}
onError={(e) => e.target.src = fallbackImgUrl} />
2023-06-14 16:23:44 +02:00
) : null}
{commentMediaInfo?.type === "audio" ? (
2023-07-31 08:59:17 +02:00
<audio className="card" controls
key={`fti-${index}`}
src={commentMediaInfo.url}
alt={commentMediaInfo.type}
2023-06-14 16:23:44 +02:00
onError={(e) => e.target.src = fallbackImgUrl} />
) : null}
</Link>
) : null}
<div key={`ti-${index}`} className="thread-icons" >
2023-07-31 08:59:17 +02:00
{(commentMediaInfo && (
commentMediaInfo.type === 'image' ||
commentMediaInfo.type === 'video' ||
(commentMediaInfo.type === 'webpage' &&
commentMediaInfo.thumbnail))) ? (
<OfflineIndicator
address={thread.subplebbitAddress}
className="thread-icon offline-icon"
tooltipPlace="top" />
2023-06-14 16:23:44 +02:00
) : (
2023-07-31 08:59:17 +02:00
<OfflineIndicator
address={thread.subplebbitAddress}
className="thread-icon offline-icon-no-link"
tooltipPlace="top" />
)}
2023-06-14 16:23:44 +02:00
</div>
2023-07-31 08:59:17 +02:00
<BoardForm selectedStyle={selectedStyle}
style={{ all: "unset"}}>
2023-07-10 11:15:35 +02:00
<div key={`meta-${index}`} className="meta" title="(R)eplies / (L)ink Replies" >
R:&nbsp;<b key={`b-${index}`}>{thread.replyCount}</b>
{linkCount > 0 ? (
<>
&nbsp;/
L:&nbsp;<b key={`i-${index}`}>{linkCount}</b>
</>
) : null}
2023-07-31 08:59:17 +02:00
<PostMenu
style={{ display: isHoveringOnThread === thread.cid ? 'inline-block' : 'none',
position: 'absolute', lineHeight: '1em', marginTop: '-1px', outline: 'none',
zIndex: '999'}}
key={`pmb-${index}`}
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>
2023-05-07 17:48:38 +02:00
</div>
2023-06-14 16:23:44 +02:00
{createPortal(
2023-07-31 08:59:17 +02:00
<PostMenuCatalog selectedStyle={selectedStyle}
ref={el => {postMenuCatalogRef.current = el}}
2023-06-14 16:23:44 +02:00
onClick={(event) => event.stopPropagation()}
2023-07-31 08:59:17 +02:00
style={{position: "absolute",
top: menuPosition.top + 7,
left: menuPosition.left}}>
2023-06-14 16:23:44 +02:00
<div className={`post-menu-thread post-menu-thread-${thread.cid}`}
2023-07-31 08:59:17 +02:00
style={{ display: openMenuCid === thread.cid ? 'block' : 'none' }}
2023-06-14 16:23:44 +02:00
>
<ul className="post-menu-catalog">
<li onClick={() => handleOptionClick(thread.cid)}>Hide thread</li>
2023-07-09 16:03:46 +02:00
<VerifiedAuthor commentCid={thread.cid}>{({ authorAddress }) => (
2023-06-14 16:23:44 +02:00
<>
2023-07-31 08:59:17 +02:00
{authorAddress === account?.author.address ||
authorAddress === account?.signer.address ? (
2023-07-09 16:03:46 +02:00
<>
<li onClick={() => handleAuthorEditClick(thread)}>Edit post</li>
<li onClick={() => handleAuthorDeleteClick(thread)}>Delete post</li>
</>
) : null}
{isModerator ? (
<>
{authorAddress === account?.author.address ||
2023-07-31 08:59:17 +02:00
authorAddress === account?.signer.address ? (
2023-07-09 16:03:46 +02:00
null
) : (
<li onClick={() => {
setSelectedAddress(thread.subplebbitAddress);
setModeratingCommentCid(thread.cid)
2023-07-31 08:59:17 +02:00
setIsModerationOpen(true);
2023-07-09 16:03:46 +02:00
handleOptionClick(thread.cid);
setDeletePost(true);
}}>
2023-07-31 08:59:17 +02:00
Delete post
2023-07-09 16:03:46 +02:00
</li>
)}
<li
2023-07-31 08:59:17 +02:00
onClick={() => {
setSelectedAddress(thread.subplebbitAddress);
setModeratingCommentCid(thread.cid)
setIsModerationOpen(true);
handleOptionClick(thread.cid);
}}>
2023-07-09 16:03:46 +02:00
Mod tools
</li>
</>
) : null}
2023-06-14 16:23:44 +02:00
</>
2023-07-09 16:03:46 +02:00
)}</VerifiedAuthor>
2023-06-14 16:23:44 +02:00
{(commentMediaInfo && (
2023-07-31 08:59:17 +02:00
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
2023-06-14 16:23:44 +02:00
href={`https://lens.google.com/uploadbyurl?url=${commentMediaInfo.url}`}
target="_blank" rel="noreferrer"
2023-07-31 08:59:17 +02:00
>Google</a>
</li>
<li onClick={() => handleOptionClick(thread.cid)}>
<a
2023-06-14 16:23:44 +02:00
href={`https://yandex.com/images/search?url=${commentMediaInfo.url}`}
target="_blank" rel="noreferrer"
2023-07-31 08:59:17 +02:00
>Yandex</a>
</li>
<li onClick={() => handleOptionClick(thread.cid)}>
<a
2023-06-14 16:23:44 +02:00
href={`https://saucenao.com/search.php?url=${commentMediaInfo.url}`}
target="_blank" rel="noreferrer"
2023-07-31 08:59:17 +02:00
>SauceNAO</a>
</li>
</ul>
</li>
) : null
2023-06-14 16:23:44 +02:00
}
</ul>
</div>
</PostMenuCatalog>, document.body
)}
</BoardForm>
2023-07-31 08:59:17 +02:00
<Link style={{all: "unset", cursor: "pointer"}} key={`link2-${index}`} to={`/p/${thread.subplebbitAddress}/c/${thread.cid}`}
onClick={() => setSelectedThread(thread.cid)}>
2023-05-07 17:48:38 +02:00
<div key={`t-${index}`} className="teaser">
2023-06-14 16:23:44 +02:00
<b key={`b2-${index}`}>{thread.title ? `${thread.title}` : null}</b>
{thread.content ? `: ${thread.content}` : null}
2023-05-07 17:48:38 +02:00
</div>
2023-06-14 16:23:44 +02:00
</Link>
2023-07-31 08:59:17 +02:00
</div>
2023-07-25 21:10:22 +02:00
)
2023-07-31 08:59:17 +02:00
}}
endReached={tryLoadMore}
useWindowScroll={true}
components={{List: GridContainer}}
/>
) : (<CatalogLoader />)}
2023-05-07 17:48:38 +02:00
</Threads>
<Footer selectedStyle={selectedStyle}>
<Break id="break" selectedStyle={selectedStyle} style={{
marginTop: "-36px",
width: "100%",
}} />
<Break selectedStyle={selectedStyle} style={{
width: "100%",
}} />
<span className="style-changer" style={{
float: "right",
marginTop: "2px",
}}>
Style:
2023-07-31 08:59:17 +02:00
 
2023-05-07 17:48:38 +02:00
<select id="style-selector" onChange={handleStyleChange} value={selectedStyle}>
<option value="Yotsuba">Yotsuba</option>
<option value="Yotsuba-B">Yotsuba B</option>
<option value="Futaba">Futaba</option>
<option value="Burichan">Burichan</option>
<option value="Tomorrow">Tomorrow</option>
<option value="Photon">Photon</option>
</select>
</span>
<NavBar selectedStyle={selectedStyle} style={{
marginTop: "42px",
}}>
2023-07-31 08:59:17 +02:00
<>
<span className="boardList">
[
2023-07-14 14:32:33 +02:00
<Link to={`/p/subscriptions`} onClick={() => window.scrollTo(0, 0)}>Subscriptions</Link>
2023-07-31 08:59:17 +02:00
]&nbsp;[
{defaultSubplebbits.map((subplebbit, index) => (
<span className="boardList" key={`span-${subplebbit.address}`}>
{index === 0 ? null : "\u00a0"}
<Link to={`/p/${subplebbit.address}`} key={`a-${subplebbit.address}`} onClick={() => handleClickTitle(subplebbit.title, subplebbit.address)}
>{subplebbit.title ? subplebbit.title : subplebbit.address}</Link>
{index !== defaultSubplebbits.length - 1 ? " /" : null}
</span>
))}
]
</span>
2023-05-07 17:48:38 +02:00
<span className="nav">
2023-07-31 08:59:17 +02:00
[
<span id="button-span" style={{cursor: 'pointer'}} onClick={
() => {
window.electron && window.electron.isElectron ? (
setIsCreateBoardOpen(true)
) : (
alert(
'You can create a board with the desktop version of plebchan:\nhttps://github.com/plebbit/plebchan/releases/latest\n\nIf you are comfortable with the command line, use plebbit-cli:\nhttps://github.com/plebbit/plebbit-cli\n\n'
)
)
}
}>Create Board</span>
]
2023-05-07 17:48:38 +02:00
[
<Link to={`/p/subscriptions/catalog/settings`} onClick={() => setIsSettingsOpen(true)}>Settings</Link>
2023-05-07 17:48:38 +02:00
]
[
2023-07-31 08:59:17 +02:00
<Link to="/" onClick={() => handleStyleChange({target: {value: "Yotsuba"}}
2023-05-07 17:48:38 +02:00
)}>Home</Link>
]
</span>
</>
</NavBar>
<div id="version">
plebchan v{version}. GPL-2.0
</div>
<div className="footer-links"
style={{
textAlign: "center",
fontSize: "x-small",
fontFamily: "arial",
marginTop: "5px",
marginBottom: "15px",
}}>
2023-07-31 08:59:17 +02:00
<a style={{textDecoration: 'underline'}} href="https://plebbit.com" target="_blank" rel="noopener noreferrer">About</a>
&nbsp;&nbsp;
<a style={{textDecoration: 'underline'}} href="https://github.com/plebbit/plebchan/releases/latest" target="_blank" rel="noopener noreferrer">App</a>
2023-05-07 17:48:38 +02:00
&nbsp;&nbsp;
2023-07-31 08:59:17 +02:00
<a style={{textDecoration: 'underline'}} href="https://twitter.com/plebchan_eth" target="_blank" rel="noopener noreferrer">Twitter</a>
&nbsp;&nbsp;
<a style={{textDecoration: 'underline'}} href="https://t.me/plebbit" target="_blank" rel="noopener noreferrer">Telegram</a>
2023-05-07 17:48:38 +02:00
</div>
</Footer>
</Container>
</>
);
}
export default SubscriptionsCatalog;