2023-05-25 13:42:58 +02:00
import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
import { createPortal } from 'react-dom' ;
2023-04-21 10:47:39 +02:00
import { Helmet } from 'react-helmet-async' ;
2023-04-29 10:50:18 +02:00
import InfiniteScroll from 'react-infinite-scroller' ;
2023-04-21 10:47:39 +02:00
import { Link , useNavigate , useParams } from 'react-router-dom' ;
2023-05-25 13:42:58 +02:00
import { confirmAlert } from 'react-confirm-alert' ;
2023-05-08 21:10:42 +02:00
import { Tooltip } from 'react-tooltip' ;
2023-05-25 13:42:58 +02:00
import { useAccount , useFeed , usePublishComment , usePublishCommentEdit , useSubplebbit , useSubscribe } from '@plebbit/plebbit-react-hooks' ;
2023-03-25 14:54:04 +01:00
import { debounce } from 'lodash' ;
2023-05-25 13:42:58 +02:00
import { Container , NavBar , Header , Break , PostForm , PostFormLink , PostFormTable , PostMenu , BoardForm } from '../styled/views/Board.styled' ;
import { Threads , PostMenuCatalog } from '../styled/views/Catalog.styled' ;
import { TopBar , Footer , AuthorDeleteAlert } from '../styled/views/Thread.styled' ;
2023-03-19 18:30:07 +01:00
import CatalogLoader from '../CatalogLoader' ;
2023-05-25 13:42:58 +02:00
import EditModal from '../modals/EditModal' ;
2023-03-23 15:49:57 +01:00
import ImageBanner from '../ImageBanner' ;
2023-07-08 14:37:08 +02:00
import VerifiedAuthor from '../VerifiedAuthor' ;
2023-07-19 18:16:01 +02:00
import CreateBoardModal from '../modals/CreateBoardModal' ;
2023-05-25 13:42:58 +02:00
import ModerationModal from '../modals/ModerationModal' ;
2023-05-06 15:40:30 +02:00
import OfflineIndicator from '../OfflineIndicator' ;
2023-05-24 12:15:43 +02:00
import SettingsModal from '../modals/SettingsModal' ;
2023-07-10 11:15:35 +02:00
import countLinks from '../../utils/countLinks' ;
2023-03-23 15:49:57 +01:00
import getCommentMediaInfo from '../../utils/getCommentMediaInfo' ;
2023-03-20 17:08:05 +01:00
import handleStyleChange from '../../utils/handleStyleChange' ;
2023-06-27 10:35:21 +02:00
import useAnonModeRef from '../../hooks/useAnonModeRef' ;
2023-03-20 17:08:05 +01:00
import useClickForm from '../../hooks/useClickForm' ;
2023-04-04 14:42:22 +02:00
import useError from '../../hooks/useError' ;
2023-05-09 15:58:19 +02:00
import useStateString from '../../hooks/useStateString' ;
2023-05-03 18:32:16 +02:00
import useSuccess from '../../hooks/useSuccess' ;
2023-06-27 10:35:21 +02:00
import useAnonModeStore from '../../hooks/stores/useAnonModeStore' ;
2023-06-16 14:42:23 +02:00
import useGeneralStore from '../../hooks/stores/useGeneralStore' ;
2023-04-24 20:00:11 +00:00
import packageJson from '../../../package.json'
const { version } = packageJson
2023-02-19 16:48:46 +01:00
2023-03-02 18:19:08 +01:00
2023-03-20 17:08:05 +01:00
const Catalog = () => {
2023-03-13 14:29:34 +01:00
const {
2023-04-22 17:37:53 +02:00
captchaResponse , setCaptchaResponse ,
2023-04-10 21:34:37 +02:00
setChallengesArray ,
2023-03-20 17:08:05 +01:00
defaultSubplebbits ,
2023-05-25 13:42:58 +02:00
editedComment ,
2023-05-26 10:10:51 +02:00
setIsAuthorDelete ,
setIsAuthorEdit ,
2023-04-09 20:55:55 +02:00
setIsCaptchaOpen ,
2023-05-25 13:42:58 +02:00
isModerationOpen , setIsModerationOpen ,
2023-03-20 17:08:05 +01:00
isSettingsOpen , setIsSettingsOpen ,
2023-05-25 13:42:58 +02:00
setModeratingCommentCid ,
2023-04-10 21:34:37 +02:00
setPendingComment ,
2023-04-24 15:48:30 +02:00
setPendingCommentIndex ,
2023-04-22 14:33:59 +02:00
setResolveCaptchaPromise ,
2023-03-20 17:08:05 +01:00
selectedAddress , setSelectedAddress ,
2023-03-13 14:29:34 +01:00
selectedStyle ,
2023-06-17 20:24:38 +02:00
setSelectedThread ,
2023-03-20 17:08:05 +01:00
selectedTitle , setSelectedTitle ,
showPostForm ,
2023-04-09 20:55:55 +02:00
showPostFormLink ,
2023-04-08 13:27:17 +02:00
} = useGeneralStore ( state => state );
2023-03-13 14:29:34 +01:00
2023-06-27 10:35:21 +02:00
const { anonymousMode } = useAnonModeStore ();
2023-04-03 15:08:45 +02:00
const nameRef = useRef ();
const subjectRef = useRef ();
const commentRef = useRef ();
const linkRef = useRef ();
2023-05-25 13:42:58 +02:00
const threadMenuRefs = useRef ({});
2023-05-25 17:48:55 +02:00
const postMenuRef = useRef ( null );
const postMenuCatalogRef = useRef ( null );
2023-06-27 10:35:21 +02:00
const selectedThreadCidRef = useRef ( null );
2023-04-03 15:08:45 +02:00
2023-02-19 16:48:46 +01:00
const navigate = useNavigate ();
2023-05-21 14:06:07 +02:00
2023-06-14 16:24:25 +02:00
const [, setNewErrorMessage ] = useError ();
const [, setNewSuccessMessage ] = useSuccess ();
2023-05-21 14:06:07 +02:00
const [ triggerPublishComment , setTriggerPublishComment ] = useState ( false );
2023-02-24 20:57:51 +01:00
const [ prevScrollPos , setPrevScrollPos ] = useState ( 0 );
const [ visible , setVisible ] = useState ( true );
2023-05-25 13:42:58 +02:00
const [ isHoveringOnThread , setIsHoveringOnThread ] = useState ( false );
const [ isModerator , setIsModerator ] = 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 );
const [ menuPosition , setMenuPosition ] = useState ({ top : 0 , left : 0 });
const [ openMenuCid , setOpenMenuCid ] = useState ( null );
2023-06-27 10:35:21 +02:00
const [ executeAnonMode , setExecuteAnonMode ] = useState ( false );
2023-07-19 18:16:01 +02:00
const [ isCreateBoardOpen , setIsCreateBoardOpen ] = useState ( false );
2023-06-16 13:48:40 +02:00
2023-06-10 18:52:45 +02:00
const { feed , hasMore , loadMore } = useFeed ({ subplebbitAddresses : [ ` ${ selectedAddress } ` ], sortType : 'active' });
2023-03-02 18:19:08 +01:00
const { subplebbitAddress } = useParams ();
2023-05-07 16:50:05 +02:00
const subplebbit = useSubplebbit ({ subplebbitAddress : selectedAddress });
2023-05-25 13:42:58 +02:00
const account = useAccount ();
2023-03-25 15:34:10 +01:00
2023-05-15 04:44:33 +00:00
const stateString = useStateString ( subplebbit );
2023-05-07 17:13:19 +02:00
2023-06-27 10:35:21 +02:00
useAnonModeRef ( selectedThreadCidRef , anonymousMode && executeAnonMode );
2023-05-21 14:06:07 +02:00
2023-05-25 13:42:58 +02:00
useEffect (() => {
if ( subplebbit . roles !== undefined ) {
const role = subplebbit . roles [ account ? . author . address ] ? . role ;
if ( role === 'moderator' || role === 'admin' || role === 'owner' ) {
setIsModerator ( true );
} else {
setIsModerator ( false );
}
}
}, [ account ? . author . address , subplebbit . roles ]);
const handleOptionClick = () => {
setOpenMenuCid ( null );
};
2023-05-25 21:03:17 +02:00
const handleOutsideClick = useCallback (( e ) => {
2023-05-25 17:48:55 +02:00
if ( openMenuCid !== null && ! postMenuRef . current . contains ( e . target ) && ! postMenuCatalogRef . current . contains ( e . target )) {
setOpenMenuCid ( null );
}
2023-05-25 21:03:17 +02:00
}, [ openMenuCid , postMenuRef , postMenuCatalogRef ]);
2023-05-25 17:48:55 +02:00
useEffect (() => {
if ( openMenuCid !== null ) {
document . addEventListener ( 'click' , handleOutsideClick );
} else {
document . removeEventListener ( 'click' , handleOutsideClick );
}
return () => {
document . removeEventListener ( 'click' , handleOutsideClick );
};
2023-05-25 21:03:17 +02:00
}, [ openMenuCid , handleOutsideClick ]);
2023-05-25 17:48:55 +02:00
2023-05-25 13:42:58 +02:00
2023-05-21 14:06:07 +02:00
useEffect (() => {
setSelectedAddress ( subplebbitAddress );
}, [ subplebbitAddress , setSelectedAddress ]);
2023-05-09 15:58:19 +02:00
const errorString = useMemo (() => {
if ( subplebbit ? . state === 'failed' ) {
let errorString = 'Failed fetching board "' + selectedAddress + '".' ;
if ( subplebbit . error ) {
errorString += `: ${ subplebbit . error . toString (). slice ( 0 , 300 ) } `
}
return errorString
}
}, [ subplebbit ? . state , subplebbit ? . error , selectedAddress ])
2023-05-21 14:06:07 +02:00
2023-05-09 15:58:19 +02:00
useEffect (() => {
2023-06-14 16:24:25 +02:00
if ( errorString ) {
setNewErrorMessage ( errorString );
2023-05-09 15:58:19 +02:00
}
2023-06-14 16:24:25 +02:00
}, [ errorString , setNewErrorMessage ]);
2023-05-25 13:42:58 +02:00
2023-05-03 18:32:16 +02:00
const { subscribed , subscribe , unsubscribe } = useSubscribe ({ subplebbitAddress : selectedAddress });
2023-07-24 09:59:10 +02:00
2023-03-02 18:19:08 +01:00
useEffect (() => {
const selectedSubplebbit = defaultSubplebbits . find (( subplebbit ) => subplebbit . address === subplebbitAddress );
2023-07-24 09:59:10 +02:00
if ( subplebbitAddress ) {
setSelectedAddress ( subplebbitAddress );
} else if ( subplebbit ? . address ) {
setSelectedAddress ( subplebbit . address )
}
2023-03-02 18:19:08 +01:00
if ( selectedSubplebbit ) {
setSelectedTitle ( selectedSubplebbit . title );
2023-07-24 09:59:10 +02:00
} else if ( subplebbit ? . title ) {
setSelectedTitle ( subplebbit . title );
2023-03-02 18:19:08 +01:00
}
2023-07-24 09:59:10 +02:00
}, [ subplebbitAddress , setSelectedAddress , setSelectedTitle , defaultSubplebbits , subplebbit ? . address , subplebbit ? . title ]);
2023-03-02 18:19:08 +01:00
2023-03-25 14:54:04 +01:00
// mobile navbar scroll effect
2023-03-02 18:19:08 +01:00
useEffect (() => {
2023-03-25 14:54:04 +01:00
const debouncedHandleScroll = debounce (() => {
2023-03-02 18:19:08 +01:00
const currentScrollPos = window . pageYOffset ;
setVisible ( prevScrollPos > currentScrollPos || currentScrollPos < 10 );
setPrevScrollPos ( currentScrollPos );
2023-03-25 14:54:04 +01:00
}, 50 );
window . addEventListener ( 'scroll' , debouncedHandleScroll );
return () => window . removeEventListener ( 'scroll' , debouncedHandleScroll );
2023-03-02 18:19:08 +01:00
}, [ prevScrollPos , visible ]);
2023-02-19 16:48:46 +01:00
const tryLoadMore = async () => {
try { loadMore ()}
catch ( e )
{ await new Promise ( resolve => setTimeout ( resolve , 1000 ))}
2023-04-01 13:59:54 +02:00
};
2023-02-19 16:48:46 +01:00
const onChallengeVerification = ( challengeVerification ) => {
if ( challengeVerification . challengeSuccess === true ) {
2023-05-25 13:42:58 +02:00
if ( challengeVerification . publication ? . cid !== undefined ) {
navigate ( `/p/ ${ subplebbitAddress } /c/ ${ challengeVerification . publication ? . cid } ` );
console . log ( 'challenge success' );
} else {
2023-06-14 16:24:25 +02:00
setNewSuccessMessage ( 'Challenge Success' );
2023-05-25 13:42:58 +02:00
}
2023-02-19 16:48:46 +01:00
}
else if ( challengeVerification . challengeSuccess === false ) {
2023-07-02 21:36:08 +02:00
setNewErrorMessage ( `Challenge Failed, reason: ${ challengeVerification . reason } . Errors: ${ challengeVerification . errors } ` );
console . log ( 'challenge failed' , challengeVerification );
2023-02-19 16:48:46 +01:00
}
2023-04-11 22:27:24 +02:00
};
2023-03-02 18:19:08 +01:00
2023-02-19 16:48:46 +01:00
const onChallenge = async ( challenges , comment ) => {
2023-04-10 21:34:37 +02:00
setPendingComment ( comment );
2023-02-19 16:48:46 +01:00
let challengeAnswers = [];
2023-04-10 21:34:37 +02:00
2023-02-19 16:48:46 +01:00
try {
challengeAnswers = await getChallengeAnswersFromUser ( challenges )
}
catch ( error ) {
2023-07-02 11:45:56 +02:00
setNewErrorMessage ( error . message ); console . log ( error );
2023-02-19 16:48:46 +01:00
}
if ( challengeAnswers ) {
await comment . publishChallengeAnswers ( challengeAnswers )
}
2023-04-03 15:08:45 +02:00
};
2023-04-11 22:27:24 +02:00
2023-04-16 11:21:05 +02:00
2023-04-23 15:14:49 +02:00
useEffect (() => {
setPublishCommentOptions (( prevPublishCommentOptions ) => ({
... prevPublishCommentOptions ,
subplebbitAddress : selectedAddress ,
}));
}, [ selectedAddress ]);
2023-04-11 22:27:24 +02:00
const [ publishCommentOptions , setPublishCommentOptions ] = useState ({
subplebbitAddress : selectedAddress ,
onChallenge ,
2023-04-16 11:21:05 +02:00
onChallengeVerification ,
2023-04-11 22:27:24 +02:00
onError : ( error ) => {
2023-07-02 11:45:56 +02:00
setNewErrorMessage ( error . message ); console . log ( error );
2023-04-11 22:27:24 +02:00
},
});
2023-04-16 11:21:05 +02:00
2023-04-12 14:02:35 +02:00
const { publishComment , index } = usePublishComment ( publishCommentOptions );
useEffect (() => {
if ( index !== undefined ) {
2023-04-24 15:48:30 +02:00
setPendingCommentIndex ( index );
2023-04-12 14:02:35 +02:00
navigate ( `/profile/c/ ${ index } ` );
}
2023-04-27 11:42:51 +02:00
}, [ index , navigate , setPendingCommentIndex ]);
2023-04-16 11:21:05 +02:00
2023-04-12 14:02:35 +02:00
2023-04-27 12:36:21 +02:00
const resetFields = useCallback (() => {
2023-04-25 22:07:33 +02:00
if ( nameRef . current ) {
nameRef . current . value = '' ;
}
if ( subjectRef . current ) {
subjectRef . current . value = '' ;
}
if ( commentRef . current ) {
commentRef . current . value = '' ;
}
if ( linkRef . current ) {
linkRef . current . value = '' ;
}
2023-04-27 12:36:21 +02:00
}, []);
2023-04-12 14:02:35 +02:00
2023-04-11 22:27:24 +02:00
const handleSubmit = async ( event ) => {
event . preventDefault ();
2023-05-11 21:19:57 +02:00
if ( subjectRef . current . value === "" ) {
2023-06-14 16:24:25 +02:00
setNewErrorMessage ( 'Subject field is mandatory' );
2023-05-11 21:19:57 +02:00
return ;
}
2023-04-11 22:27:24 +02:00
setPublishCommentOptions (( prevPublishCommentOptions ) => ({
... prevPublishCommentOptions ,
2023-04-16 11:21:05 +02:00
author : {
displayName : nameRef . current . value || undefined ,
},
2023-04-11 22:27:24 +02:00
title : subjectRef . current . value || undefined ,
content : commentRef . current . value || undefined ,
link : linkRef . current . value || undefined ,
}));
2023-04-27 12:36:21 +02:00
setTriggerPublishComment ( true );
2023-04-11 22:27:24 +02:00
};
2023-06-16 13:48:40 +02:00
2023-06-29 18:10:27 +02:00
const updateSigner = useCallback ( async () => {
if ( anonymousMode ) {
setExecuteAnonMode ( true );
2023-06-27 10:35:21 +02:00
2023-06-29 18:10:27 +02:00
let storedSigners = JSON . parse ( localStorage . getItem ( 'storedSigners' )) || {};
let signer ;
2023-06-27 10:35:21 +02:00
2023-06-29 18:10:27 +02:00
if ( ! storedSigners [ selectedThreadCidRef ]) {
signer = await account ? . plebbit . createSigner ();
storedSigners [ selectedThreadCidRef ] = { privateKey : signer ? . privateKey , address : signer ? . address };
localStorage . setItem ( 'storedSigners' , JSON . stringify ( storedSigners ));
} else {
const signerPrivateKey = storedSigners [ selectedThreadCidRef ]. privateKey ;
2023-06-27 10:35:21 +02:00
2023-06-29 18:10:27 +02:00
try {
signer = await account ? . plebbit . createSigner ({ type : 'ed25519' , privateKey : signerPrivateKey });
} catch ( error ) {
console . log ( error );
2023-06-27 10:35:21 +02:00
}
2023-06-29 18:10:27 +02:00
}
2023-06-27 10:35:21 +02:00
2023-06-29 18:10:27 +02:00
setPublishCommentOptions ( prevPublishCommentOptions => {
const newPublishCommentOptions = {
2023-06-27 10:35:21 +02:00
... prevPublishCommentOptions ,
signer ,
author : {
... prevPublishCommentOptions . author ,
address : signer ? . address
},
2023-06-29 18:10:27 +02:00
};
2023-06-27 10:35:21 +02:00
2023-06-29 18:10:27 +02:00
if ( JSON . stringify ( prevPublishCommentOptions ) !== JSON . stringify ( newPublishCommentOptions )) {
return newPublishCommentOptions ;
}
2023-06-27 10:35:21 +02:00
2023-06-29 18:10:27 +02:00
return prevPublishCommentOptions ;
});
}
}, [ selectedThreadCidRef , anonymousMode , account ]);
useEffect (() => {
2023-06-27 10:35:21 +02:00
updateSigner ();
2023-06-29 18:10:27 +02:00
}, [ updateSigner ]);
2023-06-27 10:35:21 +02:00
2023-04-11 22:27:24 +02:00
useEffect (() => {
2023-05-12 21:32:33 +02:00
if ( publishCommentOptions && triggerPublishComment ) {
2023-04-11 22:27:24 +02:00
( async () => {
2023-06-07 18:26:03 +02:00
await publishComment ();
resetFields ();
2023-04-11 22:27:24 +02:00
})();
2023-06-07 21:24:17 +02:00
setTriggerPublishComment ( false );
2023-06-27 10:35:21 +02:00
setExecuteAnonMode ( false );
2023-04-11 22:27:24 +02:00
}
2023-06-07 18:26:03 +02:00
}, [ publishCommentOptions , triggerPublishComment , publishComment , resetFields ]);
2023-04-11 22:27:24 +02:00
2023-02-19 16:48:46 +01:00
const getChallengeAnswersFromUser = async ( challenges ) => {
2023-04-10 21:34:37 +02:00
setChallengesArray ( challenges );
2023-02-19 16:48:46 +01: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 ;
challengeImg . onload = () => {
2023-03-12 22:07:15 +01:00
setIsCaptchaOpen ( true );
2023-02-19 16:48:46 +01:00
2023-04-16 11:21:05 +02:00
const handleKeyDown = async ( event ) => {
2023-02-19 16:48:46 +01:00
if ( event . key === 'Enter' ) {
2023-04-22 17:37:53 +02:00
const currentCaptchaResponse = captchaResponse ;
2023-04-16 11:21:05 +02:00
resolve ( currentCaptchaResponse );
2023-03-12 22:07:15 +01:00
setIsCaptchaOpen ( false );
2023-02-19 16:48:46 +01:00
document . removeEventListener ( 'keydown' , handleKeyDown );
2023-04-03 15:08:45 +02:00
event . preventDefault ();
2023-02-19 16:48:46 +01:00
}
};
2023-03-12 22:07:15 +01:00
setCaptchaResponse ( '' );
2023-02-19 16:48:46 +01:00
document . addEventListener ( 'keydown' , handleKeyDown );
2023-04-22 14:33:59 +02:00
setResolveCaptchaPromise ( resolve );
2023-02-19 16:48:46 +01:00
};
challengeImg . onerror = () => {
2023-06-14 16:24:25 +02:00
reject ( setNewErrorMessage ( 'Could not load challenges' ));
2023-02-19 16:48:46 +01:00
};
});
};
2023-05-25 13:42:58 +02:00
const [ publishCommentEditOptions , setPublishCommentEditOptions ] = useState ({
commentCid : commentCid ,
content : editedComment || undefined ,
subplebbitAddress : selectedAddress || subplebbitAddress ,
onChallenge ,
onChallengeVerification ,
onError : ( error ) => {
2023-07-02 11:45:56 +02:00
setNewErrorMessage ( error . message ); console . log ( error );
2023-05-25 13:42:58 +02:00
},
});
2023-06-14 16:24:25 +02:00
const { publishCommentEdit } = usePublishCommentEdit ( publishCommentEditOptions );
2023-05-25 13:42:58 +02:00
2023-06-14 17:07:00 +02:00
const handleAuthorDeleteClick = ( comment ) => {
handleOptionClick ( comment . cid );
2023-05-25 13:42:58 +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 = {() => {
2023-05-26 10:10:51 +02:00
setIsAuthorDelete ( true );
setIsAuthorEdit ( false );
2023-05-25 13:42:58 +02:00
setPublishCommentEditOptions ( prevOptions => ({
... prevOptions ,
2023-07-02 21:36:08 +02:00
commentCid : comment . cid ,
subplebbitAddress : comment . subplebbitAddress ,
2023-05-25 13:42:58 +02:00
deleted : true ,
}));
setTriggerPublishCommentEdit ( true );
onClose ();
}}
>
Yes
</ button >
</ div >
</ div >
</ AuthorDeleteAlert >
);
}
});
};
const handleAuthorEditClick = ( comment ) => {
handleOptionClick ( comment . cid );
2023-05-26 10:10:51 +02:00
setIsAuthorEdit ( true );
setIsAuthorDelete ( false );
2023-05-25 13:42:58 +02:00
setCommentCid ( comment . cid );
setOriginalCommentContent ( comment . content );
setIsEditModalOpen ( true );
}
useEffect (() => {
setPublishCommentEditOptions (( prevOptions ) => ({
... prevOptions ,
commentCid : commentCid ,
content : editedComment || undefined ,
}));
}, [ commentCid , editedComment ]);
useEffect (() => {
if ( editedComment !== '' ) {
setTriggerPublishCommentEdit ( true );
}
}, [ editedComment ]);
useEffect (() => {
if ( publishCommentEditOptions && triggerPublishCommentEdit ) {
( async () => {
await publishCommentEdit ();
setTriggerPublishCommentEdit ( false );
})();
}
}, [ publishCommentEditOptions , triggerPublishCommentEdit , publishCommentEdit ]);
2023-04-03 15:08:45 +02:00
// mobile navbar board select functionality
2023-02-27 18:16:47 +01:00
const handleSelectChange = ( event ) => {
const selected = event . target . value ;
2023-05-03 11:01:41 +02:00
if ( selected === 'subscriptions' ) {
2023-05-07 17:22:55 +02:00
navigate ( `/p/subscriptions` );
2023-05-03 11:01:41 +02:00
return ;
2023-05-16 16:37:50 +02:00
} else if ( selected === 'all' ) {
navigate ( `/p/all` );
return ;
2023-05-03 11:01:41 +02:00
}
2023-02-27 18:16:47 +01:00
const selectedTitle = defaultSubplebbits . find (( subplebbit ) => subplebbit . address === selected ). title ;
setSelectedTitle ( selectedTitle );
setSelectedAddress ( selected );
2023-04-08 22:30:44 +02:00
navigate ( `/p/ ${ selected } ` );
2023-02-19 16:48:46 +01:00
};
2023-05-03 18:32:16 +02:00
const handleSubscribe = async () => {
try {
if ( subscribed === false ) {
await subscribe ( selectedAddress );
} else if ( subscribed === true ) {
await unsubscribe ( selectedAddress );
}
} catch ( error ) {
2023-07-02 11:45:56 +02:00
setNewErrorMessage ( error . message ); console . log ( error );
2023-05-03 18:32:16 +02:00
}
};
2023-03-02 18:19:08 +01:00
2023-05-07 16:50:05 +02:00
2023-02-19 16:48:46 +01:00
return (
2023-04-21 10:47:39 +02:00
<>
< Helmet >
< title >{(( selectedTitle ? selectedTitle : selectedAddress ) + " - Catalog - plebchan" )}</ title >
</ Helmet >
< Container >
2023-07-19 18:16:01 +02:00
< CreateBoardModal
selectedStyle = { selectedStyle }
isOpen = { isCreateBoardOpen }
closeModal = {() => setIsCreateBoardOpen ( false )} />
2023-04-21 10:47:39 +02:00
< SettingsModal
selectedStyle = { selectedStyle }
isOpen = { isSettingsOpen }
closeModal = {() => setIsSettingsOpen ( false )} />
2023-05-25 13:42:58 +02:00
< ModerationModal
selectedStyle = { selectedStyle }
isOpen = { isModerationOpen }
2023-05-30 11:24:10 +02:00
closeModal = {() => { setIsModerationOpen ( false ); setDeletePost ( false )}}
2023-05-25 13:42:58 +02:00
deletePost = { deletePost } />
< EditModal
selectedStyle = { selectedStyle }
isOpen = { isEditModalOpen }
closeModal = {() => setIsEditModalOpen ( false )}
originalCommentContent = { originalCommentContent } />
2023-04-21 10:47:39 +02:00
< NavBar selectedStyle = { selectedStyle }>
<>
2023-05-01 18:41:10 +02:00
< span className = "boardList" >
2023-05-04 15:50:35 +02:00
[
2023-07-14 14:32:33 +02:00
< Link to = { `/p/all` } onClick = {() => window . scrollTo ( 0 , 0 )}> All </ Link >
2023-06-17 20:24:38 +02:00
/
2023-07-14 14:32:33 +02:00
< Link to = { `/p/subscriptions` } onClick = {() => window . scrollTo ( 0 , 0 )}> Subscriptions </ Link >
2023-05-04 15:50:35 +02:00
] & nbsp ;[
2023-05-01 18:41:10 +02:00
{ defaultSubplebbits . map (( subplebbit , index ) => (
2023-04-21 10:47:39 +02:00
< span className = "boardList" key = { `span- ${ subplebbit . address } ` }>
2023-05-01 18:41:10 +02:00
{ index === 0 ? null : "\u00a0" }
< Link to = { `/p/ ${ subplebbit . address } ` } key = { `a- ${ subplebbit . address } ` } onClick = {() => {
2023-04-21 10:47:39 +02:00
setSelectedTitle ( subplebbit . title );
setSelectedAddress ( subplebbit . address );
}}
>{ subplebbit . title ? subplebbit . title : subplebbit . address }</ Link >
2023-05-01 18:41:10 +02:00
{ index !== defaultSubplebbits . length - 1 ? " /" : null }
2023-04-21 10:47:39 +02:00
</ span >
))}
2023-05-04 15:50:35 +02:00
]
</ span >
2023-05-01 21:58:19 +02:00
< span className = "nav" >
2023-07-19 18:16:01 +02:00
[
2023-05-27 12:33:25 +02:00
< span id = "button-span" style = {{ cursor : 'pointer' }} onClick = {
2023-07-19 18:16:01 +02:00
() => {
window . electron && window . electron . isElectron ? (
setIsCreateBoardOpen ( true )
) : (
alert (
2023-07-20 10:00:58 +02:00
'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-04-30 17:37:19 +02:00
)
2023-07-19 18:16:01 +02:00
)
}
2023-05-27 12:33:25 +02:00
}> Create Board </ span >
2023-04-30 17:37:19 +02:00
]
2023-02-19 16:48:46 +01:00
[
2023-04-08 22:30:44 +02:00
< Link to = { `/p/ ${ selectedAddress } /catalog/settings` } onClick = {() => setIsSettingsOpen ( true )}> Settings </ Link >
2023-04-21 10:47:39 +02:00
]
[
2023-05-27 12:55:16 +02:00
< Link to = "/" > Home </ Link >
2023-04-21 10:47:39 +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 = { selectedAddress } onChange = { handleSelectChange }>
< option value = "all" > All </ option >
2023-06-17 20:24:38 +02:00
< option value = "subscriptions" > Subscriptions </ option >
2023-05-27 11:04:23 +02:00
{ defaultSubplebbits . map ( subplebbit => (
< option key = { `option- ${ subplebbit . address } ` } value = { subplebbit . address }
>{ subplebbit . title ? subplebbit . title : subplebbit . address }</ option >
))}
</ select >
2023-05-29 15:48:09 +02:00
< span id = "button-span" style = {{ cursor : 'pointer' }} onClick = {
2023-04-30 17:37:19 +02:00
() => alert (
2023-07-20 10:00:58 +02:00
'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-04-30 17:37:19 +02:00
)
2023-05-27 11:04:23 +02:00
}> Create Board </ span >
</ div >
< div className = "page-jump" >
< Link to = { `/p/ ${ selectedAddress } /catalog/settings` } onClick = {() => setIsSettingsOpen ( true )}> Settings </ Link >
& nbsp ;
< Link to = "/" onClick = {() => { handleStyleChange ({ target : { value : "Yotsuba" }}); window . scrollTo ( 0 , 0 );}}> Home </ Link >
</ div >
2023-04-21 10:47:39 +02:00
</ div >
2023-02-23 16:45:29 +01:00
</ div >
2023-04-21 10:47:39 +02:00
< div id = "separator-mobile" > & nbsp ;</ div >
< div id = "separator-mobile" > & nbsp ;</ div >
</>
</ NavBar >
< Header selectedStyle = { selectedStyle }>
<>
< div className = "banner" >
< ImageBanner />
</ div >
<>
2023-06-27 16:42:39 +02:00
< div className = "board-title" >{ subplebbit . title ?? null }</ div >
< div className = "board-address" > p / { subplebbit . address }
2023-05-08 21:10:42 +02:00
< OfflineIndicator
2023-06-27 16:42:39 +02:00
address = { subplebbit . address }
2023-05-08 21:10:42 +02:00
className = "offline"
tooltipPlace = "top" />
</ div >
2023-04-21 10:47:39 +02:00
</>
</>
</ Header >
< Break selectedStyle = { selectedStyle } />
< PostForm selectedStyle = { selectedStyle }>
< PostFormLink id = "post-form-link" showPostFormLink = { showPostFormLink } selectedStyle = { selectedStyle } >
< div id = "post-form-link-desktop" >
[
2023-04-26 15:17:26 +02:00
< Link to = { `/p/ ${ subplebbitAddress } /catalog/post` } onClick = { useClickForm ()} onMouseOver = {( event ) => event . target . style . cursor = 'pointer' }> Start a New Thread </ Link >
2023-04-21 10:47:39 +02:00
]
</ div >
< div id = "post-form-link-mobile" >
< span className = "btn-wrap" >
2023-04-26 15:17:26 +02:00
< Link to = { `/p/ ${ subplebbitAddress } /catalog/post` } onClick = { useClickForm ()} onMouseOver = {( event ) => event . target . style . cursor = 'pointer' }> Start a New Thread </ Link >
2023-04-21 10:47:39 +02:00
</ span >
</ div >
</ PostFormLink >
< PostFormTable id = "post-form" showPostForm = { showPostForm } selectedStyle = { selectedStyle } className = "post-form" >
< tbody >
< tr data - type = "Name" >
< td id = "td-name" > Name </ td >
< td >
2023-06-27 10:35:21 +02:00
{ account && account ? . author && account ? . author . displayName ? (
< input name = "name" type = "text" tabIndex = { 1 } value = { account ? . author ? . displayName } ref = { nameRef } disabled />
2023-05-26 17:25:49 +02:00
) : (
< input name = "name" type = "text" placeholder = "Anonymous" tabIndex = { 1 } ref = { nameRef } />
)}
2023-04-21 10:47:39 +02:00
</ td >
</ tr >
< tr data - type = "Subject" >
< td > Subject </ td >
< td >
< input name = "sub" type = "text" tabIndex = { 3 } ref = { subjectRef }/>
< input id = "post-button" type = "submit" value = "Post" tabIndex = { 6 }
onClick = { handleSubmit } />
</ td >
</ tr >
< tr data - type = "Comment" >
< td > Comment </ td >
< td >
< textarea name = "com" cols = "48" rows = "4" tabIndex = { 4 } wrap = "soft" ref = { commentRef } />
</ td >
</ tr >
< tr data - type = "File" >
< td > Embed File </ td >
< td >
< input name = "embed" type = "text" tabIndex = { 7 } placeholder = "Paste link" ref = { linkRef } />
< button id = "t-help" type = "button" onClick = {
() => alert ( "- Embedding media is optional, posts can be text-only. \n- A CAPTCHA challenge will appear after posting. \n- The CAPTCHA is case-sensitive." )
} data - tip = "Help" > ? </ button >
</ td >
</ tr >
</ tbody >
</ PostFormTable >
</ PostForm >
< TopBar selectedStyle = { selectedStyle }>
< hr />
< span className = "style-changer" >
Style :
< 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" >
2023-02-24 18:13:02 +01:00
[
2023-05-10 22:20:59 +02:00
< Link to = { `/p/ ${ selectedAddress } ` } onClick = {()=> { window . scrollTo ( 0 , 0 )}}> Return </ Link >
2023-02-24 18:13:02 +01:00
]
</ div >
2023-07-13 15:58:04 +02:00
{ subplebbit . state === "succeeded" ? (
2023-05-01 19:01:53 +02:00
<>
2023-06-17 20:24:38 +02:00
< span className = "subscribe-button-desktop" >
[
< span id = "subscribe" style = {{ cursor : 'pointer' }}>
< span onClick = {() => handleSubscribe ()}>
2023-06-16 14:42:23 +02:00
{ subscribed ? "Unsubscribe" : "Subscribe" }
</ span >
2023-06-17 20:24:38 +02:00
</ span >
]
</ span >
< span className = "subscribe-button-mobile" >
< span className = "btn-wrap" onClick = {() => handleSubscribe ()}>
{ subscribed ? "Unsubscribe" : "Subscribe" }
</ span >
</ span >
2023-05-27 11:04:23 +02:00
</>
2023-05-01 19:01:53 +02:00
) : (
< div id = "stats" style = {{ float : "right" , marginTop : "5px" }}>
2023-05-16 12:40:29 +02:00
< span className = { stateString ? "ellipsis" : "" }>{ stateString }</ span >
2023-05-01 19:01:53 +02:00
</ div >
)}
2023-04-21 10:47:39 +02:00
< div id = "return-button-mobile" >
< span className = "btn-wrap-catalog btn-wrap" >
2023-05-10 22:20:59 +02:00
< Link to = { `/p/ ${ selectedAddress } ` } onClick = {()=> { window . scrollTo ( 0 , 0 )}}> Return </ Link >
2023-02-24 18:13:02 +01:00
</ span >
</ div >
2023-04-21 10:47:39 +02:00
< hr />
</ TopBar >
2023-05-08 21:10:42 +02:00
< Tooltip id = "tooltip" className = "tooltip" />
2023-04-21 10:47:39 +02:00
< Threads selectedStyle = { selectedStyle }>
2023-05-09 16:30:02 +02:00
{ subplebbit ? . state === "failed" ? (
null
2023-04-21 10:47:39 +02:00
) : (
2023-07-13 15:58:04 +02:00
subplebbit . state === "succeeded" ? (
2023-06-17 12:51:30 +02:00
< InfiniteScroll
pageStart = { 0 }
loadMore = { tryLoadMore }
hasMore = { hasMore }
>
{ subplebbit . rules ? (
< div className = 'thread'
onMouseOver = {() => setIsHoveringOnThread ( 'rules' )}
onMouseLeave = {() => setIsHoveringOnThread ( '' )}>
< BoardForm selectedStyle = { selectedStyle } style = {{ all : 'unset' }}>
2023-07-10 11:15:35 +02:00
< div className = 'meta' title = "(R)eplies / (L)ink Replies" >
R :& nbsp ;< b > 0 </ b > & nbsp ; / L: <b>0</b>
2023-06-17 12:51:30 +02:00
< div className = 'thread-icons'
style = {{ position : 'absolute' , top : '-2px' , right : '15px' }}>
2023-06-28 18:23:22 +02:00
< span className = "thread-icon sticky-icon" title = "Sticky"
style = {{
imageRendering : "pixelated" ,}} />
< span className = "thread-icon closed-icon" title = "Closed"
style = {{
imageRendering : "pixelated" ,}} />
2023-06-17 12:51:30 +02:00
</ div >
< PostMenu
style = {{ display : isHoveringOnThread === "rules" ? 'inline-block' : 'none' ,
position : 'absolute' , lineHeight : '1em' , marginTop : '-1px' , outline : 'none' ,
zIndex : '999' }}
title = "Post menu"
ref = { el => {
threadMenuRefs . current [ "rules" ] = el ;
postMenuRef . current = el ;
}}
className = 'post-menu-button'
id = 'post-menu-button-catalog'
rotated = { openMenuCid === "rules" }
onClick = {( event ) => {
event . stopPropagation ();
const rect = threadMenuRefs . current [ "rules" ]. getBoundingClientRect ();
setMenuPosition ({ top : rect . top + window . scrollY , left : rect . left });
setOpenMenuCid ( prevCid => ( prevCid === "rules" ? null : "rules" ));
}}
>
▶
</ PostMenu >
2023-05-25 13:42:58 +02:00
</ div >
{ createPortal (
< PostMenuCatalog selectedStyle = { selectedStyle }
2023-05-25 17:48:55 +02:00
ref = { el => { postMenuCatalogRef . current = el }}
onClick = {( event ) => event . stopPropagation ()}
2023-05-25 13:42:58 +02:00
style = {{ position : "absolute" ,
top : menuPosition . top + 7 ,
left : menuPosition . left }}>
2023-06-17 12:51:30 +02:00
< div className = { `post-menu-thread post-menu-thread- ${ "rules" } ` }
style = {{ display : openMenuCid === "rules" ? 'block' : 'none' }}
2023-05-25 13:42:58 +02:00
>
< ul className = "post-menu-catalog" >
2023-06-17 12:51:30 +02:00
< li onClick = {() => handleOptionClick ( "rules" )}> Hide thread </ li >
{ /* {isModerator ? (
2023-05-25 13:42:58 +02:00
<>
2023-06-17 12:51:30 +02:00
change rules
2023-05-25 13:42:58 +02:00
</>
2023-06-17 12:51:30 +02:00
) : null} */ }
2023-05-25 13:42:58 +02:00
</ ul >
</ div >
</ PostMenuCatalog >, document . body
)}
</ BoardForm >
2023-06-27 21:06:30 +02:00
< Link style = {{ all : "unset" , cursor : "pointer" }} to = { `/p/ ${ selectedAddress } /rules` }>
2023-06-17 12:51:30 +02:00
< div className = "teaser" >
< b > Rules </ b >
{ ": " + subplebbit . rules . map (( rule , index ) => ` ${ index + 1 } . ${ rule } ` ). join ( ' ' )}
</ div >
</ Link >
2023-03-26 14:43:58 +02:00
</ div >
2023-06-17 12:51:30 +02:00
) : null }
{ subplebbit . description ? (
< div className = 'thread'
onMouseOver = {() => setIsHoveringOnThread ( 'description' )}
onMouseLeave = {() => setIsHoveringOnThread ( '' )}>
2023-06-27 21:06:30 +02:00
< Link style = {{ all : 'unset' , cursor : 'pointer' }} to = { `/p/ ${ selectedAddress } /description` }>
2023-06-17 12:51:30 +02:00
{ subplebbit . suggested ? . avatarUrl ? (
< img className = 'card'
src = { subplebbit . suggested . avatarUrl } alt = "board avatar" />
) : null }
</ Link >
{ subplebbit . suggested ? . avatarUrl ? (
< div className = 'thread-icons' >
2023-06-28 18:23:22 +02:00
< span className = "thread-icon sticky-icon" title = "Sticky"
style = {{
imageRendering : "pixelated" ,}} />
< span className = "thread-icon closed-icon" title = "Closed"
style = {{
imageRendering : "pixelated" ,}} />
2023-06-17 12:51:30 +02:00
</ div >
) : null }
< BoardForm selectedStyle = { selectedStyle } style = {{ all : 'unset' }}>
2023-07-10 11:15:35 +02:00
< div className = 'meta' title = "(R)eplies / (L)ink Replies" >
R :& nbsp ;< b > 0 </ b > & nbsp ; / L: <b>0</b>
2023-06-17 12:51:30 +02:00
{ subplebbit . suggested ? . avatarUrl ? null : (
< div className = 'thread-icons'
style = {{ position : 'absolute' , top : '-2px' , right : '15px' }}>
2023-06-28 18:23:22 +02:00
< span className = "thread-icon sticky-icon" title = "Sticky"
style = {{
imageRendering : "pixelated" ,}} />
< span className = "thread-icon closed-icon" title = "Closed"
style = {{
imageRendering : "pixelated" ,}} />
2023-06-17 12:51:30 +02:00
</ div >
)}
< PostMenu
style = {{ display : isHoveringOnThread === "description" ? 'inline-block' : 'none' ,
position : 'absolute' , lineHeight : '1em' , marginTop : '-1px' , outline : 'none' ,
zIndex : '999' }}
title = "Post menu"
ref = { el => {
threadMenuRefs . current [ "description" ] = el ;
postMenuRef . current = el ;
}}
className = 'post-menu-button'
id = 'post-menu-button-catalog'
rotated = { openMenuCid === "description" }
onClick = {( event ) => {
event . stopPropagation ();
const rect = threadMenuRefs . current [ "description" ]. getBoundingClientRect ();
setMenuPosition ({ top : rect . top + window . scrollY , left : rect . left });
setOpenMenuCid ( prevCid => ( prevCid === "description" ? null : "description" ));
}}
>
▶
</ 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- ${ "description" } ` }
style = {{ display : openMenuCid === "description" ? 'block' : 'none' }}
>
< ul className = "post-menu-catalog" >
< li onClick = {() => handleOptionClick ( "description" )}> Hide thread </ li >
{ /* {isModerator ? (
<>
change description
</>
) : null} */ }
{ subplebbit . suggested ? . avatarUrl ? (
< li
onMouseOver = {() => { setIsImageSearchOpen ( true )}}
onMouseLeave = {() => { setIsImageSearchOpen ( false )}}>
Image search »
< ul className = "dropdown-menu post-menu-catalog"
style = {{ display : isImageSearchOpen ? 'block' : 'none' }}>
< li onClick = {() => handleOptionClick ( "description" )}>
< a
href = { `https://lens.google.com/uploadbyurl?url= ${ subplebbit . suggested . avatarUrl } ` }
target = "_blank" rel = "noreferrer"
> Google </ a >
</ li >
< li onClick = {() => handleOptionClick ( "description" )}>
< a
href = { `https://yandex.com/images/search?url= ${ subplebbit . suggested . avatarUrl } ` }
target = "_blank" rel = "noreferrer"
> Yandex </ a >
</ li >
< li onClick = {() => handleOptionClick ( "description" )}>
< a
href = { `https://saucenao.com/search.php?url= ${ subplebbit . suggested . avatarUrl } ` }
target = "_blank" rel = "noreferrer"
> SauceNAO </ a >
</ li >
</ ul >
</ li >
) : null }
</ ul >
</ div >
</ PostMenuCatalog >, document . body
)}
</ BoardForm >
2023-06-27 21:06:30 +02:00
< Link style = {{ all : "unset" , cursor : "pointer" }} to = { `/p/ ${ selectedAddress } /description` }
2023-06-17 12:51:30 +02:00
onClick = {() => setSelectedThread ( "description" )}>
< div className = "teaser" >
< b > Welcome to { subplebbit . title || subplebbit . address }</ b >
{ ": " + subplebbit . description }
</ div >
</ Link >
</ div >
) : null }
{ feed . map (( thread , index ) => {
const commentMediaInfo = getCommentMediaInfo ( thread );
const fallbackImgUrl = "assets/filedeleted-res.gif" ;
2023-07-10 11:15:35 +02:00
const linkCount = countLinks ( thread );
2023-06-17 12:51:30 +02:00
return (
< div key = { `thread- ${ index } ` } className = "thread"
onMouseOver = {() => { setIsHoveringOnThread ( thread . cid )}}
onMouseLeave = {() => { setIsHoveringOnThread ( '' )}}>
{ commentMediaInfo ? . url ? (
< Link style = {{ all : "unset" , cursor : "pointer" }} key = { `link- ${ index } ` } to = { `/p/ ${ selectedAddress } /c/ ${ thread . cid } ` }
onClick = {() => setSelectedThread ( thread . cid )}>
{ commentMediaInfo ? . type === "webpage" ? (
thread . thumbnailUrl ? (
< img className = "card" key = { `img- ${ index } ` }
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- ${ index } ` }
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- ${ index } ` }
src = { commentMediaInfo . url }
alt = { commentMediaInfo . type }
onError = {( e ) => e . target . src = fallbackImgUrl } />
) : null }
{ commentMediaInfo ? . type === "audio" ? (
< audio className = "card" controls
key = { `fti- ${ index } ` }
src = { commentMediaInfo . url }
alt = { commentMediaInfo . type }
onError = {( e ) => e . target . src = fallbackImgUrl } />
) : null }
</ Link >
) : null }
{( commentMediaInfo && (
commentMediaInfo . type === 'image' ||
commentMediaInfo . type === 'video' ||
( commentMediaInfo . type === 'webpage' &&
commentMediaInfo . thumbnail ))) ? (
< div key = { `ti- ${ index } ` } className = "thread-icons" >
{ thread . pinned ? (
2023-06-28 18:23:22 +02:00
< span key = { `si- ${ index } ` } className = "thread-icon sticky-icon" title = "Sticky"
style = {{
imageRendering : "pixelated" ,}} />
2023-06-17 12:51:30 +02:00
) : null }
{ thread . locked ? (
2023-06-28 18:23:22 +02:00
< span key = { `li- ${ index } ` } className = "thread-icon closed-icon" title = "Closed"
style = {{
imageRendering : "pixelated" ,}} />
2023-06-17 12:51:30 +02:00
) : null }
</ div >
) : null }
< 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-06-17 12:51:30 +02:00
{( commentMediaInfo && (
commentMediaInfo . type === 'image' ||
commentMediaInfo . type === 'video' ||
( commentMediaInfo . type === 'webpage' &&
commentMediaInfo . thumbnail ))) ? null : (
< div className = 'thread-icons'
style = {{ position : 'absolute' , top : '-2px' , right : '15px' }}>
{ thread . pinned ? (
2023-06-28 18:23:22 +02:00
< span key = { `si- ${ index } ` } className = "thread-icon sticky-icon" title = "Sticky"
style = {{
imageRendering : "pixelated" ,}} />
2023-06-17 12:51:30 +02:00
) : null }
{ thread . locked ? (
2023-06-28 18:23:22 +02:00
< span key = { `li- ${ index } ` } className = "thread-icon closed-icon" title = "Closed"
style = {{
imageRendering : "pixelated" ,}} />
2023-06-17 12:51:30 +02:00
) : null }
</ div >
)}
< 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 >
</ 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 >
2023-07-09 16:03:46 +02:00
< VerifiedAuthor commentCid = { thread . cid }>{({ authorAddress }) => (
2023-06-17 12:51:30 +02:00
<>
2023-07-09 16:03:46 +02:00
{ 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 = {() => {
setModeratingCommentCid ( thread . cid )
setIsModerationOpen ( true );
handleOptionClick ( thread . cid );
setDeletePost ( true );
}}>
Delete post
</ li >
)}
< li
onClick = {() => {
setModeratingCommentCid ( thread . cid )
setIsModerationOpen ( true );
handleOptionClick ( thread . cid );
}}>
Mod tools
</ li >
</>
) : null }
2023-06-17 12:51:30 +02:00
</>
2023-07-09 16:03:46 +02:00
)}</ VerifiedAuthor >
2023-06-17 12:51:30 +02:00
{( 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- ${ index } ` } to = { `/p/ ${ selectedAddress } /c/ ${ thread . cid } ` }
onClick = {() => setSelectedThread ( thread . cid )}>
< div key = { `t- ${ index } ` } className = "teaser" >
< b key = { `b2- ${ index } ` }>{ thread . title ? ` ${ thread . title } ` : null }</ b >
{ thread . content ? `: ${ thread . content } ` : null }
</ div >
</ Link >
</ div >
)})}
</ InfiniteScroll >
2023-05-09 16:30:02 +02:00
) : (< CatalogLoader />)
)}
2023-04-21 10:47:39 +02:00
</ Threads >
2023-04-24 13:09:59 +02:00
< 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 :
< 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-05-01 21:58:19 +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-06-17 20:24:38 +02:00
/
2023-07-14 14:32:33 +02:00
< Link to = { `/p/subscriptions` } onClick = {() => window . scrollTo ( 0 , 0 )}> Subscriptions </ Link >
2023-05-03 11:01:41 +02:00
] & nbsp ;
2023-05-01 21:58:19 +02:00
</ span >
{ 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 >
))}
2023-04-24 13:09:59 +02:00
< span className = "nav" >
2023-05-01 21:58:19 +02:00
[
2023-07-19 18:16:01 +02:00
< span id = "button-span" style = {{ cursor : 'pointer' }} onClick = {
() => {
window . electron && window . electron . isElectron ? (
setIsCreateBoardOpen ( true )
) : (
alert (
2023-07-20 10:00:58 +02:00
'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-01 21:58:19 +02:00
)
2023-07-19 18:16:01 +02:00
)
}
}> Create Board </ span >
2023-05-01 21:58:19 +02:00
]
2023-04-24 13:09:59 +02:00
[
2023-05-01 21:58:19 +02:00
< Link to = { `/p/ ${ selectedAddress } /catalog/settings` } onClick = {() => setIsSettingsOpen ( true )}> Settings </ Link >
2023-04-24 13:09:59 +02:00
]
[
< Link to = "/" onClick = {() => handleStyleChange ({ target : { value : "Yotsuba" }}
)}> Home </ Link >
]
</ span >
</>
</ NavBar >
< div id = "version" >
2023-04-24 20:00:11 +00:00
plebchan v { version }. GPL - 2.0
2023-04-24 13:09:59 +02:00
</ div >
< div className = "footer-links"
2023-04-24 17:53:09 +00:00
style = {{
textAlign : "center" ,
fontSize : "x-small" ,
fontFamily : "arial" ,
marginTop : "5px" ,
marginBottom : "15px" ,
}}>
< a style = {{ textDecoration : 'underline' }} href = "https://plebbit.com" target = "_blank" rel = "noopener noreferrer" > About </ a >
2023-04-24 13:09:59 +02:00
& nbsp ; • & nbsp ;
2023-04-24 20:06:35 +00:00
< a style = {{ textDecoration : 'underline' }} href = "https://github.com/plebbit/plebchan/releases/latest" target = "_blank" rel = "noopener noreferrer" > App </ a >
2023-04-24 13:09:59 +02:00
& nbsp ; • & nbsp ;
2023-04-24 20:06:35 +00:00
< a style = {{ textDecoration : 'underline' }} href = "https://twitter.com/plebchan_eth" target = "_blank" rel = "noopener noreferrer" > Twitter </ a >
2023-04-24 13:09:59 +02:00
& nbsp ; • & nbsp ;
2023-04-24 17:53:09 +00:00
< a style = {{ textDecoration : 'underline' }} href = "https://t.me/plebbit" target = "_blank" rel = "noopener noreferrer" > Telegram </ a >
2023-04-24 13:09:59 +02:00
</ div >
</ Footer >
2023-04-21 10:47:39 +02:00
</ Container >
</>
2023-02-19 16:48:46 +01:00
);
}
export default Catalog ;