mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix virtuoso media glitch in all feed views
This commit is contained in:
@@ -108,8 +108,10 @@ const Subscriptions = () => {
|
||||
const [moderatorPermissions, setModeratorPermissions] = useState({});
|
||||
const [executeAnonMode, setExecuteAnonMode] = useState(false);
|
||||
const [cidTracker, setCidTracker] = useState({});
|
||||
const [isThumbnailClicked, setIsThumbnailClicked] = useState({});
|
||||
const [isMobileThumbnailClicked, setIsMobileThumbnailClicked] = useState({});
|
||||
const [isThreadThumbnailClicked, setIsThreadThumbnailClicked] = useState({});
|
||||
const [isReplyThumbnailClicked, setIsReplyThumbnailClicked] = useState({});
|
||||
const [isMobileThreadThumbnailClicked, setIsMobileThreadThumbnailClicked] = useState({});
|
||||
const [isMobileReplyThumbnailClicked, setIsMobileReplyThumbnailClicked] = useState({});
|
||||
const [isCreateBoardOpen, setIsCreateBoardOpen] = useState(false);
|
||||
|
||||
const setSelectedThreadCid = (cid) => { selectedThreadCidRef.current = cid };
|
||||
@@ -130,17 +132,35 @@ const Subscriptions = () => {
|
||||
}
|
||||
}, [feed, setFeedCacheState]);
|
||||
|
||||
const handleThumbnailClick = (index, isMobile=false) => {
|
||||
if (isMobile) {
|
||||
setIsMobileThumbnailClicked(prevState => ({
|
||||
...prevState,
|
||||
[index]: !prevState[index],
|
||||
}));
|
||||
} else {
|
||||
setIsThumbnailClicked(prevState => ({
|
||||
...prevState,
|
||||
[index]: !prevState[index],
|
||||
}));
|
||||
|
||||
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;
|
||||
case 'mobileReply':
|
||||
setIsMobileReplyThumbnailClicked(prevState => ({
|
||||
...prevState,
|
||||
[index]: !prevState[index],
|
||||
}));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -675,6 +695,21 @@ const Subscriptions = () => {
|
||||
const commentMediaInfo = getCommentMediaInfo(thread);
|
||||
const fallbackImgUrl = "assets/filedeleted-res.gif";
|
||||
const isModerator = moderatorPermissions[thread.subplebbitAddress];
|
||||
let displayWidth, displayHeight, displayWidthMobile, displayHeightMobile;
|
||||
if (thread.linkWidth && thread.linkHeight) {
|
||||
let scale = Math.min(1, 250 / Math.max(thread.linkWidth, thread.linkHeight));
|
||||
displayWidth = `${thread.linkWidth * scale}px`;
|
||||
displayHeight = `${thread.linkHeight * scale}px`;
|
||||
|
||||
scale = Math.min(1, 100 / Math.max(thread.linkWidth, thread.linkHeight));
|
||||
displayWidthMobile = `${thread.linkWidth * scale}px`;
|
||||
displayHeightMobile = `${thread.linkHeight * scale}px`;
|
||||
} else {
|
||||
displayWidth = '250px';
|
||||
displayHeight = '250px';
|
||||
displayWidthMobile = '100px';
|
||||
displayHeightMobile = '100px';
|
||||
}
|
||||
return (
|
||||
<Fragment key={`fr-${index}`}>
|
||||
<div key={`t-${index}`} className="thread">
|
||||
@@ -692,21 +727,21 @@ const Subscriptions = () => {
|
||||
commentMediaInfo?.url.slice(0, 30) + "(...)" :
|
||||
commentMediaInfo?.url
|
||||
}</a> ({commentMediaInfo?.type === "iframe" ? "video" : commentMediaInfo?.type})
|
||||
{isThumbnailClicked[index] ? (
|
||||
{isThreadThumbnailClicked[index] ? (
|
||||
<span>
|
||||
-[
|
||||
<span className='reply-link'
|
||||
style={{textDecoration: 'underline', cursor: 'pointer'}}
|
||||
onClick={() => {handleThumbnailClick(index)}}>Close</span>
|
||||
onClick={() => {handleThumbnailClick(index, 'thread')}}>Close</span>
|
||||
]
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
{commentMediaInfo?.type === 'iframe' && (
|
||||
<div key={`enlarge-${index}`}
|
||||
className={`img-container ${isThumbnailClicked[index] ? 'expanded-container' : ''}`}>
|
||||
<span key={`fta-${index}`} className="file-thumb">
|
||||
{(isThumbnailClicked[index] || !commentMediaInfo.thumbnail) && commentMediaInfo.embedUrl ? (
|
||||
className={`img-container ${isThreadThumbnailClicked[index] ? 'expanded-container' : ''}`}>
|
||||
<span key={`fta-${index}`} className="file-thumb" style={isThreadThumbnailClicked[index] ? {} : {width: displayWidth, height: displayHeight}}>
|
||||
{(isThreadThumbnailClicked[index] || !commentMediaInfo.thumbnail) && commentMediaInfo.embedUrl ? (
|
||||
<iframe
|
||||
className='enlarged'
|
||||
key={`fti-${index}`}
|
||||
@@ -722,7 +757,7 @@ const Subscriptions = () => {
|
||||
key={`fti-${index}`}
|
||||
src={commentMediaInfo.thumbnail}
|
||||
alt="thumbnail"
|
||||
onClick={() => {handleThumbnailClick(index)}}
|
||||
onClick={() => {handleThumbnailClick(index, 'thread')}}
|
||||
style={{cursor: "pointer"}}
|
||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||
)}
|
||||
@@ -731,11 +766,11 @@ const Subscriptions = () => {
|
||||
)}
|
||||
{commentMediaInfo?.type === "webpage" ? (
|
||||
<div key={`enlarge-${index}`} className="img-container">
|
||||
<span key={`fta-${index}`} className="file-thumb">
|
||||
<span key={`fta-${index}`} className="file-thumb" style={isThreadThumbnailClicked[index] ? {} : {width: displayWidth, height: displayHeight}}>
|
||||
{thread.thumbnailUrl ? (
|
||||
<img key={`fti-${index}`}
|
||||
src={commentMediaInfo.thumbnail} alt={commentMediaInfo.type}
|
||||
onClick={handleImageClick}
|
||||
onClick={(e) => {handleImageClick(e); handleThumbnailClick(index, 'thread')}}
|
||||
style={{cursor: "pointer"}}
|
||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||
) : null}
|
||||
@@ -744,19 +779,19 @@ const Subscriptions = () => {
|
||||
) : null}
|
||||
{commentMediaInfo?.type === "image" ? (
|
||||
<div key={`enlarge-${index}`} className="img-container">
|
||||
<span key={`fta-${index}`} className="file-thumb">
|
||||
<span key={`fta-${index}`} className="file-thumb" style={isThreadThumbnailClicked[index] ? {} : {width: displayWidth, height: displayHeight}}>
|
||||
<img key={`fti-${index}`}
|
||||
src={commentMediaInfo.url} alt={commentMediaInfo.type}
|
||||
onClick={handleImageClick}
|
||||
onClick={(e) => {handleImageClick(e); handleThumbnailClick(index, 'thread')}}
|
||||
style={{cursor: "pointer"}}
|
||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||
</span>
|
||||
</div>
|
||||
) : null}
|
||||
{commentMediaInfo?.type === "video" ? (
|
||||
<div key={`enlarge-${index}`} className={`img-container ${isThumbnailClicked[index] ? 'expanded-container' : ''}`}>
|
||||
<span key={`fta-${index}`} className="file-thumb">
|
||||
{isThumbnailClicked[index] ? (
|
||||
<div key={`enlarge-${index}`} className={`img-container ${isThreadThumbnailClicked[index] ? 'expanded-container' : ''}`}>
|
||||
<span key={`fta-${index}`} className="file-thumb" style={isThreadThumbnailClicked[index] ? {} : {width: displayWidth, height: displayHeight}}>
|
||||
{isThreadThumbnailClicked[index] ? (
|
||||
<video
|
||||
className='enlarged'
|
||||
key={`fti-${index}`}
|
||||
@@ -770,7 +805,7 @@ const Subscriptions = () => {
|
||||
key={`fti-${index}`}
|
||||
src={commentMediaInfo.url}
|
||||
alt="thumbnail"
|
||||
onClick={() => {handleThumbnailClick(index)}}
|
||||
onClick={() => {handleThumbnailClick(index, 'thread')}}
|
||||
style={{cursor: "pointer"}}
|
||||
onError={(e) => e.target.src = fallbackImgUrl}
|
||||
/>
|
||||
@@ -779,7 +814,7 @@ const Subscriptions = () => {
|
||||
</div>
|
||||
) : null}
|
||||
{commentMediaInfo?.type === "audio" ? (
|
||||
<span key={`fta-${index}`} className="file-thumb">
|
||||
<span key={`fta-${index}`} className="file-thumb" style={isThreadThumbnailClicked[index] ? {} : {width: displayWidth, height: displayHeight}}>
|
||||
<audio controls key={`fti-${index}`}
|
||||
src={commentMediaInfo.url} alt={commentMediaInfo.type}
|
||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||
@@ -1073,6 +1108,15 @@ const Subscriptions = () => {
|
||||
const replyMediaInfo = getCommentMediaInfo(reply);
|
||||
const fallbackImgUrl = "assets/filedeleted-res.gif";
|
||||
const shortParentCid = findShortParentCid(reply.parentCid, selectedFeed);
|
||||
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';
|
||||
}
|
||||
return (
|
||||
<div key={`rc-${index}`} className="reply-container">
|
||||
<div key={`sa-${index}`} className="side-arrows">{'>>'}</div>
|
||||
@@ -1334,11 +1378,11 @@ const Subscriptions = () => {
|
||||
</div>
|
||||
{replyMediaInfo?.type === "webpage" ? (
|
||||
<div key={`enlarge-reply-${index}`} className="img-container">
|
||||
<span key={`fta-${index}`} className="file-thumb-reply">
|
||||
<span key={`fta-${index}`} className="file-thumb-reply" style={isReplyThumbnailClicked[index] ? {} : {width: replyDisplayWidth, height: replyDisplayHeight}}>
|
||||
{reply.thumbnailUrl ? (
|
||||
<img key={`fti-${index}`}
|
||||
src={replyMediaInfo.thumbnail} alt={replyMediaInfo.type}
|
||||
onClick={handleImageClick}
|
||||
onClick={(e) => {handleImageClick(e); handleThumbnailClick(index, 'reply')}}
|
||||
style={{cursor: "pointer"}}
|
||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||
) : null}
|
||||
@@ -1347,17 +1391,17 @@ const Subscriptions = () => {
|
||||
) : null}
|
||||
{replyMediaInfo?.type === "image" ? (
|
||||
<div key={`enlarge-reply-${index}`} className="img-container">
|
||||
<span key={`fta-${index}`} className="file-thumb-reply">
|
||||
<span key={`fta-${index}`} className="file-thumb-reply" style={isReplyThumbnailClicked[index] ? {} : {width: replyDisplayWidth, height: replyDisplayHeight}}>
|
||||
<img key={`fti-${index}`}
|
||||
src={replyMediaInfo.url} alt={replyMediaInfo.type}
|
||||
onClick={handleImageClick}
|
||||
onClick={(e) => {handleImageClick(e); handleThumbnailClick(index, 'reply')}}
|
||||
style={{cursor: "pointer"}}
|
||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||
</span>
|
||||
</div>
|
||||
) : null}
|
||||
{replyMediaInfo?.type === "video" ? (
|
||||
<span key={`fta-${index}`} className="file-thumb-reply">
|
||||
<span key={`fta-${index}`} className="file-thumb-reply" style={isReplyThumbnailClicked[index] ? {} : {width: replyDisplayWidth, height: replyDisplayHeight}}>
|
||||
<video controls
|
||||
key={`fti-${index}`}
|
||||
src={replyMediaInfo.url} alt={replyMediaInfo.type}
|
||||
@@ -1365,7 +1409,7 @@ const Subscriptions = () => {
|
||||
</span>
|
||||
) : null}
|
||||
{replyMediaInfo?.type === "audio" ? (
|
||||
<span key={`fta-${index}`} className="file-thumb-reply">
|
||||
<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}
|
||||
@@ -1692,8 +1736,8 @@ const Subscriptions = () => {
|
||||
<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">
|
||||
{(isMobileThumbnailClicked[index] || !commentMediaInfo.thumbnail) && commentMediaInfo.embedUrl ? (
|
||||
<span key={`mob-fta-${index}`} className="file-thumb-mobile" style={isMobileThreadThumbnailClicked[index] ? {} : {marginBottom: '25px'}}>
|
||||
{(isMobileThreadThumbnailClicked[index] || !commentMediaInfo.thumbnail) && commentMediaInfo.embedUrl ? (
|
||||
<div style={{width: "92vw"}}>
|
||||
<iframe
|
||||
key={`mob-fti-${index}`}
|
||||
@@ -1708,15 +1752,15 @@ const Subscriptions = () => {
|
||||
key={`mob-fti-${index}`}
|
||||
src={commentMediaInfo.thumbnail}
|
||||
alt="thumbnail"
|
||||
onClick={() => {handleThumbnailClick(index, true)}}
|
||||
onClick={() => {handleThumbnailClick(index, 'mobileThread')}}
|
||||
style={{cursor: "pointer"}}
|
||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||
)}
|
||||
{commentMediaInfo?.type === "video" || "iframe" ? (
|
||||
isMobileThumbnailClicked[index] ? (
|
||||
isMobileThreadThumbnailClicked[index] ? (
|
||||
<div style={{textAlign: "center", marginTop: "15px", marginBottom: "15px"}}>
|
||||
<span className='button-mobile' style={{float: "none", cursor: "pointer"}}
|
||||
onClick={() => {handleThumbnailClick(index, true)}}
|
||||
onClick={() => {handleThumbnailClick(index, 'mobileThread')}}
|
||||
>Close</span>
|
||||
</div>
|
||||
) : (
|
||||
@@ -1728,11 +1772,11 @@ const Subscriptions = () => {
|
||||
{commentMediaInfo?.url ? (
|
||||
commentMediaInfo.type === "webpage" ? (
|
||||
<div key={`enlarge-mob-${index}`} className="img-container">
|
||||
<span key={`mob-ft${thread.cid}`} className="file-thumb-mobile">
|
||||
<span key={`mob-ft${thread.cid}`} className="file-thumb-mobile" style={isMobileThreadThumbnailClicked[index] ? {} : {width: displayWidthMobile, height: displayHeightMobile, marginBottom: '25px'}}>
|
||||
{thread.thumbnailUrl ? (
|
||||
<img key={`mob-img-${index}`}
|
||||
src={commentMediaInfo.thumbnail} alt="thumbnail"
|
||||
onClick={handleImageClick}
|
||||
onClick={(e) => {handleImageClick(e); handleThumbnailClick(index, 'mobileThread')}}
|
||||
style={{cursor: "pointer"}}
|
||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||
) : null}
|
||||
@@ -1741,18 +1785,18 @@ const Subscriptions = () => {
|
||||
</div>
|
||||
) : commentMediaInfo.type === "image" ? (
|
||||
<div key={`enlarge-mob-${index}`} className="img-container">
|
||||
<span key={`mob-ft${thread.cid}`} className="file-thumb-mobile">
|
||||
<span key={`mob-ft${thread.cid}`} className="file-thumb-mobile" style={isMobileThreadThumbnailClicked[index] ? {} : {width: displayWidthMobile, height: displayHeightMobile, marginBottom: '25px'}}>
|
||||
<img key={`mob-img-${index}`}
|
||||
src={commentMediaInfo.url} alt={commentMediaInfo.type}
|
||||
onClick={handleImageClick}
|
||||
onClick={(e) => {handleImageClick(e); handleThumbnailClick(index, 'mobileThread')}}
|
||||
style={{cursor: "pointer"}}
|
||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||
<div key={`mob-fi-${index}`} className="file-info-mobile">{commentMediaInfo?.type}</div>
|
||||
</span>
|
||||
</div>
|
||||
) : commentMediaInfo.type === "video" ? (
|
||||
<span key={`mob-ft${thread.cid}`} className="file-thumb-mobile">
|
||||
{isMobileThumbnailClicked[index] ? (
|
||||
<span key={`mob-ft${thread.cid}`} className="file-thumb-mobile" style={isMobileThreadThumbnailClicked[index] ? {} : {marginBottom: '25px'}}>
|
||||
{isMobileThreadThumbnailClicked[index] ? (
|
||||
<video key={`fti-${index}`}
|
||||
src={commentMediaInfo.url} alt={commentMediaInfo.type}
|
||||
controls
|
||||
@@ -1763,17 +1807,17 @@ const Subscriptions = () => {
|
||||
key={`fti-${index}`}
|
||||
src={commentMediaInfo.url}
|
||||
alt="thumbnail"
|
||||
onClick={() => {handleThumbnailClick(index, true)}}
|
||||
onClick={() => {handleThumbnailClick(index, 'mobileThread')}}
|
||||
style={{cursor: "pointer"}}
|
||||
id="video-thumbnail-mobile"
|
||||
onError={(e) => e.target.src = fallbackImgUrl}
|
||||
/>
|
||||
)}
|
||||
{commentMediaInfo?.type === "video" || "iframe" ? (
|
||||
isMobileThumbnailClicked[index] ? (
|
||||
isMobileThreadThumbnailClicked[index] ? (
|
||||
<div style={{textAlign: "center", marginTop: "15px", marginBottom: "15px"}}>
|
||||
<span className='button-mobile' style={{float: "none", cursor: "pointer"}}
|
||||
onClick={() => {handleThumbnailClick(index, true)}}
|
||||
onClick={() => {handleThumbnailClick(index, 'mobileThread')}}
|
||||
>Close</span>
|
||||
</div>
|
||||
) : (
|
||||
@@ -1781,7 +1825,7 @@ const Subscriptions = () => {
|
||||
)) : <div key={`mob-fi-${index}`} className="file-info-mobile">video</div>}
|
||||
</span>
|
||||
) : commentMediaInfo.type === "audio" ? (
|
||||
<span key={`mob-ft${thread.cid}`} className="file-thumb-mobile">
|
||||
<span key={`mob-ft${thread.cid}`} className="file-thumb-mobile" style={isMobileThreadThumbnailClicked[index] ? {} : {width: displayWidthMobile, height: displayHeightMobile, marginBottom: '25px'}}>
|
||||
<audio key={`mob-img-${index}`}
|
||||
src={commentMediaInfo.url} alt={commentMediaInfo.type}
|
||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||
@@ -1934,11 +1978,11 @@ const Subscriptions = () => {
|
||||
{replyMediaInfo?.url ? (
|
||||
replyMediaInfo.type === "webpage" ? (
|
||||
<div key={`enlarge-mob-reply-${index}`} className="img-container">
|
||||
<span key={`mob-ft${reply.cid}`} className="file-thumb-mobile">
|
||||
<span key={`mob-ft${reply.cid}`} className="file-thumb-mobile" style={isMobileReplyThumbnailClicked[index] ? {} : {width: displayWidthMobile, height: displayHeightMobile}}>
|
||||
{reply.thumbnailUrl ? (
|
||||
<img key={`mob-img-${index}`}
|
||||
src={replyMediaInfo.thumbnail} alt="thumbnail"
|
||||
onClick={handleImageClick}
|
||||
onClick={(e) => {handleImageClick(e); handleThumbnailClick(index, 'mobileReply')}}
|
||||
style={{cursor: "pointer"}}
|
||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||
) : null}
|
||||
@@ -1947,17 +1991,17 @@ const Subscriptions = () => {
|
||||
</div>
|
||||
) : replyMediaInfo.type === "image" ? (
|
||||
<div key={`enlarge-mob-reply-${index}`} className="img-container">
|
||||
<span key={`mob-ft${reply.cid}`} className="file-thumb-mobile">
|
||||
<span key={`mob-ft${reply.cid}`} className="file-thumb-mobile" style={isMobileReplyThumbnailClicked[index] ? {} : {width: displayWidthMobile, height: displayHeightMobile}}>
|
||||
<img key={`mob-img-${index}`}
|
||||
src={replyMediaInfo.url} alt={replyMediaInfo.type}
|
||||
onClick={handleImageClick}
|
||||
onClick={(e) => {handleImageClick(e); handleThumbnailClick(index, 'mobileReply')}}
|
||||
style={{cursor: "pointer"}}
|
||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||
<div key={`mob-fi-${index}`} className="file-info-mobile">{replyMediaInfo.type}</div>
|
||||
</span>
|
||||
</div>
|
||||
) : replyMediaInfo.type === "video" ? (
|
||||
<span key={`mob-ft${reply.cid}`} className="file-thumb-mobile">
|
||||
<span key={`mob-ft${reply.cid}`} className="file-thumb-mobile" style={isMobileReplyThumbnailClicked[index] ? {} : {width: displayWidthMobile, height: displayHeightMobile}}>
|
||||
<video key={`fti-${index}`}
|
||||
src={replyMediaInfo.url} alt={replyMediaInfo.type}
|
||||
style={{ pointerEvents: "none" }}
|
||||
@@ -1965,7 +2009,7 @@ const Subscriptions = () => {
|
||||
<div key={`mob-fi-${index}`} className="file-info-mobile">{replyMediaInfo.type}</div>
|
||||
</span>
|
||||
) : replyMediaInfo.type === "audio" ? (
|
||||
<span key={`mob-ft${reply.cid}`} className="file-thumb-mobile">
|
||||
<span key={`mob-ft${reply.cid}`} className="file-thumb-mobile" style={isMobileReplyThumbnailClicked[index] ? {} : {width: displayWidthMobile, height: displayHeightMobile}}>
|
||||
<audio key={`mob-img-${index}`}
|
||||
src={replyMediaInfo.url} alt={replyMediaInfo.type}
|
||||
onError={(e) => e.target.src = fallbackImgUrl} />
|
||||
|
||||
Reference in New Issue
Block a user