2023-07-01 13:23:03 +02:00
import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
2023-05-25 17:48:55 +02:00
import { createPortal } from 'react-dom' ;
2023-04-21 10:47:39 +02:00
import { Helmet } from 'react-helmet-async' ;
2023-03-20 17:08:05 +01:00
import { Link , useNavigate , useParams } from 'react-router-dom' ;
2023-05-22 18:56:34 +02:00
import { confirmAlert } from 'react-confirm-alert' ;
2023-03-23 15:49:57 +01:00
import { Tooltip } from 'react-tooltip' ;
2023-05-22 18:56:34 +02:00
import { useAccount , useAccountComments , useComment , usePublishComment , usePublishCommentEdit , useSubplebbit } from '@plebbit/plebbit-react-hooks' ;
2023-04-25 14:34:48 +02:00
import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/utils'
2023-03-25 14:54:04 +01:00
import { debounce } from 'lodash' ;
2023-05-24 12:15:43 +02:00
import { Container , NavBar , Header , Break , PostForm , PostFormTable , PostMenu } from '../styled/views/Board.styled' ;
import { ReplyFormLink , TopBar , BottomBar , BoardForm , Footer , AuthorDeleteAlert } from '../styled/views/Thread.styled' ;
2023-05-25 17:48:55 +02:00
import { PostMenuCatalog } from '../styled/views/Catalog.styled' ;
2023-05-24 12:15:43 +02:00
import EditModal from '../modals/EditModal' ;
2023-05-31 15:44:15 +02:00
import EditLabel from '../EditLabel' ;
2023-03-19 18:30:07 +01:00
import ImageBanner from '../ImageBanner' ;
2023-05-24 12:15:43 +02:00
import ModerationModal from '../modals/ModerationModal' ;
2023-05-06 15:40:30 +02:00
import OfflineIndicator from '../OfflineIndicator' ;
2023-06-15 14:17:33 +02:00
import PendingLabel from '../PendingLabel' ;
2023-03-29 13:37:36 +02:00
import Post from '../Post' ;
2023-03-19 18:30:07 +01:00
import PostLoader from '../PostLoader' ;
2023-06-03 16:33:59 +02:00
import PostOnHover from '../PostOnHover' ;
2023-06-01 10:43:17 +02:00
import StateLabel from '../StateLabel' ;
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-24 12:15:43 +02:00
import ReplyModal from '../modals/ReplyModal' ;
import SettingsModal from '../modals/SettingsModal' ;
2023-04-17 10:37:58 +02:00
import findShortParentCid from '../../utils/findShortParentCid' ;
2023-03-23 15:49:57 +01:00
import getCommentMediaInfo from '../../utils/getCommentMediaInfo' ;
import getDate from '../../utils/getDate' ;
2023-04-20 17:20:26 +02:00
import handleAddressClick from '../../utils/handleAddressClick' ;
2023-04-29 17:44:27 +02:00
import handleImageClick from '../../utils/handleImageClick' ;
2023-04-13 17:08:35 +02:00
import handleQuoteClick from '../../utils/handleQuoteClick' ;
2023-06-01 21:41:48 +02:00
import handleQuoteHover from '../../utils/handleQuoteHover' ;
2023-03-20 17:08:05 +01:00
import handleStyleChange from '../../utils/handleStyleChange' ;
2023-06-01 21:41:48 +02:00
import removeHighlight from '../../utils/removeHighlight' ;
2023-06-16 13:48:40 +02:00
import useAnonMode from '../../hooks/useAnonMode' ;
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-18 22:32:32 +02:00
import useSuccess from '../../hooks/useSuccess' ;
2023-06-16 14:42:23 +02:00
import useAnonModeStore from '../../hooks/stores/useAnonModeStore' ;
import useGeneralStore from '../../hooks/stores/useGeneralStore' ;
import packageJson from '../../../package.json'
2023-07-31 08:59:17 +02:00
const { version } = packageJson
2023-02-12 21:20:08 +01:00
2023-03-02 21:51:06 +01:00
2023-03-20 17:08:05 +01:00
const Thread = () => {
2023-03-13 14:29:34 +01:00
const {
2023-03-20 17:08:05 +01:00
captchaResponse , setCaptchaResponse ,
2023-04-10 21:34:37 +02:00
setChallengesArray ,
2023-03-20 17:08:05 +01:00
defaultSubplebbits ,
2023-05-23 14:56:25 +02:00
editedComment ,
2023-05-26 10:10:51 +02:00
setIsAuthorDelete ,
setIsAuthorEdit ,
2023-04-09 20:55:55 +02:00
setIsCaptchaOpen ,
2023-05-19 18:25:01 +02:00
isModerationOpen , setIsModerationOpen ,
2023-03-20 17:08:05 +01:00
isSettingsOpen , setIsSettingsOpen ,
2023-05-19 18:25:01 +02:00
setModeratingCommentCid ,
2023-06-24 11:44:36 +02:00
setReplyQuoteCid ,
2023-04-22 14:33:59 +02:00
setResolveCaptchaPromise ,
2023-04-24 16:39:20 +02:00
setPendingComment ,
2023-04-25 14:34:48 +02:00
setPendingCommentIndex ,
2023-05-14 22:25:55 +02:00
setSelectedAddress ,
2023-04-12 21:56:25 +02:00
setSelectedParentCid ,
setSelectedShortCid ,
2023-03-13 14:29:34 +01:00
selectedStyle ,
2023-03-20 17:08:05 +01:00
selectedThread , setSelectedThread ,
2023-06-24 16:36:59 +02:00
setSelectedText ,
2023-03-20 17:08:05 +01:00
selectedTitle , setSelectedTitle ,
showPostForm ,
2023-04-09 20:55:55 +02:00
showPostFormLink ,
2023-06-24 12:38:14 +02:00
setTriggerInsertion ,
2023-04-08 13:27:17 +02:00
} = useGeneralStore ( state => state );
2023-03-20 17:08:05 +01:00
2023-06-16 14:42:23 +02:00
const { anonymousMode } = useAnonModeStore ();
2023-07-31 08:59:17 +02:00
2023-05-18 16:59:51 +02:00
const account = useAccount ();
const navigate = useNavigate ();
const handleClickForm = useClickForm ();
2023-06-14 16:24:25 +02:00
const [, setNewErrorMessage ] = useError ();
const [, setNewSuccessMessage ] = useSuccess ();
2023-06-07 21:24:17 +02:00
2023-04-03 15:08:45 +02:00
const nameRef = useRef ();
const commentRef = useRef ();
const linkRef = useRef ();
2023-05-18 16:59:51 +02:00
const threadMenuRefs = useRef ({});
const replyMenuRefs = useRef ({});
2023-05-25 17:48:55 +02:00
const postMenuRef = useRef ( null );
const postMenuCatalogRef = useRef ( null );
2023-06-03 17:22:39 +02:00
const backlinkRefs = useRef ({});
const quoteRefs = useRef ({});
2023-06-21 21:53:45 +02:00
const postRefs = useRef ({});
2023-06-03 16:33:59 +02:00
const postOnHoverRef = useRef ( null );
2023-06-16 13:48:40 +02:00
const backlinkRefsMobile = useRef ({});
const quoteRefsMobile = useRef ({});
2023-04-03 15:08:45 +02:00
2023-05-10 10:00:08 +02:00
const [ triggerPublishComment , setTriggerPublishComment ] = useState ( false );
2023-05-22 18:56:34 +02:00
const [ triggerPublishCommentEdit , setTriggerPublishCommentEdit ] = useState ( false );
2023-05-21 16:36:03 +02:00
const [ deletePost , setDeletePost ] = useState ( false );
2023-03-17 14:35:03 +01:00
const [ isReplyOpen , setIsReplyOpen ] = useState ( false );
2023-05-22 18:56:34 +02:00
const [ isEditModalOpen , setIsEditModalOpen ] = useState ( false );
const [ originalCommentContent , setOriginalCommentContent ] = useState ( null );
2023-02-24 20:57:51 +01:00
const [ prevScrollPos , setPrevScrollPos ] = useState ( 0 );
const [ visible , setVisible ] = useState ( true );
2023-05-18 16:59:51 +02:00
const [ isImageSearchOpen , setIsImageSearchOpen ] = useState ( false );
2023-05-18 22:32:32 +02:00
const [ isModerator , setIsModerator ] = useState ( false );
2023-05-22 18:56:34 +02:00
const [ commentCid , setCommentCid ] = useState ( null );
2023-07-31 08:59:17 +02:00
const [ menuPosition , setMenuPosition ] = useState ({ top : 0 , left : 0 });
2023-05-25 17:48:55 +02:00
const [ openMenuCid , setOpenMenuCid ] = useState ( null );
2023-06-02 13:50:58 +02:00
const [ outOfViewCid , setOutOfViewCid ] = useState ( null );
2023-07-31 08:59:17 +02:00
const [ outOfViewPosition , setOutOfViewPosition ] = useState ({ top : 0 , left : 0 });
2023-06-03 16:33:59 +02:00
const [ postOnHoverHeight , setPostOnHoverHeight ] = useState ( 0 );
2023-06-16 13:48:40 +02:00
const [ executeAnonMode , setExecuteAnonMode ] = useState ( false );
2023-06-21 21:53:45 +02:00
const [ cidTracker , setCidTracker ] = useState ({});
2023-07-30 15:39:52 +02:00
const [ isThreadThumbnailClicked , setIsThreadThumbnailClicked ] = useState ({});
const [ isReplyThumbnailClicked , setIsReplyThumbnailClicked ] = useState ({});
const [ isMobileThreadThumbnailClicked , setIsMobileThreadThumbnailClicked ] = useState ({});
2023-07-19 18:16:01 +02:00
const [ isCreateBoardOpen , setIsCreateBoardOpen ] = useState ( false );
2023-06-21 21:53:45 +02:00
2023-06-16 13:48:40 +02:00
useAnonMode ( selectedThread , anonymousMode && executeAnonMode );
2023-05-18 22:32:32 +02:00
2023-07-31 08:59:17 +02:00
const comment = useComment ({ commentCid : selectedThread });
2023-03-02 18:19:08 +01:00
const { subplebbitAddress , threadCid } = useParams ();
2023-07-31 08:59:17 +02:00
const subplebbit = useSubplebbit ({ subplebbitAddress : comment . subplebbitAddress });
2023-05-14 22:25:55 +02:00
const selectedAddress = subplebbit . address ;
2023-02-20 22:17:04 +01:00
2023-05-15 04:44:33 +00:00
const stateString = useStateString ( comment );
2023-05-09 15:58:19 +02:00
2023-05-10 10:00:08 +02:00
const commentMediaInfo = getCommentMediaInfo ( comment );
const fallbackImgUrl = "assets/filedeleted-res.gif" ;
2023-05-18 22:32:32 +02:00
2023-07-30 15:39:52 +02:00
const handleThumbnailClick = ( index , type ) => {
switch ( type ) {
case 'thread' :
setIsThreadThumbnailClicked ( prevState => ({
... prevState ,
[ index ] : ! prevState [ index ],
}));
break ;
case 'reply' :
setIsReplyThumbnailClicked ( prevState => ({
... prevState ,
[ index ] : ! prevState [ index ],
}));
break ;
case 'mobileThread' :
setIsMobileThreadThumbnailClicked ( prevState => ({
... prevState ,
[ index ] : ! prevState [ index ],
}));
break ;
default :
break ;
2023-07-07 17:48:24 +02:00
}
};
2023-05-18 22:32:32 +02:00
useEffect (() => {
2023-07-31 08:59:17 +02:00
if ( subplebbit . roles !== undefined ) {
2023-05-22 13:16:16 +02:00
const role = subplebbit . roles [ account ? . author ? . address ] ? . role ;
2023-07-31 08:59:17 +02:00
2023-05-19 21:05:51 +02:00
if ( role === 'moderator' || role === 'admin' || role === 'owner' ) {
setIsModerator ( true );
} else {
setIsModerator ( false );
}
2023-05-18 22:32:32 +02:00
}
2023-07-31 08:59:17 +02:00
}, [ account ? . author . address , subplebbit . roles ]);
2023-05-18 22:32:32 +02:00
2023-05-25 17:48:55 +02:00
const handleOptionClick = () => {
setOpenMenuCid ( null );
2023-05-18 22:32:32 +02:00
};
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 );
}
2023-07-31 08:59:17 +02:00
2023-05-25 17:48:55 +02:00
return () => {
document . removeEventListener ( 'click' , handleOutsideClick );
};
2023-05-25 21:03:17 +02:00
}, [ openMenuCid , handleOutsideClick ]);
2023-05-25 17:48:55 +02:00
2023-07-01 13:23:03 +02:00
useEffect (() => {
if ( postOnHoverRef . current ) {
const rect = postOnHoverRef . current . getBoundingClientRect ();
setPostOnHoverHeight ( rect . height );
}
}, [ outOfViewCid ]);
2023-07-31 08:59:17 +02:00
2023-05-15 17:17:36 +02:00
useEffect (() => {
window . scrollTo ( 0 , 0 );
}, []);
2023-05-14 22:25:55 +02:00
useEffect (() => {
2023-07-31 08:59:17 +02:00
if ( comment . state === "failed" && selectedAddress === undefined ) {
2023-05-15 09:42:37 +02:00
navigate ( '/404' );
2023-05-14 22:25:55 +02:00
}
2023-05-15 09:42:37 +02:00
}, [ selectedAddress , navigate , comment . state ]);
2023-05-14 22:25:55 +02:00
2023-05-10 10:00:08 +02:00
2023-05-09 15:58:19 +02:00
const errorString = useMemo (() => {
if ( comment ? . state === 'failed' ) {
let errorString = 'Failed fetching thread.'
if ( comment . error ) {
errorString += `: ${ comment . error . toString (). slice ( 0 , 300 ) } `
}
return errorString
}
}, [ comment ? . state , comment ? . error ])
2023-05-10 10:00:08 +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-09 15:58:19 +02:00
2023-04-24 16:39:20 +02:00
2023-07-31 08:59:17 +02:00
const flattenedReplies = useMemo (() =>
2023-04-25 14:34:48 +02:00
flattenCommentsPages ( comment . replies ), [ comment . replies ]
);
const filter = useMemo (() => ({
parentCids : [
selectedThread || 'n/a' , ... flattenedReplies . map ( reply => reply . cid )
]
2023-04-27 11:42:51 +02:00
}), [ flattenedReplies , selectedThread ]);
2023-04-25 14:34:48 +02:00
2023-07-31 08:59:17 +02:00
const { accountComments } = useAccountComments ({ filter });
2023-04-25 14:34:48 +02:00
const accountRepliesNotYetInCommentReplies = useMemo (() => {
const commentReplyCids = new Set ( flattenedReplies . map ( reply => reply . cid ))
return accountComments . filter ( accountReply => ! commentReplyCids . has ( accountReply . cid ))
}, [ flattenedReplies , accountComments ]);
const sortedReplies = useMemo (() => [
... accountRepliesNotYetInCommentReplies , ... flattenedReplies
2023-07-31 08:59:17 +02:00
]. sort (( a , b ) => a . timestamp - b . timestamp
2023-04-25 14:34:48 +02:00
), [ accountRepliesNotYetInCommentReplies , flattenedReplies ]);
2023-04-15 21:08:16 +02:00
2023-06-22 14:59:30 +02:00
// let post.jsx access full cid of user-typed short cid
useEffect (() => {
2023-06-21 22:24:56 +02:00
const newCidTracker = {};
sortedReplies . forEach (( reply ) => {
newCidTracker [ reply . shortCid ] = reply . cid ;
});
setCidTracker ( newCidTracker );
}, [ sortedReplies ]);
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 ( threadCid ) {
setSelectedThread ( threadCid );
}
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 , threadCid , defaultSubplebbits , subplebbit , setSelectedThread , setSelectedAddress , setSelectedTitle ]);
2023-02-12 21:20:08 +01:00
2023-03-08 09:49:42 +01:00
// mobile navbar scroll effect
2023-02-24 20:57:51 +01:00
useEffect (() => {
2023-03-25 14:54:04 +01:00
const debouncedHandleScroll = debounce (() => {
2023-05-21 18:12:33 +02:00
const currentScrollPos = window . scrollY ;
2023-02-24 20:57:51 +01:00
setVisible ( prevScrollPos > currentScrollPos || currentScrollPos < 10 );
setPrevScrollPos ( currentScrollPos );
2023-03-25 14:54:04 +01:00
}, 50 );
2023-07-31 08:59:17 +02:00
2023-03-25 14:54:04 +01:00
window . addEventListener ( 'scroll' , debouncedHandleScroll );
2023-07-31 08:59:17 +02:00
2023-03-25 14:54:04 +01:00
return () => window . removeEventListener ( 'scroll' , debouncedHandleScroll );
2023-02-24 20:57:51 +01:00
}, [ prevScrollPos , visible ]);
2023-03-02 21:51:06 +01:00
2023-07-31 08:59:17 +02:00
2023-03-12 10:27:59 +01:00
const onChallengeVerification = ( challengeVerification ) => {
if ( challengeVerification . challengeSuccess === true ) {
2023-05-18 22:32:32 +02:00
if ( challengeVerification . publication ? . cid !== undefined ) {
2023-06-14 16:24:25 +02:00
return ;
2023-05-18 22:32:32 +02:00
} else {
2023-06-14 16:24:25 +02:00
setNewSuccessMessage ( 'Challenge Success' );
2023-05-18 22:32:32 +02: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-03-12 10:27:59 +01:00
}
2023-04-11 22:27:24 +02:00
};
2023-03-12 10:27:59 +01:00
const onChallenge = async ( challenges , comment ) => {
2023-04-10 21:34:37 +02:00
setPendingComment ( comment );
2023-03-12 10:27:59 +01:00
let challengeAnswers = [];
2023-07-31 08:59:17 +02:00
2023-03-12 10:27:59 +01:00
try {
challengeAnswers = await getChallengeAnswersFromUser ( challenges )
}
catch ( error ) {
2023-07-02 11:45:56 +02:00
setNewErrorMessage ( error . message ); console . log ( error );
2023-03-12 10:27:59 +01:00
}
if ( challengeAnswers ) {
await comment . publishChallengeAnswers ( challengeAnswers )
}
2023-04-03 15:08:45 +02:00
};
2023-07-31 08:59:17 +02:00
2023-04-23 15:14:49 +02:00
useEffect (() => {
setPublishCommentOptions (( prevPublishCommentOptions ) => ({
... prevPublishCommentOptions ,
2023-06-14 17:07:00 +02:00
subplebbitAddress : comment . subplebbitAddress ,
2023-04-23 15:14:49 +02:00
}));
2023-06-14 17:07:00 +02:00
}, [ comment . subplebbitAddress ]);
2023-04-23 15:14:49 +02:00
2023-07-31 08:59:17 +02:00
2023-04-11 22:27:24 +02:00
const [ publishCommentOptions , setPublishCommentOptions ] = useState ({
2023-06-14 17:07:00 +02:00
subplebbitAddress : comment . subplebbitAddress ,
2023-04-11 22:27:24 +02:00
onChallenge ,
2023-04-22 17:37:53 +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-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
}
2023-04-27 11:42:51 +02:00
}, [ index , setPendingCommentIndex ]);
2023-04-12 14:02:35 +02:00
2023-07-31 08:59:17 +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 ( 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-12 21:32:33 +02:00
if (
commentRef . current . value === "" &&
linkRef . current . value === ""
) {
2023-06-14 16:24:25 +02:00
setNewErrorMessage ( "Please enter a comment or link." );
2023-05-12 21:32:33 +02:00
return ;
}
2023-07-31 08:59:17 +02:00
2023-04-11 22:27:24 +02:00
setPublishCommentOptions (( prevPublishCommentOptions ) => ({
... prevPublishCommentOptions ,
2023-04-16 18:07:20 +02:00
author : {
displayName : nameRef . current . value || undefined ,
2023-08-01 14:48:47 +02:00
address : account ? . author . address ,
2023-04-16 18:07:20 +02:00
},
2023-04-11 22:27:24 +02:00
content : commentRef . current . value || undefined ,
link : linkRef . current . value || undefined ,
2023-04-12 14:58:53 +02:00
parentCid : selectedThread ,
2023-04-11 22:27:24 +02:00
}));
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-07-31 08:59:17 +02:00
2023-06-29 18:10:27 +02:00
const updateSigner = useCallback ( async () => {
if ( anonymousMode ) {
setExecuteAnonMode ( true );
2023-07-31 08:59:17 +02:00
2023-06-29 18:10:27 +02:00
let storedSigners = JSON . parse ( localStorage . getItem ( 'storedSigners' )) || {};
let signer ;
2023-07-31 08:59:17 +02:00
2023-06-29 18:10:27 +02:00
if ( ! storedSigners [ selectedThread ]) {
signer = await account ? . plebbit . createSigner ();
storedSigners [ selectedThread ] = { privateKey : signer ? . privateKey , address : signer ? . address };
localStorage . setItem ( 'storedSigners' , JSON . stringify ( storedSigners ));
} else {
const signerPrivateKey = storedSigners [ selectedThread ]. privateKey ;
2023-07-31 08:59:17 +02:00
2023-06-29 18:10:27 +02:00
try {
2023-07-31 08:59:17 +02:00
signer = await account ? . plebbit . createSigner ({ type : 'ed25519' , privateKey : signerPrivateKey });
2023-06-29 18:10:27 +02:00
} catch ( error ) {
console . log ( error );
2023-06-26 21:55:26 +02:00
}
2023-06-29 18:10:27 +02:00
}
2023-07-31 08:59:17 +02:00
2023-06-29 18:10:27 +02:00
setPublishCommentOptions ( prevPublishCommentOptions => {
const newPublishCommentOptions = {
2023-06-26 21:55:26 +02:00
... prevPublishCommentOptions ,
signer ,
author : {
... prevPublishCommentOptions . author ,
2023-08-01 14:48:47 +02:00
address : signer ? . address ,
2023-06-26 21:55:26 +02:00
},
2023-06-29 18:10:27 +02:00
};
2023-07-31 08:59:17 +02:00
2023-06-29 18:10:27 +02:00
if ( JSON . stringify ( prevPublishCommentOptions ) !== JSON . stringify ( newPublishCommentOptions )) {
return newPublishCommentOptions ;
}
2023-07-31 08:59:17 +02:00
2023-06-29 18:10:27 +02:00
return prevPublishCommentOptions ;
});
}
}, [ selectedThread , anonymousMode , account ]);
2023-07-31 08:59:17 +02:00
2023-06-29 18:10:27 +02:00
useEffect (() => {
2023-07-07 17:48:24 +02:00
if ( anonymousMode ) {
updateSigner ();
}
}, [ updateSigner , anonymousMode ]);
2023-07-31 08:59:17 +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 18:26:03 +02:00
setTriggerPublishComment ( false );
2023-06-26 21:55:26 +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-04-03 15:08:45 +02:00
2023-03-12 10:27:59 +01:00
const getChallengeAnswersFromUser = async ( challenges ) => {
2023-04-10 21:34:37 +02:00
setChallengesArray ( challenges );
2023-07-31 08:59:17 +02:00
2023-03-12 10:27:59 +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 ;
2023-07-31 08:59:17 +02:00
2023-03-12 10:27:59 +01:00
challengeImg . onload = () => {
2023-03-12 22:07:15 +01:00
setIsCaptchaOpen ( true );
2023-07-31 08:59:17 +02:00
2023-04-22 17:37:53 +02:00
const handleKeyDown = async ( event ) => {
2023-03-12 10:27:59 +01:00
if ( event . key === 'Enter' ) {
2023-04-22 17:37:53 +02:00
const currentCaptchaResponse = captchaResponse ;
resolve ( currentCaptchaResponse );
2023-03-12 22:07:15 +01:00
setIsCaptchaOpen ( false );
2023-03-12 10:27:59 +01:00
document . removeEventListener ( 'keydown' , handleKeyDown );
2023-04-03 15:08:45 +02:00
event . preventDefault ();
2023-03-12 10:27:59 +01:00
}
};
2023-03-12 22:07:15 +01:00
setCaptchaResponse ( '' );
2023-03-12 10:27:59 +01:00
document . addEventListener ( 'keydown' , handleKeyDown );
2023-04-22 14:33:59 +02:00
setResolveCaptchaPromise ( resolve );
2023-03-12 10:27:59 +01:00
};
2023-07-31 08:59:17 +02:00
2023-03-12 10:27:59 +01:00
challengeImg . onerror = () => {
2023-06-14 16:24:25 +02:00
reject ( setNewErrorMessage ( 'Could not load challenges' ));
2023-03-12 10:27:59 +01:00
};
});
};
2023-05-18 22:32:32 +02:00
2023-05-22 18:56:34 +02:00
const [ publishCommentEditOptions , setPublishCommentEditOptions ] = useState ({
commentCid : commentCid ,
2023-05-23 14:56:25 +02:00
content : editedComment || undefined ,
2023-06-14 17:07:00 +02:00
subplebbitAddress : comment . subplebbitAddress ,
2023-05-22 18:56:34 +02:00
onChallenge ,
onChallengeVerification ,
onError : ( error ) => {
2023-07-02 11:45:56 +02:00
setNewErrorMessage ( error . message ); console . log ( error );
2023-05-22 18:56:34 +02:00
},
});
2023-07-31 08:59:17 +02:00
2023-06-14 16:24:25 +02:00
const { publishCommentEdit } = usePublishCommentEdit ( publishCommentEditOptions );
2023-05-22 18:56:34 +02:00
2023-07-02 21:36:08 +02:00
const handleAuthorDeleteClick = ( comment ) => {
handleOptionClick ( comment . cid );
2023-05-22 18:56:34 +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 >
2023-05-23 14:56:25 +02:00
< 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-23 14:56:25 +02:00
setPublishCommentEditOptions ( prevOptions => ({
... prevOptions ,
2023-07-02 21:36:08 +02:00
commentCid : comment . cid ,
subplebbitAddress : comment . subplebbitAddress ,
2023-05-23 14:56:25 +02:00
deleted : true ,
}));
setTriggerPublishCommentEdit ( true );
onClose ();
}}
>
Yes
</ button >
</ div >
2023-05-22 18:56:34 +02:00
</ div >
</ AuthorDeleteAlert >
);
}
});
};
const handleAuthorEditClick = ( comment ) => {
handleOptionClick ( comment . cid );
2023-05-26 10:10:51 +02:00
setIsAuthorEdit ( true );
setIsAuthorDelete ( false );
2023-05-22 18:56:34 +02:00
setCommentCid ( comment . cid );
setOriginalCommentContent ( comment . content );
setIsEditModalOpen ( true );
}
2023-07-31 08:59:17 +02:00
2023-05-22 18:56:34 +02:00
useEffect (() => {
setPublishCommentEditOptions (( prevOptions ) => ({
... prevOptions ,
commentCid : commentCid ,
2023-05-23 14:56:25 +02:00
content : editedComment || undefined ,
2023-05-22 18:56:34 +02:00
}));
2023-05-23 14:56:25 +02:00
}, [ commentCid , editedComment ]);
useEffect (() => {
if ( editedComment !== '' ) {
setTriggerPublishCommentEdit ( true );
}
}, [ editedComment ]);
2023-05-22 18:56:34 +02:00
2023-07-31 08:59:17 +02:00
2023-05-22 18:56:34 +02:00
useEffect (() => {
2023-06-29 16:45:12 +02:00
let isActive = true ;
2023-05-22 18:56:34 +02:00
if ( publishCommentEditOptions && triggerPublishCommentEdit ) {
( async () => {
2023-06-07 18:26:03 +02:00
await publishCommentEdit ();
2023-06-29 16:45:12 +02:00
if ( isActive ) {
setTriggerPublishCommentEdit ( false );
}
2023-05-22 18:56:34 +02:00
})();
}
2023-06-29 16:45:12 +02:00
return () => {
isActive = false ;
};
}, [ triggerPublishCommentEdit , publishCommentEdit , publishCommentEditOptions ]);
2023-05-22 18:56:34 +02:00
2023-03-08 09:49:42 +01: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-12 21:20:08 +01:00
};
2023-03-02 21:51:06 +01:00
2023-02-12 21:20:08 +01:00
return (
2023-04-21 10:47:39 +02:00
<>
< Helmet >
2023-07-31 08:59:17 +02:00
< title >
{(
( comment . content ? . slice ( 0 , 40 ) ?? comment . title ? . slice ( 0 , 40 ) ?? "Thread" ) + " - "
+ ( selectedTitle ? selectedTitle : selectedAddress )
+ " - plebchan"
)}
</ title >
</ Helmet >
2023-04-21 10:47:39 +02:00
< Container >
2023-07-19 18:16:01 +02:00
< CreateBoardModal
2023-07-31 08:59:17 +02:00
selectedStyle = { selectedStyle }
isOpen = { isCreateBoardOpen }
closeModal = {() => setIsCreateBoardOpen ( false )} />
< ReplyModal
selectedStyle = { selectedStyle }
isOpen = { isReplyOpen }
closeModal = {() => setIsReplyOpen ( false )} />
2023-04-21 10:47:39 +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-05-22 18:56:34 +02:00
< EditModal
2023-07-31 08:59:17 +02:00
selectedStyle = { selectedStyle }
isOpen = { isEditModalOpen }
closeModal = {() => setIsEditModalOpen ( false )}
originalCommentContent = { originalCommentContent } />
2023-04-21 10:47:39 +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-01 21:58:19 +02:00
< span className = "nav" >
2023-05-01 18:41:10 +02:00
[
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-04-30 17:37:19 +02:00
)
2023-07-31 08:59:17 +02:00
)
}
2023-05-27 12:33:25 +02:00
}> Create Board </ span >
2023-04-30 17:37:19 +02:00
]
2023-02-12 21:20:08 +01:00
[
2023-04-21 10:47:39 +02:00
< Link to = { `/p/ ${ selectedAddress } /c/ ${ selectedThread } /settings` } onClick = {() => setIsSettingsOpen ( true )}> Settings </ Link >
]
[
2023-05-27 12:55:16 +02:00
< Link to = "/" > Home </ Link >
2023-04-21 10:47:39 +02:00
]
2023-02-12 21:20:08 +01:00
</ span >
2023-04-21 10:47:39 +02:00
< 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 => (
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-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 } /c/ ${ selectedThread } /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-04-21 10:47:39 +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-06-27 16:42:39 +02:00
< div className = "board-title" >{ subplebbit . title ?? null }</ div >
< div className = "board-address" > p / { subplebbit . address }
2023-07-31 08:59:17 +02:00
< OfflineIndicator
address = { subplebbit . address }
className = "offline"
tooltipPlace = "top" />
2023-05-09 16:36:49 +02:00
</ div >
2023-07-31 08:59:17 +02:00
</>
2023-04-21 10:47:39 +02:00
</>
</ Header >
< Break selectedStyle = { selectedStyle } />
< PostForm selectedStyle = { selectedStyle } name = "post" action = "" method = "post" enctype = "multipart/form-data" >
< ReplyFormLink id = "post-form-link" showReplyFormLink = { showPostFormLink } selectedStyle = { selectedStyle } >
< div id = "return-button-mobile" >
2023-07-31 08:59:17 +02:00
< span className = "btn-wrap" onClick = {()=> { window . scrollTo ( 0 , 0 )}}>
2023-04-21 10:47:39 +02:00
< Link to = { `/p/ ${ selectedAddress } ` }> Return </ Link >
</ span >
</ div >
< div id = "catalog-button-mobile" >
< span className = "btn-wrap" >
2023-07-31 08:59:17 +02:00
< Link to = { `/p/ ${ selectedAddress } /catalog` } onClick = {()=> { window . scrollTo ( 0 , 0 )}}> Catalog </ Link >
2023-04-21 10:47:39 +02:00
</ span >
</ div >
< div id = "bottom-button-mobile" >
< span className = "btn-wrap" >
2023-07-31 08:59:17 +02:00
< span style = {{ cursor : 'pointer' }} onClick = {() => window . scrollTo ( 0 , document . body . scrollHeight )} onMouseOver = {( event ) => event . target . style . cursor = 'pointer' }> Bottom </ span >
2023-04-21 10:47:39 +02:00
</ span >
</ div >
< div id = "post-form-link-desktop" >
[
2023-07-31 08:59:17 +02:00
< Link to = { `/p/ ${ subplebbitAddress } /c/ ${ selectedThread } /post` } onClick = {() => { handleClickForm (); setSelectedShortCid ( comment . shortCid )}} onMouseOver = {( event ) => event . target . style . cursor = 'pointer' }> Post a Reply </ Link >
2023-04-21 10:47:39 +02:00
]
</ div >
< div id = "post-form-link-mobile" >
< span className = "btn-wrap" >
2023-07-31 08:59:17 +02:00
< Link to = { `/p/ ${ subplebbitAddress } /c/ ${ selectedThread } /post` } onClick = {() => { handleClickForm (); setSelectedShortCid ( comment . shortCid )}} onMouseOver = {( event ) => event . target . style . cursor = 'pointer' }> Post a Reply </ Link >
2023-04-21 10:47:39 +02:00
</ span >
</ div >
</ ReplyFormLink >
< 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-07-31 08:59:17 +02:00
< input id = "post-button" type = "submit" value = "Post" tabIndex = { 6 }
onClick = { handleSubmit } />
2023-04-21 10:47:39 +02:00
</ 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 :
2023-07-31 08:59:17 +02:00
2023-04-21 10:47:39 +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 >
< span className = "return-button" id = "return-button-desktop" >
2023-02-23 16:45:29 +01:00
[
2023-04-21 10:47:39 +02:00
< Link to = { `/p/ ${ selectedAddress } ` }> Return </ Link >
2023-02-23 16:45:29 +01:00
]
2023-02-12 21:20:08 +01:00
</ span >
2023-04-21 10:47:39 +02:00
< span className = "return-button catalog-button" id = "catalog-button-desktop" >
2023-02-12 21:20:08 +01:00
[
2023-04-21 10:47:39 +02:00
< Link to = { `/p/ ${ selectedAddress } /catalog` }> Catalog </ Link >
2023-02-12 21:20:08 +01:00
]
2023-04-21 10:47:39 +02:00
</ span >
2023-07-31 08:59:17 +02:00
< span className = "return-button catalog-button" id = "bottom-button-desktop" >
2023-04-21 10:47:39 +02:00
[
2023-07-31 08:59:17 +02:00
< span id = "button" style = {{ cursor : 'pointer' }} onClick = {() => window . scrollTo ( 0 , document . body . scrollHeight )}
onMouseOver = {( event ) => event . target . style . cursor = 'pointer' }
onTouchStart = {() => window . scrollTo ( 0 , document . body . scrollHeight )}> Bottom </ span >
2023-04-21 10:47:39 +02:00
]
</ span >
{ comment ? (
comment . replyCount !== undefined ? (
comment . replyCount > 0 ? (
comment . replyCount === 1 ? (
< span className = "reply-stat" >{ comment . replyCount } reply </ span >
) : (
< span className = "reply-stat" >{ comment . replyCount } replies </ span >
)
2023-03-18 22:05:46 +01:00
) : (
2023-04-21 10:47:39 +02:00
< span className = "reply-stat" > No replies yet </ span >
2023-03-18 22:05:46 +01:00
)
) : (
2023-05-16 12:40:29 +02:00
< span className = { stateString ? "reply-stat ellipsis" : "" }>{ stateString }</ span >
2023-03-18 22:05:46 +01:00
)
2023-02-21 14:49:00 +01:00
) : (
2023-05-16 12:40:29 +02:00
< span className = { stateString ? "reply-stat ellipsis" : "" }>{ stateString }</ span >
2023-04-21 10:47:39 +02:00
)}
< hr />
</ TopBar >
< Tooltip id = "tooltip" className = "tooltip" />
< BoardForm selectedStyle = { selectedStyle }>
{ comment !== undefined ? (
2023-04-29 12:34:47 +02:00
comment . state === "fetching-ipfs" ? (
< PostLoader />
) : (
2023-04-21 10:47:39 +02:00
<>
< div className = "thread" >
< div className = "op-container" >
< div className = "post op op-desktop" >
< div className = "post-info" >
2023-07-07 17:48:24 +02:00
{ commentMediaInfo ? . url ? (
< div key = { `f- ${ index } ` } className = "file" style = {{ marginBottom : "5px" }}>
< div key = { `ft- ${ index } ` } className = "file-text" >
2023-04-21 10:47:39 +02:00
Link :& nbsp ;
2023-07-07 17:48:24 +02:00
< a key = { `fa- ${ index } ` } href = { commentMediaInfo . url } target = "_blank"
rel = "noopener noreferrer" >{
2023-04-21 10:47:39 +02:00
commentMediaInfo ? . url . length > 30 ?
commentMediaInfo ? . url . slice ( 0 , 30 ) + "(...)" :
commentMediaInfo ? . url
2023-07-07 17:48:24 +02:00
}</ a > & nbsp ;({ commentMediaInfo ? . type === "iframe" ? "video" : commentMediaInfo ? . type })
2023-07-30 15:39:52 +02:00
{ isThreadThumbnailClicked [ index ] ? (
2023-07-07 17:48:24 +02:00
< span >
- [
< span className = 'reply-link'
style = {{ textDecoration : 'underline' , cursor : 'pointer' }}
2023-07-30 15:39:52 +02:00
onClick = {() => { handleThumbnailClick ( index , 'thread' )}}> Close </ span >
2023-07-07 17:48:24 +02:00
]
</ span >
) : null }
2023-03-08 09:49:42 +01:00
</ div >
2023-07-07 17:48:24 +02:00
{ commentMediaInfo ? . type === 'iframe' && (
< div key = { `enlarge- ${ index } ` }
2023-07-30 15:39:52 +02:00
className = { `img-container ${ isThreadThumbnailClicked [ index ] ? 'expanded-container' : '' } ` }>
2023-07-07 17:48:24 +02:00
< span key = { `fta- ${ index } ` } className = "file-thumb" >
2023-07-30 15:39:52 +02:00
{( isThreadThumbnailClicked [ index ] || ! commentMediaInfo . thumbnail ) && commentMediaInfo . embedUrl ? (
2023-07-07 17:48:24 +02:00
< iframe
className = 'enlarged'
key = { `fti- ${ index } ` }
src = { commentMediaInfo . embedUrl }
width = { commentMediaInfo . thumbnail ? "560" : "250" }
height = "315"
style = {{ border : "none" }}
title = "Embedded content"
allow = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen />
) : (
< img
key = { `fti- ${ index } ` }
src = { commentMediaInfo . thumbnail }
alt = "thumbnail"
2023-07-30 15:39:52 +02:00
onClick = {() => { handleThumbnailClick ( index , 'thread' )}}
2023-07-07 17:48:24 +02:00
style = {{ cursor : "pointer" }}
onError = {( e ) => e . target . src = fallbackImgUrl } />
)}
</ span >
</ div >
)}
2023-04-21 10:47:39 +02:00
{ commentMediaInfo ? . type === "webpage" ? (
2023-07-07 17:48:24 +02:00
< div key = { `enlarge- ${ index } ` } className = "img-container" >
< span key = { `fta- ${ index } ` } className = "file-thumb" >
2023-04-30 13:32:52 +02:00
{ comment . thumbnailUrl ? (
2023-07-07 17:48:24 +02:00
< img key = { `fti- ${ index } ` }
2023-04-30 16:23:32 +02:00
src = { commentMediaInfo . thumbnail } alt = { commentMediaInfo . type }
2023-07-30 15:39:52 +02:00
onClick = {( e ) => { handleImageClick ( e ); handleThumbnailClick ( index , 'thread' )}}
2023-07-07 17:48:24 +02:00
style = {{ cursor : "pointer" }}
2023-04-30 13:32:52 +02:00
onError = {( e ) => e . target . src = fallbackImgUrl } />
) : null }
</ span >
</ div >
) : null }
{ commentMediaInfo ? . type === "image" ? (
2023-07-07 17:48:24 +02:00
< div key = { `enlarge- ${ index } ` } className = "img-container" >
< span key = { `fta- ${ index } ` } className = "file-thumb" >
< img key = { `fti- ${ index } ` }
2023-04-30 13:32:52 +02:00
src = { commentMediaInfo . url } alt = { commentMediaInfo . type }
2023-07-30 15:39:52 +02:00
onClick = {( e ) => { handleImageClick ( e ); handleThumbnailClick ( index , 'thread' )}}
2023-07-07 17:48:24 +02:00
style = {{ cursor : "pointer" }}
2023-04-29 17:44:27 +02:00
onError = {( e ) => e . target . src = fallbackImgUrl } />
2023-04-30 13:32:52 +02:00
</ span >
</ div >
2023-04-21 10:47:39 +02:00
) : null }
{ commentMediaInfo ? . type === "video" ? (
2023-07-30 15:39:52 +02:00
< div key = { `enlarge- ${ index } ` } className = { `img-container ${ isThreadThumbnailClicked [ index ] ? 'expanded-container' : '' } ` }>
2023-07-07 17:48:24 +02:00
< span key = { `fta- ${ index } ` } className = "file-thumb" >
2023-07-30 15:39:52 +02:00
{ isThreadThumbnailClicked [ index ] ? (
2023-07-07 17:48:24 +02:00
< video
className = 'enlarged'
key = { `fti- ${ index } ` }
src = { commentMediaInfo . url }
controls
style = {{ cursor : "pointer" }}
onError = {( e ) => e . target . src = fallbackImgUrl }
/>
) : (
< video
key = { `fti- ${ index } ` }
src = { commentMediaInfo . url }
alt = "thumbnail"
2023-07-30 15:39:52 +02:00
onClick = {() => { handleThumbnailClick ( index , 'thread' )}}
2023-07-07 17:48:24 +02:00
style = {{ cursor : "pointer" }}
onError = {( e ) => e . target . src = fallbackImgUrl }
/>
)}
2023-04-21 10:47:39 +02:00
</ span >
2023-07-07 17:48:24 +02:00
</ div >
2023-04-21 10:47:39 +02:00
) : null }
{ commentMediaInfo ? . type === "audio" ? (
2023-07-07 17:48:24 +02:00
< span key = { `fta- ${ index } ` } className = "file-thumb" >
< audio controls key = { `fti- ${ index } ` }
src = { commentMediaInfo . url } alt = { commentMediaInfo . type }
2023-04-29 17:44:27 +02:00
onError = {( e ) => e . target . src = fallbackImgUrl } />
2023-04-21 10:47:39 +02:00
</ span >
) : null }
</ div >
) : null }
< span className = "name-block" >
{ comment . title ? (
comment . title . length > 75 ?
2023-07-31 08:59:17 +02:00
<>
< span key = { `q- ${ comment . cid } ` } className = "title"
data - tooltip - id = "tooltip"
data - tooltip - content = { comment . title }
data - tooltip - place = "top" >
{ comment . title . slice ( 0 , 75 ) + " (...)" }
</ span >
</>
: < span key = { `q- ${ comment . cid } ` } className = "title" >
{ comment . title }
</ span >)
: null }
& nbsp ;
{ comment ? . author ? . displayName
? comment ? . author ? . displayName . length > 20
? <>
< span key = { `n- ${ comment . cid } ` } className = "name"
data - tooltip - id = "tooltip"
data - tooltip - content = { comment ? . author ? . displayName }
data - tooltip - place = "top" >
{ comment ? . author ? . displayName . slice ( 0 , 20 ) + " (...)" }
</ span >
</>
2023-07-30 22:15:09 +02:00
: < span key = { `n- ${ comment . cid } ` } className = "name" >
2023-07-31 08:59:17 +02:00
{ comment ? . author ? . displayName }</ span >
: < span key = { `n- ${ comment . cid } ` } className = "name" >
Anonymous </ span >}
2023-07-30 22:15:09 +02:00
& nbsp ;
2023-07-31 08:59:17 +02:00
& nbsp ;
< span className = "poster-address address-desktop"
id = "reply-button" style = {{ cursor : "pointer" }}
onClick = {() => handleAddressClick (< VerifiedAuthor commentCid = { comment . cid }>{({ shortAuthorAddress }) => ( shortAuthorAddress )}</ VerifiedAuthor >)}>
( u /
2023-04-21 10:47:39 +02:00
< span key = { `pa- ${ comment . cid } ` } className = "poster-address" >
2023-07-31 08:59:17 +02:00
{< VerifiedAuthor commentCid = { comment . cid }>{({ shortAuthorAddress }) => ( shortAuthorAddress )}</ VerifiedAuthor >}
</ span >)
</ span >
& nbsp ;
< span className = "date-time" data - utc = "data" >{ getDate ( comment ? . timestamp )}</ span >
& nbsp ;
< span className = "post-number post-number-desktop" >
< span > c / </ span >
< Link to = {() => {}} id = "reply-button" style = {{ cursor : 'pointer' }}
onClick = {() => {
let text = document . getSelection (). toString ();
text = text ? `> ${ text } ` : text ;
setSelectedText ( text );
if ( isReplyOpen ) {
setReplyQuoteCid ( comment . shortCid );
setTriggerInsertion ( Date . now ());
} else {
setIsReplyOpen ( true );
setSelectedShortCid ( comment . shortCid );
setSelectedParentCid ( comment . cid );
}}} title = "Reply to this post" >{ comment . shortCid }</ Link >
</ span > & nbsp ;
{ comment . pinned ? (
<>
& nbsp ;
< img src = "assets/sticky.gif" alt = "Sticky" title = "Sticky"
style = {{ marginBottom : "-1px" ,
imageRendering : "pixelated" ,}} />
</>
) : null }
{ comment . locked ? (
<>
& nbsp ;
< img src = "assets/closed.gif" alt = "Closed" title = "Closed"
style = {{ marginBottom : "-1px" ,
imageRendering : "pixelated" ,}} />
</>
) : null }
< PostMenu
key = { `pmb- ${ index } ` }
title = "Post menu"
ref = { el => {
threadMenuRefs . current [ comment . cid ] = el ;
postMenuRef . current = el ;
}}
className = 'post-menu-button'
rotated = { openMenuCid === comment . cid }
onClick = {( event ) => {
event . stopPropagation ();
const rect = threadMenuRefs . current [ comment . cid ]. getBoundingClientRect ();
setMenuPosition ({ top : rect . top + window . scrollY , left : rect . left });
setOpenMenuCid ( prevCid => ( prevCid === comment . cid ? null : comment . cid ));
}}
>
▶
</ PostMenu >
{ 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- ${ comment . cid } ` }
style = {{ display : openMenuCid === comment . cid ? 'block' : 'none' }}
2023-05-25 17:48:55 +02:00
>
2023-07-31 08:59:17 +02:00
< ul className = "post-menu-catalog" >
< li onClick = {() => handleOptionClick ( comment . cid )}> Hide thread </ li >
< VerifiedAuthor commentCid = { comment . cid }>{({ authorAddress }) => (
<>
{ authorAddress === account ? . author . address ||
authorAddress === account ? . signer . address ? (
<>
< li onClick = {() => handleAuthorEditClick ( comment )}> Edit post </ li >
< li onClick = {() => handleAuthorDeleteClick ( comment )}> Delete post </ li >
</>
) : null }
{ isModerator ? (
2023-07-09 16:03:46 +02:00
<>
{ authorAddress === account ? . author . address ||
2023-07-31 08:59:17 +02:00
authorAddress === account ? . signer . address ? (
null
) : (
< li onClick = {() => {
setModeratingCommentCid ( comment . cid )
setIsModerationOpen ( true );
handleOptionClick ( comment . cid );
setDeletePost ( true );
}}>
Delete post
</ li >
)}
2023-07-09 16:03:46 +02:00
< li
2023-07-31 08:59:17 +02:00
onClick = {() => {
setModeratingCommentCid ( comment . cid )
setIsModerationOpen ( true );
handleOptionClick ( comment . cid );
2023-07-30 22:15:09 +02:00
}}>
2023-07-31 08:59:17 +02:00
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 ( comment . cid )}>
< a
href = { `https://lens.google.com/uploadbyurl?url= ${ commentMediaInfo . url } ` }
target = "_blank" rel = "noreferrer"
> Google </ a >
</ li >
< li onClick = {() => handleOptionClick ( comment . cid )}>
< a
href = { `https://yandex.com/images/search?url= ${ commentMediaInfo . url } ` }
target = "_blank" rel = "noreferrer"
> Yandex </ a >
</ li >
< li onClick = {() => handleOptionClick ( comment . cid )}>
< a
href = { `https://saucenao.com/search.php?url= ${ commentMediaInfo . url } ` }
target = "_blank" rel = "noreferrer"
> SauceNAO </ a >
</ li >
</ ul >
</ li >
) : null
}
</ ul >
2023-07-30 22:15:09 +02:00
</ div >
2023-07-31 08:59:17 +02:00
</ PostMenuCatalog >, document . body
)}
< div key = { `bi- ${ index } ` } id = "backlink-id" className = "backlink" >
{ comment . replies ? . pages ? . topAll . comments
. sort (( a , b ) => a . timestamp - b . timestamp )
. map (( reply , index ) => (
< div key = { `div- ${ index } ` } style = {{ display : 'inline-block' }}
ref = { el => {
backlinkRefs . current [ reply . cid ] = el ;
}}>
< Link key = { `ql- ${ index } ` }
to = {() => {}} className = "quote-link"
onClick = {( event ) => handleQuoteClick ( reply , null , event )}
onMouseOver = {( event ) => {
event . stopPropagation ();
handleQuoteHover ( reply , null , () => {
setOutOfViewCid ( reply . cid );
const rect = backlinkRefs . current [ reply . cid ]. getBoundingClientRect ();
const distanceToRight = window . innerWidth - rect . right ;
const distanceToTop = rect . top ;
const distanceToBottom = window . innerHeight - rect . bottom ;
let top ;
if ( distanceToTop < postOnHoverHeight / 2 ) {
top = window . scrollY - 5 ;
} else if ( distanceToBottom < postOnHoverHeight / 2 ) {
top = window . scrollY - postOnHoverHeight + window . innerHeight - 10 ;
} else {
top = rect . top + window . scrollY - postOnHoverHeight / 2 ;
}
if ( distanceToRight < 200 ) {
setOutOfViewPosition ({
top ,
right : window . innerWidth - rect . left - 10 ,
maxWidth : rect . left - 5
});
} else {
setOutOfViewPosition ({
top ,
left : rect . left + rect . width + 5 ,
maxWidth : window . innerWidth - rect . left - rect . width - 5
});
}
});
}}
onMouseLeave = {() => {
removeHighlight ();
setOutOfViewCid ( null );
}}>
c / { reply . shortCid }</ Link >
& nbsp ;
</ div >
))
}
</ div >
</ span >
< blockquote key = { `blockquote- ${ comment . cid } ` }>
< Post content = { comment . content } comment = { comment } key = { `post- ${ comment . cid } ` } />
< EditLabel key = { `edit-label-thread- ${ index } ` }
commentCid = { comment . cid }
className = "ttl" />
< StateLabel key = { `state-label-thread- ${ index } ` }
commentIndex = { comment . index }
className = "ttl ellipsis" />
</ blockquote >
2023-02-27 12:35:23 +01:00
</ div >
</ div >
2023-07-31 08:59:17 +02:00
</ div >
{ comment . replyCount === undefined ? < PostLoader /> : null }
{ sortedReplies . map (( reply , index ) => {
2023-04-21 10:47:39 +02:00
const replyMediaInfo = getCommentMediaInfo ( reply );
2023-04-29 12:47:30 +02:00
const fallbackImgUrl = "assets/filedeleted-res.gif" ;
2023-04-21 10:47:39 +02:00
const shortParentCid = findShortParentCid ( reply . parentCid , comment );
2023-06-26 21:55:26 +02:00
let storedSigners = JSON . parse ( localStorage . getItem ( 'storedSigners' )) || {};
let signerAddress ;
if ( storedSigners [ selectedThread ]) {
signerAddress = storedSigners [ selectedThread ]. address ;
}
2023-07-30 15:39:52 +02:00
let replyDisplayWidth , replyDisplayHeight ;
if ( reply . linkWidth && reply . linkHeight ) {
const scale = Math . min ( 1 , 125 / Math . max ( reply . linkWidth , reply . linkHeight ));
replyDisplayWidth = ` ${ reply . linkWidth * scale } px` ;
replyDisplayHeight = ` ${ reply . linkHeight * scale } px` ;
} else {
replyDisplayWidth = '125px' ;
replyDisplayHeight = '125px' ;
}
2023-04-21 10:47:39 +02:00
return (
2023-04-22 15:12:26 +02:00
< div key = { `pc- ${ index } ` } className = "reply-container" >
< div key = { `sa- ${ index } ` } className = "side-arrows" >{ '>>' }</ div >
< div key = { `pr- ${ index } ` } className = "post-reply post-reply-desktop" >
< div key = { `pi- ${ index } ` } className = "post-info" >
2023-07-31 08:59:17 +02:00
& nbsp ;
2023-04-22 15:12:26 +02:00
< span key = { `nb- ${ index } ` } className = "nameblock" >
2023-07-31 08:59:17 +02:00
{ reply . author ? . displayName
? reply . author ? . displayName . length > 20
? <>
< span key = { `mob-n- ${ index } ` } className = "name"
data - tooltip - id = "tooltip"
data - tooltip - content = { reply . author ? . displayName }
data - tooltip - place = "top" >
{ reply . author ? . displayName . slice ( 0 , 20 ) + " (...)" }
</ span >
</>
: < span key = { `mob-n- ${ index } ` } className = "name" >
{ reply . author ? . displayName ?? reply . displayName }</ span >
: < span key = { `mob-n- ${ index } ` } className = "name" >
Anonymous </ span >}
2023-04-21 10:47:39 +02:00
& nbsp ;
2023-04-22 15:12:26 +02:00
< span key = { `pa- ${ index } ` } className = "poster-address address-desktop"
2023-07-31 08:59:17 +02:00
id = "reply-button" style = {{ cursor : "pointer" }}
2023-04-21 10:47:39 +02:00
onClick = {() => handleAddressClick ( reply . author ? . shortAddress )}
>
( u /
2023-07-31 08:59:17 +02:00
{ reply . author ? . shortAddress ?
(
2023-04-22 15:43:38 +02:00
< span key = { `mob-ha- ${ index } ` }>
2023-07-31 08:59:17 +02:00
{ reply . author ? . shortAddress }
2023-04-22 15:43:38 +02:00
</ span >
) : (
2023-07-31 08:59:17 +02:00
anonymousMode ? (
< span key = { `mob-ha- ${ index } ` }>
{ signerAddress ? . slice ( 8 , 20 )}
</ span >
) : (
< span key = { `mob-ha- ${ index } ` }
>
{ account ? . author ? . shortAddress }
</ span >
)
2023-04-22 15:43:38 +02:00
)
2023-07-31 08:59:17 +02:00
}
2023-04-22 15:43:38 +02:00
)
2023-02-28 16:34:33 +01:00
</ span >
2023-04-21 10:47:39 +02:00
</ span >
& nbsp ;
2023-06-23 15:37:46 +02:00
< span key = { `dt- ${ index } ` } className = "date-time" >
{ getDate ( reply ? . timestamp )} & nbsp ;
2023-07-31 08:59:17 +02:00
< span key = { `pn- ${ index } ` } className = "post-number post-number-desktop" >
< span key = { `pl1- ${ index } ` }> c / </ span >
{ reply . shortCid ? (
< Link id = "reply-button" key = { `pl2- ${ index } ` }
onClick = {() => {
let text = document . getSelection (). toString ();
text = text ? `> ${ text } ` : text ;
setSelectedText ( text );
if ( isReplyOpen ) {
setReplyQuoteCid ( reply . shortCid );
setTriggerInsertion ( Date . now ());
} else {
setIsReplyOpen ( true );
setSelectedShortCid ( reply . shortCid );
setSelectedParentCid ( reply . cid );
}
}} title = "Reply to this post" >{ reply . shortCid }</ Link >
) : (
< PendingLabel key = "pending" commentIndex = { reply . index } />
)}
2023-06-23 15:37:46 +02:00
</ span >
2023-04-21 10:47:39 +02:00
</ span > & nbsp ;
2023-07-31 08:59:17 +02:00
< PostMenu
key = { `pmb- ${ index } ` }
2023-05-18 16:59:51 +02:00
title = "Post menu"
2023-07-31 08:59:17 +02:00
ref = { el => {
replyMenuRefs . current [ reply . cid ] = el ;
postMenuRef . current = el ;
2023-05-25 17:48:55 +02:00
}}
2023-07-31 08:59:17 +02:00
className = 'post-menu-button'
2023-05-25 17:48:55 +02:00
rotated = { openMenuCid === reply . cid }
onClick = {( event ) => {
event . stopPropagation ();
2023-05-18 16:59:51 +02:00
const rect = replyMenuRefs . current [ reply . cid ]. getBoundingClientRect ();
2023-07-31 08:59:17 +02:00
setMenuPosition ({ top : rect . top + window . scrollY , left : rect . left });
2023-05-25 17:48:55 +02:00
setOpenMenuCid ( prevCid => ( prevCid === reply . cid ? null : reply . cid ));
2023-07-31 08:59:17 +02:00
}}
2023-05-18 16:59:51 +02:00
>
▶
</ PostMenu >
2023-05-25 17:48:55 +02:00
{ createPortal (
2023-07-31 08:59:17 +02:00
< 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-reply post-menu-reply- ${ reply . cid } ` }
style = {{ display : openMenuCid === reply . cid ? 'block' : 'none' }}
>
< ul className = "post-menu-catalog" >
< li onClick = {() => handleOptionClick ( reply . cid )}> Hide post </ li >
< VerifiedAuthor commentCid = { reply . cid }>{({ authorAddress }) => (
<>
{ authorAddress === account ? . author . address ||
authorAddress === account ? . signer . address ? (
<>
< li onClick = {() => handleAuthorEditClick ( reply )}> Edit post </ li >
< li onClick = {() => handleAuthorDeleteClick ( reply )}> Delete post </ li >
</>
) : null }
{ isModerator ? (
<>
{ authorAddress === account ? . author . address ||
2023-07-09 16:03:46 +02:00
authorAddress === account ? . signer . address ? (
2023-07-31 08:59:17 +02:00
null
) : (
< li onClick = {() => {
setModeratingCommentCid ( reply . cid )
setIsModerationOpen ( true );
handleOptionClick ( reply . cid );
setDeletePost ( true );
}}>
Delete post
2023-07-09 16:03:46 +02:00
</ li >
2023-07-31 08:59:17 +02:00
)}
< li
onClick = {() => {
setModeratingCommentCid ( reply . cid )
setIsModerationOpen ( true );
handleOptionClick ( reply . cid );
}}>
Mod tools
</ li >
</>
) : null }
</>
)}</ VerifiedAuthor >
{( replyMediaInfo && (
replyMediaInfo . type === 'image' ||
( replyMediaInfo . type === 'webpage' &&
replyMediaInfo . thumbnail ))) ? (
< li
onMouseOver = {() => { setIsImageSearchOpen ( true )}}
onMouseLeave = {() => { setIsImageSearchOpen ( false )}}>
2023-05-25 17:48:55 +02:00
Image search »
2023-05-26 20:54:23 +02:00
< ul className = "dropdown-menu post-menu-catalog"
2023-07-31 08:59:17 +02:00
style = {{ display : isImageSearchOpen ? 'block' : 'none' }}>
2023-05-25 17:48:55 +02:00
< li onClick = {() => handleOptionClick ( reply . cid )}>
2023-07-31 08:59:17 +02:00
< a
href = { `https://lens.google.com/uploadbyurl?url= ${ replyMediaInfo . url } ` }
target = "_blank" rel = "noreferrer"
2023-05-25 17:48:55 +02:00
> Google </ a >
</ li >
< li onClick = {() => handleOptionClick ( reply . cid )}>
< a
2023-07-31 08:59:17 +02:00
href = { `https://yandex.com/images/search?url= ${ replyMediaInfo . url } ` }
target = "_blank" rel = "noreferrer"
2023-05-25 17:48:55 +02:00
> Yandex </ a >
</ li >
< li onClick = {() => handleOptionClick ( reply . cid )}>
< a
2023-07-31 08:59:17 +02:00
href = { `https://saucenao.com/search.php?url= ${ replyMediaInfo . url } ` }
target = "_blank" rel = "noreferrer"
2023-05-25 17:48:55 +02:00
> SauceNAO </ a >
</ li >
</ ul >
</ li >
) : null
2023-07-31 08:59:17 +02:00
}
</ ul >
</ div >
2023-05-25 17:48:55 +02:00
</ PostMenuCatalog >, document . body
)}
2023-06-03 16:33:59 +02:00
< div key = { `bi- ${ index } ` } id = "backlink-id" className = "backlink" >
2023-04-21 10:47:39 +02:00
{ reply . replies ? . pages ? . topAll . comments
. sort (( a , b ) => a . timestamp - b . timestamp )
2023-04-22 15:12:26 +02:00
. map (( reply , index ) => (
2023-07-31 08:59:17 +02:00
< div key = { `div- ${ index } ` } style = {{ display : 'inline-block' }}
ref = { el => {
backlinkRefs . current [ reply . cid ] = el ;
}}>
< Link key = { `ql- ${ index } ` }
to = {() => {}} className = "quote-link"
onClick = {( event ) => handleQuoteClick ( reply , null , event )}
onMouseOver = {( event ) => {
event . stopPropagation ();
handleQuoteHover ( reply , null , () => {
setOutOfViewCid ( reply . cid );
const rect = backlinkRefs . current [ reply . cid ]. getBoundingClientRect ();
const distanceToRight = window . innerWidth - rect . right ;
const distanceToTop = rect . top ;
const distanceToBottom = window . innerHeight - rect . bottom ;
let top ;
2023-06-11 13:59:56 +02:00
2023-07-31 08:59:17 +02:00
if ( distanceToTop < postOnHoverHeight / 2 ) {
top = window . scrollY - 5 ;
} else if ( distanceToBottom < postOnHoverHeight / 2 ) {
top = window . scrollY - postOnHoverHeight + window . innerHeight - 10 ;
} else {
top = rect . top + window . scrollY - postOnHoverHeight / 2 ;
}
if ( distanceToRight < 200 ) {
setOutOfViewPosition ({
top ,
right : window . innerWidth - rect . left - 10 ,
maxWidth : rect . left - 5
2023-06-10 12:28:21 +02:00
});
2023-07-31 08:59:17 +02:00
} else {
setOutOfViewPosition ({
top ,
left : rect . left + rect . width + 5 ,
maxWidth : window . innerWidth - rect . left - rect . width - 5
});
}
});
}}
onMouseLeave = {() => {
removeHighlight ();
setOutOfViewCid ( null );
}}>
c / { reply . shortCid }</ Link >
2023-04-21 10:47:39 +02:00
& nbsp ;
</ div >
))
}
</ div >
</ div >
{ replyMediaInfo ? . url ? (
2023-07-30 15:39:52 +02:00
< div key = { `f- ${ index } ` } className = "file"
style = {{ marginBottom : "5px" }}>
< div key = { `ft- ${ index } ` } className = "reply-file-text" >
Link :& nbsp ;
< a key = { `fa- ${ index } ` } href = { replyMediaInfo . url } target = "_blank"
rel = "noopener noreferrer" >{
replyMediaInfo ? . url . length > 30 ?
replyMediaInfo ? . url . slice ( 0 , 30 ) + "(...)" :
replyMediaInfo ? . url
}</ a > & nbsp ;({ replyMediaInfo ? . type })
{ replyMediaInfo ? . type === "video" || "iframe" ? (
isReplyThumbnailClicked [ index ] ? (
< span >
- [
< span className = 'reply-link'
style = {{ textDecoration : 'underline' , cursor : 'pointer' }}
onClick = {() => { handleThumbnailClick ( index , 'reply' )}}> Close </ span >
]
</ span >) : null )
: null }
</ div >
{ replyMediaInfo ? . type === "webpage" ? (
< div key = { `enlarge-reply- ${ index } ` } className = "img-container" >
< span key = { `fta- ${ index } ` } className = "file-thumb-reply" style = { isReplyThumbnailClicked [ index ] ? {} : { width : replyDisplayWidth , height : replyDisplayHeight }}>
{ reply . thumbnailUrl ? (
2023-04-27 18:06:16 +02:00
< img key = { `fti- ${ index } ` }
2023-07-30 15:39:52 +02:00
src = { replyMediaInfo . thumbnail } alt = { replyMediaInfo . type }
onClick = {( e ) => { handleImageClick ( e ); handleThumbnailClick ( index , 'reply' )}}
2023-04-29 17:44:27 +02:00
style = {{ cursor : "pointer" }}
2023-04-27 18:06:16 +02:00
onError = {( e ) => e . target . src = fallbackImgUrl } />
2023-07-30 15:39:52 +02:00
) : null }
</ span >
2023-04-30 13:32:52 +02:00
</ div >
2023-07-30 15:39:52 +02:00
) : null }
{ replyMediaInfo ? . type === "image" ? (
< div key = { `enlarge-reply- ${ index } ` } className = "img-container" >
< span key = { `fta- ${ index } ` } className = "file-thumb-reply" style = { isReplyThumbnailClicked [ index ] ? {} : { width : replyDisplayWidth , height : replyDisplayHeight }}>
< img key = { `fti- ${ index } ` }
2023-04-21 10:47:39 +02:00
src = { replyMediaInfo . url } alt = { replyMediaInfo . type }
2023-07-30 15:39:52 +02:00
onClick = {( e ) => { handleImageClick ( e ); handleThumbnailClick ( index , 'reply' )}}
style = {{ cursor : "pointer" }}
2023-04-21 10:47:39 +02:00
onError = {( e ) => e . target . src = fallbackImgUrl } />
</ span >
2023-07-30 15:39:52 +02:00
</ div >
) : null }
{ replyMediaInfo ? . type === "video" ? (
< div key = { `enlarge-reply- ${ index } ` } className = { `img-container ${ isReplyThumbnailClicked [ index ] ? 'expanded-container' : '' } ` }>
< span key = { `fta- ${ index } ` } className = "file-thumb-reply" style = { isReplyThumbnailClicked [ index ] ? {} : { width : replyDisplayWidth , height : replyDisplayHeight }}>
{ isReplyThumbnailClicked [ index ] ? (
< video controls
className = 'enlarged'
key = { `fti- ${ index } ` }
src = { replyMediaInfo . url }
alt = { replyMediaInfo . type }
style = {{ cursor : "pointer" }}
onError = {( e ) => e . target . src = fallbackImgUrl }
/>
) : (
< video
key = { `fti- ${ index } ` }
src = { replyMediaInfo . url }
alt = "thumbnail"
onClick = {() => { handleThumbnailClick ( index , 'reply' )}}
style = {{ cursor : "pointer" }}
onError = {( e ) => e . target . src = fallbackImgUrl }
/>
)}
</ span >
2023-04-21 10:47:39 +02:00
</ div >
2023-07-30 15:39:52 +02:00
) : null }
{ replyMediaInfo ? . type === "audio" ? (
< span key = { `fta- ${ index } ` } className = "file-thumb-reply" style = { isReplyThumbnailClicked [ index ] ? {} : { width : replyDisplayWidth , height : replyDisplayHeight }}>
< audio controls
key = { `fti- ${ index } ` }
src = { replyMediaInfo . url } alt = { replyMediaInfo . type }
onError = {( e ) => e . target . src = fallbackImgUrl } />
</ span >
) : null }
</ div >
) : null }
2023-04-22 15:12:26 +02:00
< blockquote key = { `pm- ${ index } ` } className = "post-message" >
2023-07-31 08:59:17 +02:00
< Link to = {() => {}} key = { `r-pm- ${ index } ` } className = "quotelink"
2023-06-03 17:22:39 +02:00
ref = { el => {
2023-06-14 10:08:46 +02:00
quoteRefs . current [ reply . cid ] = el ;
2023-04-21 10:47:39 +02:00
}}
2023-06-21 21:53:45 +02:00
onClick = {() => handleQuoteClick ( reply , shortParentCid , null )}
2023-06-03 17:22:39 +02:00
onMouseOver = {( event ) => {
event . stopPropagation ();
handleQuoteHover ( reply , shortParentCid , () => {
2023-06-11 12:17:22 +02:00
setOutOfViewCid ( reply . parentCid );
2023-06-14 10:08:46 +02:00
const rect = quoteRefs . current [ reply . cid ]. getBoundingClientRect ();
2023-06-11 13:59:56 +02:00
const distanceToRight = window . innerWidth - rect . right ;
const distanceToTop = rect . top ;
const distanceToBottom = window . innerHeight - rect . bottom ;
let top ;
if ( distanceToTop < postOnHoverHeight / 2 ) {
top = window . scrollY - 5 ;
} else if ( distanceToBottom < postOnHoverHeight / 2 ) {
top = window . scrollY - postOnHoverHeight + window . innerHeight - 10 ;
} else {
top = rect . top + window . scrollY - postOnHoverHeight / 2 ;
}
2023-07-31 08:59:17 +02:00
2023-06-11 12:17:22 +02:00
if ( distanceToRight < 200 ) {
setOutOfViewPosition ({
2023-06-11 13:59:56 +02:00
top ,
2023-06-11 12:17:22 +02:00
right : window . innerWidth - rect . left - 10 ,
maxWidth : rect . left - 5
});
} else {
setOutOfViewPosition ({
2023-06-11 13:59:56 +02:00
top ,
2023-06-11 12:17:22 +02:00
left : rect . left + rect . width + 5 ,
2023-06-11 13:59:56 +02:00
maxWidth : window . innerWidth - rect . left - rect . width - 5
2023-06-11 12:17:22 +02:00
});
2023-06-03 17:22:39 +02:00
}
});
2023-07-31 08:59:17 +02:00
}}
2023-06-02 13:50:58 +02:00
onMouseLeave = {() => {
removeHighlight ();
setOutOfViewCid ( null );
2023-06-21 21:53:45 +02:00
}}
>
{ `c/ ${ shortParentCid } ` }{ shortParentCid === comment . shortCid ? " (OP)" : null }
</ Link >
2023-07-31 08:59:17 +02:00
< Post key = { `post- ${ index } ` }
2023-06-21 21:53:45 +02:00
content = { reply . content }
2023-06-22 14:59:30 +02:00
postQuoteRef = {( quoteShortParentCid , ref ) => {
postRefs . current [ quoteShortParentCid ] = ref ;
2023-06-21 21:53:45 +02:00
}}
postQuoteOnClick = {( quoteShortParentCid ) => {
handleQuoteClick ( reply , quoteShortParentCid , null )
}}
postQuoteOnOver = {( quoteShortParentCid ) => {
2023-06-22 14:59:30 +02:00
const quoteParentCid = cidTracker [ quoteShortParentCid ];
if ( outOfViewCid !== quoteParentCid ) {
handleQuoteHover ( reply , quoteShortParentCid , () => {
setOutOfViewCid ( quoteParentCid );
2023-06-21 21:53:45 +02:00
2023-07-31 08:59:17 +02:00
const rect = postRefs . current [ quoteShortParentCid ]. getBoundingClientRect ();
const distanceToRight = window . innerWidth - rect . right ;
const distanceToTop = rect . top ;
const distanceToBottom = window . innerHeight - rect . bottom ;
let top ;
2023-06-21 21:53:45 +02:00
2023-07-31 08:59:17 +02:00
if ( distanceToTop < postOnHoverHeight / 2 ) {
top = window . scrollY - 5 ;
} else if ( distanceToBottom < postOnHoverHeight / 2 ) {
top = window . scrollY - postOnHoverHeight + window . innerHeight - 10 ;
} else {
top = rect . top + window . scrollY - postOnHoverHeight / 2 ;
}
if ( distanceToRight < 200 ) {
setOutOfViewPosition ({
top ,
right : window . innerWidth - rect . left - 10 ,
maxWidth : rect . left - 5
});
} else {
setOutOfViewPosition ({
top ,
left : rect . left + rect . width + 5 ,
maxWidth : window . innerWidth - rect . left - rect . width - 5
});
}
})
}}
}
2023-06-21 21:53:45 +02:00
postQuoteOnLeave = {() => {
removeHighlight ();
setOutOfViewCid ( null );
}}
/>
2023-07-31 08:59:17 +02:00
< EditLabel key = { `edit-label-reply- ${ index } ` }
commentCid = { reply . cid }
className = "ttl" />
2023-06-01 10:43:17 +02:00
< StateLabel key = { `state-label-reply- ${ index } ` }
2023-07-31 08:59:17 +02:00
commentIndex = { reply . index }
className = "ttl ellipsis" />
2023-04-21 10:47:39 +02:00
</ blockquote >
</ div >
</ div >
)
})
2023-07-31 08:59:17 +02:00
}
</ div >
< div className = "thread-mobile" key = "thread-mobile" >
< hr />
< div className = "op-container" key = "op-container" >
2023-04-21 10:47:39 +02:00
< div key = { `mob-po- ${ comment . cid } ` } className = "post op op-mobile" >
< div key = { `mob-pi- ${ comment . cid } ` } className = "post-info-mobile" >
2023-04-26 16:22:24 +02:00
< button style = {{ all : 'unset' , cursor : 'pointer' }} key = { `mob-pb- ${ comment . cid } ` } className = "post-menu-button-mobile" >...</ button >
2023-04-21 10:47:39 +02:00
< span className = "name-block-mobile" >
2023-05-22 13:16:16 +02:00
{ comment ? . author ? . displayName
2023-07-31 08:59:17 +02:00
? comment ? . author ? . displayName . length > 15
? <>
< span key = { `mob-n- ${ comment . cid } ` } className = "name-mobile"
data - tooltip - id = "tooltip"
data - tooltip - content = { comment ? . author ? . displayName }
data - tooltip - place = "top" >
{ comment ? . author ? . displayName . slice ( 0 , 15 ) + " (...)" }
</ span >
</>
2023-04-21 10:47:39 +02:00
: < span key = { `mob-n- ${ comment . cid } ` } className = "name-mobile" >
2023-07-31 08:59:17 +02:00
{ comment ? . author ? . displayName }</ span >
: < span key = { `mob-n- ${ comment . cid } ` } className = "name-mobile" >
Anonymous </ span >}
2023-02-27 12:35:23 +01:00
& nbsp ;
2023-04-21 10:47:39 +02:00
< span key = { `mob-pa- ${ comment . cid } ` } className = "poster-address-mobile address-mobile"
2023-07-31 08:59:17 +02:00
id = "reply-button" style = {{ cursor : "pointer" }}
2023-07-08 14:37:08 +02:00
onClick = {() => handleAddressClick (< VerifiedAuthor commentCid = { comment . cid }>{({ shortAuthorAddress }) => ( shortAuthorAddress )}</ VerifiedAuthor >)}
2023-04-20 17:20:26 +02:00
>
2023-03-05 14:15:51 +01:00
( u /
2023-04-21 10:47:39 +02:00
< span key = { `mob-ha- ${ comment . cid } ` } className = "highlight-address-mobile" >
2023-07-08 14:37:08 +02:00
{< VerifiedAuthor commentCid = { comment . cid }>{({ shortAuthorAddress }) => ( shortAuthorAddress )}</ VerifiedAuthor >}
2023-03-29 14:36:41 +02:00
</ span >
2023-04-21 10:47:39 +02:00
) & nbsp ;
2023-02-27 12:35:23 +01:00
</ span >
2023-07-31 08:59:17 +02:00
< span key = { `ti-mob- ${ index } ` } className = "thread-icons-mobile" style = {{ float : "right" , marginRight : "18px" }}>
2023-06-29 09:03:12 +02:00
{ comment . pinned ? (
< img src = "assets/sticky.gif" alt = "Sticky" title = "Sticky"
2023-07-31 08:59:17 +02:00
style = {{ marginTop : "-1px" , marginRight : "2px" ,
imageRendering : "pixelated" ,}} />
2023-06-29 09:03:12 +02:00
) : null }
{ comment . locked ? (
< img src = "assets/closed.gif" alt = "Closed" title = "Closed"
2023-07-31 08:59:17 +02:00
style = {{ marginTop : "-1px" , marginRight : "2px" ,
imageRendering : "pixelated" ,}} />
2023-06-29 09:03:12 +02:00
) : null }
</ span >
2023-04-21 10:47:39 +02:00
< br key = { `mob-br1- ${ comment . cid } ` } />
{ comment . title ? (
2023-07-31 08:59:17 +02:00
comment . title . length > 30 ?
2023-04-21 10:47:39 +02:00
<>
< span key = { `mob-t- ${ comment . cid } ` } className = "subject-mobile"
2023-07-31 08:59:17 +02:00
data - tooltip - id = "tooltip"
data - tooltip - content = { comment . title }
data - tooltip - place = "top" >
2023-04-21 10:47:39 +02:00
{ comment . title . slice ( 0 , 30 ) + " (...)" }
</ span >
</>
: < span key = { `mob-t- ${ comment . cid } ` } className = "subject-mobile" >
{ comment . title }
</ span >) : null }
2023-02-27 12:35:23 +01:00
</ span >
2023-04-21 10:47:39 +02:00
< span key = { `mob-dt- ${ comment . cid } ` } className = "date-time-mobile post-number-mobile" >
{ getDate ( comment ? . timestamp )}
& nbsp ;
2023-05-03 11:01:41 +02:00
< span key = { `mob-no- ${ comment . cid } ` }> c / </ span >
2023-07-31 08:59:17 +02:00
< Link to = {() => {}} id = "reply-button" key = { `mob-no2- ${ comment . cid } ` } title = "Reply to this post"
onClick = {() => {
let text = document . getSelection (). toString ();
text = text ? `> ${ text } ` : text ;
setSelectedText ( text );
if ( isReplyOpen ) {
setReplyQuoteCid ( comment . shortCid );
setTriggerInsertion ( Date . now ());
} else {
setIsReplyOpen ( true );
setSelectedShortCid ( comment . shortCid );
setSelectedParentCid ( comment . cid );
}}}>{ comment . shortCid }</ Link >
2023-02-27 12:35:23 +01:00
</ span >
</ div >
2023-07-07 17:48:24 +02:00
{ comment . link ? (
< div key = { `mob-f- ${ index } ` } className = "file-mobile" >
{ commentMediaInfo ? . type === 'iframe' && (
< div key = { `enlarge-mob- ${ index } ` } className = "img-container" >
< span key = { `mob-fta- ${ index } ` } className = "file-thumb-mobile" >
2023-07-30 15:39:52 +02:00
{( isMobileThreadThumbnailClicked [ index ] || ! commentMediaInfo . thumbnail ) && commentMediaInfo . embedUrl ? (
2023-07-07 17:48:24 +02:00
< div style = {{ width : "92vw" }}>
< iframe
key = { `mob-fti- ${ index } ` }
src = { commentMediaInfo . embedUrl }
2023-07-31 08:59:17 +02:00
style = {{ border : "none" , height : "250px" }}
2023-07-07 17:48:24 +02:00
title = "Embedded content"
2023-07-31 08:59:17 +02:00
allow = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
2023-07-07 17:48:24 +02:00
allowFullScreen />
</ div >
) : (
2023-07-31 08:59:17 +02:00
< img
2023-07-07 17:48:24 +02:00
key = { `mob-fti- ${ index } ` }
2023-07-31 08:59:17 +02:00
src = { commentMediaInfo . thumbnail }
2023-07-07 17:48:24 +02:00
alt = "thumbnail"
2023-07-30 15:39:52 +02:00
onClick = {() => { handleThumbnailClick ( index , 'mobileThread' )}}
2023-07-07 17:48:24 +02:00
style = {{ cursor : "pointer" }}
onError = {( e ) => e . target . src = fallbackImgUrl } />
)}
{ commentMediaInfo ? . type === "video" || "iframe" ? (
2023-07-30 15:39:52 +02:00
isMobileThreadThumbnailClicked [ index ] ? (
2023-07-07 17:48:24 +02:00
< div style = {{ textAlign : "center" , marginTop : "15px" , marginBottom : "15px" }}>
< span className = 'button-mobile' style = {{ float : "none" , cursor : "pointer" }}
2023-07-30 15:39:52 +02:00
onClick = {() => { handleThumbnailClick ( index , 'mobileThread' )}}
2023-07-07 17:48:24 +02:00
> Close </ span >
</ div >
) : (
< div key = { `mob-fi- ${ index } ` } className = "file-info-mobile" > video </ div >
2023-07-31 08:59:17 +02:00
)) : < div key = { `mob-fi- ${ index } ` } className = "file-info-mobile" > video </ div >}
2023-07-07 17:48:24 +02:00
</ span >
</ div >
)}
{ commentMediaInfo ? . url ? (
commentMediaInfo . type === "webpage" ? (
< div key = { `enlarge-mob- ${ index } ` } className = "img-container" >
< span key = { `mob-ft ${ comment . cid } ` } className = "file-thumb-mobile" >
{ comment . thumbnailUrl ? (
< img key = { `mob-img- ${ index } ` }
src = { commentMediaInfo . thumbnail } alt = "thumbnail"
2023-07-30 15:39:52 +02:00
onClick = {( e ) => { handleImageClick ( e ); handleThumbnailClick ( index , 'mobileThread' )}}
2023-07-07 17:48:24 +02:00
style = {{ cursor : "pointer" }}
onError = {( e ) => e . target . src = fallbackImgUrl } />
) : null }
< div key = { `mob-fi- ${ index } ` } className = "file-info-mobile" >{ commentMediaInfo ? . type }</ div >
</ span >
</ div >
) : commentMediaInfo . type === "image" ? (
< div key = { `enlarge-mob- ${ index } ` } className = "img-container" >
< span key = { `mob-ft ${ comment . cid } ` } className = "file-thumb-mobile" >
< img key = { `mob-img- ${ index } ` }
src = { commentMediaInfo . url } alt = { commentMediaInfo . type }
2023-07-30 15:39:52 +02:00
onClick = {( e ) => { handleImageClick ( e ); handleThumbnailClick ( index , 'mobileThread' )}}
2023-04-30 13:32:52 +02:00
style = {{ cursor : "pointer" }}
onError = {( e ) => e . target . src = fallbackImgUrl } />
2023-07-07 17:48:24 +02:00
< div key = { `mob-fi- ${ index } ` } className = "file-info-mobile" >{ commentMediaInfo ? . type }</ div >
</ span >
</ div >
) : commentMediaInfo . type === "video" ? (
< span key = { `mob-ft ${ comment . cid } ` } className = "file-thumb-mobile" >
2023-07-30 15:39:52 +02:00
{ isMobileThreadThumbnailClicked [ index ] ? (
2023-07-07 17:48:24 +02:00
< video key = { `fti- ${ index } ` }
src = { commentMediaInfo . url } alt = { commentMediaInfo . type }
controls
2023-07-31 08:59:17 +02:00
style = {{ cursor : 'pointer' }}
2023-07-07 17:48:24 +02:00
onError = {( e ) => e . target . src = fallbackImgUrl } />
) : (
< video
key = { `fti- ${ index } ` }
src = { commentMediaInfo . url }
alt = "thumbnail"
2023-07-30 15:39:52 +02:00
onClick = {() => { handleThumbnailClick ( index , 'mobileThread' )}}
2023-07-07 17:48:24 +02:00
style = {{ cursor : "pointer" }}
id = "video-thumbnail-mobile"
onError = {( e ) => e . target . src = fallbackImgUrl }
/>
)}
{ commentMediaInfo ? . type === "video" || "iframe" ? (
2023-07-30 15:39:52 +02:00
isMobileThreadThumbnailClicked [ index ] ? (
2023-07-07 17:48:24 +02:00
< div style = {{ textAlign : "center" , marginTop : "15px" , marginBottom : "15px" }}>
< span className = 'button-mobile' style = {{ float : "none" , cursor : "pointer" }}
2023-07-30 15:39:52 +02:00
onClick = {() => { handleThumbnailClick ( index , 'mobileThread' )}}
2023-07-07 17:48:24 +02:00
> Close </ span >
</ div >
) : (
< div key = { `mob-fi- ${ index } ` } className = "file-info-mobile" > video </ div >
)) : < div key = { `mob-fi- ${ index } ` } className = "file-info-mobile" > video </ div >}
2023-07-31 08:59:17 +02:00
</ span >
2023-07-07 17:48:24 +02:00
) : commentMediaInfo . type === "audio" ? (
2023-07-31 08:59:17 +02:00
< span key = { `mob-ft ${ comment . cid } ` } className = "file-thumb-mobile" >
< audio key = { `mob-img- ${ index } ` }
src = { commentMediaInfo . url } alt = { commentMediaInfo . type }
2023-07-07 17:48:24 +02:00
onError = {( e ) => e . target . src = fallbackImgUrl } />
2023-07-31 08:59:17 +02:00
< div key = { `mob-fi- ${ index } ` } className = "file-info-mobile" >{ commentMediaInfo ? . type }</ div >
</ span >
2023-07-07 17:48:24 +02:00
) : null
) : null }
</ div >
2023-04-16 12:54:51 +02:00
) : null }
2023-04-21 10:47:39 +02:00
< blockquote key = { `mob-bq- ${ comment . cid } ` } className = "post-message-mobile" >
{ comment . content ? (
<>
2023-05-31 15:44:15 +02:00
< Post content = { comment . content } comment = { comment } key = { `post-mobile- ${ comment . cid } ` } />
2023-07-31 08:59:17 +02:00
< EditLabel key = { `edit-label-thread-mob- ${ index } ` }
commentCid = { comment . cid }
className = "ttl" />
2023-06-01 10:43:17 +02:00
< StateLabel key = { `state-label-thread-mob- ${ index } ` }
2023-07-31 08:59:17 +02:00
commentIndex = { comment . index }
className = "ttl ellipsis" />
2023-04-21 10:47:39 +02:00
</>
) : null }
</ blockquote >
2023-02-27 12:35:23 +01:00
</ div >
</ div >
2023-04-21 10:47:39 +02:00
{ comment . replyCount === undefined ? < PostLoader /> : null }
2023-04-25 14:34:48 +02:00
{ sortedReplies . map (( reply , index ) => {
2023-04-23 13:37:09 +02:00
const replyMediaInfo = getCommentMediaInfo ( reply );
2023-04-21 10:47:39 +02:00
const shortParentCid = findShortParentCid ( reply . parentCid , comment );
2023-06-26 21:55:26 +02:00
let storedSigners = JSON . parse ( localStorage . getItem ( 'storedSigners' )) || {};
let signerAddress ;
if ( storedSigners [ selectedThread ]) {
signerAddress = storedSigners [ selectedThread ]. address ;
}
2023-04-21 10:47:39 +02:00
return (
2023-07-31 08:59:17 +02:00
< div key = { `mob-rc- ${ index } ` } className = "reply-container" >
< div key = { `mob-pr- ${ index } ` } className = "post-reply post-reply-mobile" >
< div key = { `mob-pi- ${ index } ` } className = "post-info-mobile" >
< button className = "post-menu-button-mobile" title = "Post menu" style = {{ all : 'unset' , cursor : 'pointer' }}>...</ button >
< span key = { `mob-nb- ${ index } ` } className = "name-block-mobile" >
{ reply . author ? . displayName
? reply . author ? . displayName . length > 12
? <>
< span key = { `mob-n- ${ index } ` } className = "name-mobile"
data - tooltip - id = "tooltip"
data - tooltip - content = { reply . author ? . displayName }
data - tooltip - place = "top" >
{ reply . author ? . displayName . slice ( 0 , 12 ) + " (...)" }
</ span >
</>
: < span key = { `mob-n- ${ index } ` } className = "name-mobile" >
{ reply . author ? . displayName }</ span >
: < span key = { `mob-n- ${ index } ` } className = "name-mobile" >
Anonymous </ span >}
& nbsp ;
< span key = { `mob-pa- ${ index } ` } className = "poster-address-mobile address-mobile"
id = "reply-button" style = {{ cursor : "pointer" }}
onClick = {() => handleAddressClick ( reply . author ? . shortAddress )}
>
( u /
2023-04-22 15:43:38 +02:00
{ reply . author ? . shortAddress ?
(
2023-06-26 21:55:26 +02:00
< span key = { `mob-ha- ${ index } ` } className = "highlight-address-mobile" >
{ reply . author ? . shortAddress }
2023-04-22 15:43:38 +02:00
</ span >
2023-06-26 21:55:26 +02:00
) : (
anonymousMode ? (
< span key = { `mob-ha- ${ index } ` }>
{ signerAddress ? . slice ( 8 , 20 )}
</ span >
2023-07-31 08:59:17 +02:00
) : (
2023-06-26 21:55:26 +02:00
< span key = { `mob-ha- ${ index } ` }>
{ account ? . author ? . shortAddress }
</ span >
)
2023-04-22 15:43:38 +02:00
)
}
2023-07-31 08:59:17 +02:00
)
2023-04-21 10:47:39 +02:00
</ span >
2023-07-31 08:59:17 +02:00
< br key = { `mob-br- ${ index } ` } />
</ span >
< span key = { `mob-dt- ${ index } ` } className = "date-time-mobile post-number-mobile" >
{ getDate ( reply ? . timestamp )} & nbsp ;
< span key = { `mob-pl1- ${ index } ` }> c / </ span >
{ reply . shortCid ? (
< Link id = "reply-button" key = { `mob-pl2- ${ index } ` }
onClick = {() => {
let text = document . getSelection (). toString ();
text = text ? `> ${ text } ` : text ;
setSelectedText ( text );
if ( isReplyOpen ) {
setReplyQuoteCid ( reply . shortCid );
setTriggerInsertion ( Date . now ());
} else {
setIsReplyOpen ( true );
setSelectedShortCid ( reply . shortCid );
setSelectedParentCid ( reply . cid );
}}} title = "Reply to this post" >{ reply . shortCid }</ Link >
) : (
< PendingLabel key = "pending-mob" commentIndex = { reply . index } />
)}
</ span >
2023-07-30 22:15:09 +02:00
</ div >
2023-07-31 08:59:17 +02:00
{ reply . link ? (
< div key = { `mob-f- ${ reply . cid } ` } className = "file-mobile" >
{ replyMediaInfo ? . url ? (
replyMediaInfo . type === "webpage" ? (
< div key = "enlarge-reply-mob" className = "img-container" >
< span key = { `mob-ft ${ reply . cid } ` } className = "file-thumb-mobile" >
{ reply . thumbnailUrl ? (
< img key = { `mob-img- ${ reply . cid } ` }
src = { replyMediaInfo . thumbnail } alt = { replyMediaInfo . type }
onClick = { handleImageClick }
style = {{ cursor : "pointer" }}
onError = {( e ) => e . target . src = fallbackImgUrl } />
) : null }
< div key = { `mob-fi- ${ reply . cid } ` } className = "file-info-mobile" >{ replyMediaInfo . type }</ div >
</ span >
</ div >
) : replyMediaInfo . type === "image" ? (
< div key = "enlarge-reply-mob" className = "img-container" >
< span key = { `mob-ft ${ reply . cid } ` } className = "file-thumb-mobile" >
< img key = { `mob-img- ${ reply . cid } ` }
src = { replyMediaInfo . url } alt = { replyMediaInfo . type }
onClick = { handleImageClick }
style = {{ cursor : "pointer" }}
onError = {( e ) => e . target . src = fallbackImgUrl } />
< div key = { `mob-fi- ${ reply . cid } ` } className = "file-info-mobile" >{ replyMediaInfo . type }</ div >
</ span >
</ div >
) : replyMediaInfo . type === "video" ? (
< span key = { `mob-ft ${ reply . cid } ` } className = "file-thumb-mobile" >
< video key = { `fti- ${ reply . cid } ` }
src = { replyMediaInfo . url } alt = { replyMediaInfo . type }
style = {{ pointerEvents : "none" }}
onError = {( e ) => e . target . src = fallbackImgUrl } />
< div key = { `mob-fi- ${ reply . cid } ` } className = "file-info-mobile" >{ replyMediaInfo . type }</ div >
</ span >
) : replyMediaInfo . type === "audio" ? (
< span key = { `mob-ft ${ reply . cid } ` } className = "file-thumb-mobile" >
< audio key = { `mob-img- ${ reply . cid } ` }
src = { replyMediaInfo . url } alt = { replyMediaInfo . type }
onError = {( e ) => e . target . src = fallbackImgUrl } />
< div key = { `mob-fi- ${ reply . cid } ` } className = "file-info-mobile" >{ replyMediaInfo . type }</ div >
</ span >
) : null
) : null }
</ div >
) : null }
< blockquote key = { `mob-pm- ${ index } ` } className = "post-message-mobile" >
< span style = {{ cursor : 'pointer' }} key = { `mob-ql- ${ index } ` } className = "quotelink-mobile"
ref = { el => {
quoteRefsMobile . current [ reply . cid ] = el ;
}}
onClick = {( event ) => handleQuoteClick ( reply , shortParentCid , event )}
onMouseOver = {( event ) => {
event . stopPropagation ();
handleQuoteHover ( reply , shortParentCid , () => {
setOutOfViewCid ( reply . parentCid );
const rect = quoteRefsMobile . current [ reply . cid ]. getBoundingClientRect ();
const distanceToRight = window . innerWidth - rect . right ;
const distanceToTop = rect . top ;
const distanceToBottom = window . innerHeight - rect . bottom ;
let top ;
if ( distanceToTop < postOnHoverHeight / 2 ) {
top = window . scrollY - 5 ;
} else if ( distanceToBottom < postOnHoverHeight / 2 ) {
top = window . scrollY - postOnHoverHeight + window . innerHeight - 10 ;
} else {
top = rect . top + window . scrollY - postOnHoverHeight / 2 ;
}
if ( distanceToRight < 200 ) {
setOutOfViewPosition ({
top ,
right : window . innerWidth - rect . left - 10 ,
maxWidth : rect . left - 5
});
} else {
setOutOfViewPosition ({
top ,
left : rect . left + rect . width + 5 ,
maxWidth : window . innerWidth - rect . left - rect . width - 5
});
}
});
}}
onMouseLeave = {() => {
removeHighlight ();
setOutOfViewCid ( null );
}}>
{ `c/ ${ shortParentCid } ` }{ shortParentCid === comment . shortCid ? " (OP)" : null }
</ span >
< Post key = { `post-mobile- ${ index } ` }
content = { reply . content }
postQuoteRef = {( quoteShortParentCid , ref ) => {
postRefs . current [ quoteShortParentCid ] = ref ;
}}
postQuoteOnClick = {( quoteShortParentCid ) => {
handleQuoteClick ( reply , quoteShortParentCid , null )
}}
postQuoteOnOver = {( quoteShortParentCid ) => {
const quoteParentCid = cidTracker [ quoteShortParentCid ];
if ( outOfViewCid !== quoteParentCid ) {
handleQuoteHover ( reply , quoteShortParentCid , () => {
setOutOfViewCid ( quoteParentCid );
const rect = postRefs . current [ quoteShortParentCid ]. getBoundingClientRect ();
const distanceToRight = window . innerWidth - rect . right ;
const distanceToTop = rect . top ;
const distanceToBottom = window . innerHeight - rect . bottom ;
let top ;
if ( distanceToTop < postOnHoverHeight / 2 ) {
top = window . scrollY - 5 ;
} else if ( distanceToBottom < postOnHoverHeight / 2 ) {
top = window . scrollY - postOnHoverHeight + window . innerHeight - 10 ;
} else {
top = rect . top + window . scrollY - postOnHoverHeight / 2 ;
}
if ( distanceToRight < 200 ) {
setOutOfViewPosition ({
top ,
right : window . innerWidth - rect . left - 10 ,
maxWidth : rect . left - 5
});
} else {
setOutOfViewPosition ({
top ,
left : rect . left + rect . width + 5 ,
maxWidth : window . innerWidth - rect . left - rect . width - 5
});
}
})
}}
}
postQuoteOnLeave = {() => {
removeHighlight ();
setOutOfViewCid ( null );
}}
/>
< EditLabel key = { `edit-label-reply-mob- ${ index } ` }
commentCid = { reply . cid }
className = "ttl" />
< StateLabel key = { `state-label-reply-mob- ${ index } ` }
commentIndex = { reply . index }
className = "ttl ellipsis" />
</ blockquote >
{ reply . replyCount > 0 ? (
< div key = { `back-mob- ${ index } ` } className = 'backlink backlink-mobile' >
{ reply . replies ? . pages ? . topAll . comments
. sort (( a , b ) => a . timestamp - b . timestamp )
. map (( reply , index ) => (
< div key = { `div-back ${ index } ` } style = {{ display : 'inline-block' }}
ref = { el => {
backlinkRefsMobile . current [ reply . cid ] = el ;
}}>
< span style = {{ cursor : 'pointer' }} key = { `ql- ${ index } ` } className = "quote-link"
onClick = {( event ) => handleQuoteClick ( reply , reply . shortCid , event )}
onMouseOver = {( event ) => {
event . stopPropagation ();
handleQuoteHover ( reply , reply . shortCid , () => {
setOutOfViewCid ( reply . cid )
const rect = backlinkRefsMobile . current [ reply . cid ]. getBoundingClientRect ();
const distanceToRight = window . innerWidth - rect . right ;
const distanceToTop = rect . top ;
const distanceToBottom = window . innerHeight - rect . bottom ;
let top ;
if ( distanceToTop < postOnHoverHeight / 2 ) {
top = window . scrollY - 5 ;
} else if ( distanceToBottom < postOnHoverHeight / 2 ) {
top = window . scrollY - postOnHoverHeight + window . innerHeight - 10 ;
} else {
top = rect . top + window . scrollY - postOnHoverHeight / 2 ;
}
if ( distanceToRight < 200 ) {
setOutOfViewPosition ({
top ,
right : window . innerWidth - rect . left - 10 ,
maxWidth : rect . left - 5
});
} else {
setOutOfViewPosition ({
top ,
left : rect . left + rect . width + 5 ,
maxWidth : window . innerWidth - rect . left - rect . width - 5
});
}
});
}}
onMouseLeave = {() => {
removeHighlight ();
setOutOfViewCid ( null );
}} >
c / { reply . shortCid }</ span >
& nbsp ;
</ div >
))}
</ div >
) : null }
2023-04-21 10:47:39 +02:00
</ div >
2023-07-31 08:59:17 +02:00
</ div >
2023-03-18 22:14:31 +01:00
)
2023-04-21 10:47:39 +02:00
})
2023-07-31 08:59:17 +02:00
}
</ div >
< BottomBar selectedStyle = { selectedStyle }>
2023-04-21 10:47:39 +02:00
< div id = "bottombar-desktop" >
< hr />
< span className = "bottom-bar-return" >
[
2023-04-08 22:30:44 +02:00
< Link to = { `/p/ ${ selectedAddress } ` }> Return </ Link >
2023-04-21 10:47:39 +02:00
]
2023-02-24 18:13:02 +01:00
</ span >
2023-04-21 10:47:39 +02:00
< span className = "bottom-bar-catalog" >
[
2023-04-08 22:30:44 +02:00
< Link to = { `/p/ ${ selectedAddress } /catalog` }> Catalog </ Link >
2023-04-21 10:47:39 +02:00
]
2023-02-24 18:13:02 +01:00
</ span >
2023-04-21 10:47:39 +02:00
< span className = "bottom-bar-top" >
[
2023-07-31 08:59:17 +02:00
< span id = "button" onClick = {() => window . scrollTo ( 0 , 0 )}
onMouseOver = {( event ) => event . target . style . cursor = 'pointer' }
onTouchStart = {() => window . scrollTo ( 0 , 0 )}> Top </ span >
2023-04-21 10:47:39 +02:00
]
2023-02-27 12:35:23 +01:00
</ span >
2023-04-21 10:47:39 +02:00
< span className = "quickreply-button" >
2023-07-31 08:59:17 +02:00
[
< span id = "button" onClick = {() => { setIsReplyOpen ( true ); setSelectedParentCid ( comment . cid ); setSelectedShortCid ( comment . shortCid );}} onMouseOver = {( event ) => event . target . style . cursor = 'pointer' }> Post a Reply </ span >
]
2023-04-21 10:47:39 +02:00
</ span >
2023-04-29 12:34:47 +02:00
{ comment ? (
comment . replyCount !== undefined ? (
comment . replyCount > 0 ? (
comment . replyCount === 1 ? (
< span className = "reply-stat" >{ comment . replyCount } reply </ span >
) : (
< span className = "reply-stat" >{ comment . replyCount } replies </ span >
)
) : (
< span className = "reply-stat" > No replies yet </ span >
)
) : (
2023-05-16 12:40:29 +02:00
< span className = { stateString ? "reply-stat ellipsis" : "" }>{ stateString }</ span >
2023-04-29 12:34:47 +02:00
)
2023-04-21 10:47:39 +02:00
) : (
2023-05-16 12:40:29 +02:00
< span className = { stateString ? "reply-stat ellipsis" : "" }>{ stateString }</ span >
2023-04-21 10:47:39 +02:00
)}
< hr />
</ div >
</ BottomBar >
2023-04-21 18:16:05 +02:00
{ comment . replyCount > 2 ? (
2023-04-21 17:13:13 +02:00
< div id = "bottombar-mobile" >
2023-07-31 08:59:17 +02:00
< hr style = {{ marginTop : "30px" }} />
< TopBar selectedStyle = { selectedStyle } style = {{ marginTop : "-5px" }}>
2023-04-21 17:13:13 +02:00
< span className = "style-changer" >
Style :
2023-07-31 08:59:17 +02:00
2023-04-21 17:13:13 +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 >
{ comment ? (
comment . replyCount !== undefined ? (
comment . replyCount > 0 ? (
comment . replyCount === 1 ? (
< span className = "reply-stat" >{ comment . replyCount } reply </ span >
) : (
< span className = "reply-stat" >{ comment . replyCount } replies </ span >
)
) : (
< span className = "reply-stat" > No replies yet </ span >
)
2023-04-21 10:47:39 +02:00
) : (
2023-04-21 17:13:13 +02:00
< span className = "reply-stat" > Loading ...</ span >
2023-04-21 10:47:39 +02:00
)
) : (
2023-04-21 17:13:13 +02:00
null
)}
< hr />
</ TopBar >
< ReplyFormLink id = "post-form-link" selectedStyle = { selectedStyle } >
< div id = "post-form-link-mobile" className = "post-button-mobile" >
< span className = "btn-wrap" >
2023-07-31 08:59:17 +02:00
< span style = {{ cursor : 'pointer' }} onClick = {() => { setIsReplyOpen ( true ); setSelectedParentCid ( comment . cid ); setSelectedShortCid ( comment . shortCid );}} onMouseOver = {( event ) => event . target . style . cursor = 'pointer' }> Post a Reply </ span >
2023-04-21 17:13:13 +02:00
</ span >
</ div >
< div id = "btns-container" >
< div id = "return-button-mobile" >
< span className = "btn-wrap" >
< Link to = { `/p/ ${ selectedAddress } ` }> Return </ Link >
</ span >
</ div >
2023-07-31 08:59:17 +02:00
< div id = "catalog-button-mobile" style = {{ paddingRight : "2px" }}>
2023-04-21 17:13:13 +02:00
< span className = "btn-wrap" >
< Link to = { `/p/ ${ selectedAddress } /catalog` }> Catalog </ Link >
</ span >
</ div >
< span className = "bottom-bar-top" >
< span className = "btn-wrap" >
2023-07-31 08:59:17 +02:00
< span onClick = {() => window . scrollTo ( 0 , 0 )}
onMouseOver = {( event ) => event . target . style . cursor = 'pointer' }
onTouchStart = {() => window . scrollTo ( 0 , 0 )}
style = {{ cursor : 'pointer' , marginRight : "10px" , marginLeft : "10px" }}
2023-04-26 16:22:24 +02:00
> Top </ span >
2023-04-21 17:13:13 +02:00
</ span >
</ span >
</ div >
</ ReplyFormLink >
2023-04-21 10:47:39 +02:00
</ div >
2023-04-21 17:13:13 +02:00
) : ( null )}
2023-07-31 08:59:17 +02:00
</>
)) : null }
2023-06-10 12:28:21 +02:00
{ outOfViewCid && outOfViewPosition && createPortal (
2023-06-03 16:33:59 +02:00
< div
2023-06-10 12:28:21 +02:00
ref = { postOnHoverRef }
2023-06-03 16:33:59 +02:00
style = {{
2023-06-10 12:28:21 +02:00
display : "block" ,
2023-06-03 16:33:59 +02:00
position : "absolute" ,
2023-06-11 13:59:56 +02:00
top : outOfViewPosition . top ,
2023-06-10 13:07:16 +02:00
right : outOfViewPosition . right ,
2023-06-11 13:59:56 +02:00
left : outOfViewPosition . left ,
2023-06-10 12:28:21 +02:00
maxWidth : outOfViewPosition . maxWidth ,
2023-06-03 16:33:59 +02:00
}}
2023-06-10 12:28:21 +02:00
>
< PostOnHover
cid = { outOfViewCid }
feed = { comment }
/>
</ div >
2023-07-31 08:59:17 +02:00
, document . body )}
2023-04-21 10:47:39 +02:00
</ BoardForm >
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 :
2023-07-31 08:59:17 +02:00
2023-04-24 13:09:59 +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/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 ;
</ 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 }
2023-05-01 21:58:19 +02:00
</ span >
2023-07-31 08:59:17 +02:00
))}
< span className = "nav" >
[
< 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-04-24 13:09:59 +02:00
[
< Link to = { `/p/ ${ selectedAddress } /c/ ${ selectedThread } /settings` } onClick = {() => setIsSettingsOpen ( true )}> Settings </ Link >
]
[
2023-07-31 08:59:17 +02:00
< Link to = "/" onClick = {() => handleStyleChange ({ target : { value : "Yotsuba" }}
2023-04-24 13:09:59 +02:00
)}> 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" ,
}}>
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-04-24 13:09:59 +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-04-24 13:09:59 +02:00
</ div >
</ Footer >
2023-04-21 10:47:39 +02:00
</ Container >
</>
2023-02-12 21:20:08 +01:00
);
}
export default Thread ;