mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(media): reserve stable post media space before thumbnails resolve
This commit is contained in:
@@ -109,6 +109,29 @@ const Thumbnail = ({ commentMediaInfo, deleted, displayHeight, displayWidth, isF
|
|||||||
const thumbnailDimensions = { '--width': displayWidth, '--height': displayHeight } as React.CSSProperties;
|
const thumbnailDimensions = { '--width': displayWidth, '--height': displayHeight } as React.CSSProperties;
|
||||||
|
|
||||||
const linkWithoutThumbnail = url && new URL(url);
|
const linkWithoutThumbnail = url && new URL(url);
|
||||||
|
const fallbackLinkLabel = url ? getHostname(url) || (url.length > 30 ? `${url.slice(0, 30)}...` : url) : '';
|
||||||
|
const noThumbnailLink =
|
||||||
|
!hasThumbnail && linkWithoutThumbnail ? (
|
||||||
|
canEmbed(linkWithoutThumbnail) ? (
|
||||||
|
<span
|
||||||
|
role='button'
|
||||||
|
tabIndex={0}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === 'Enter' || e.key === ' ') {
|
||||||
|
e.preventDefault();
|
||||||
|
setShowThumbnail(false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onClick={() => setShowThumbnail(false)}
|
||||||
|
>
|
||||||
|
{fallbackLinkLabel}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<a href={url} target='_blank' rel='noreferrer'>
|
||||||
|
{fallbackLinkLabel}
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
) : null;
|
||||||
|
|
||||||
return deleted || removed ? (
|
return deleted || removed ? (
|
||||||
<img className={styles.fileDeleted} src='assets/filedeleted-res.gif' alt='File deleted' />
|
<img className={styles.fileDeleted} src='assets/filedeleted-res.gif' alt='File deleted' />
|
||||||
@@ -132,32 +155,12 @@ const Thumbnail = ({ commentMediaInfo, deleted, displayHeight, displayWidth, isF
|
|||||||
) : isMobile || isReply ? (
|
) : isMobile || isReply ? (
|
||||||
<span className={`${styles.thumbnailSmall} ${thumbnailSmallPadding}`} style={thumbnailDimensions}>
|
<span className={`${styles.thumbnailSmall} ${thumbnailSmallPadding}`} style={thumbnailDimensions}>
|
||||||
{thumbnailComponent}
|
{thumbnailComponent}
|
||||||
{isMobile &&
|
{noThumbnailLink}
|
||||||
!hasThumbnail &&
|
|
||||||
linkWithoutThumbnail &&
|
|
||||||
(canEmbed(linkWithoutThumbnail) ? (
|
|
||||||
<span
|
|
||||||
role='button'
|
|
||||||
tabIndex={0}
|
|
||||||
onKeyDown={(e) => {
|
|
||||||
if (e.key === 'Enter' || e.key === ' ') {
|
|
||||||
e.preventDefault();
|
|
||||||
setShowThumbnail(false);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onClick={() => setShowThumbnail(false)}
|
|
||||||
>
|
|
||||||
{getHostname(url)}
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
<a href={url} target='_blank' rel='noreferrer'>
|
|
||||||
{getHostname(url) || (url.length > 30 ? url.slice(0, 30) + '...' : url)}
|
|
||||||
</a>
|
|
||||||
))}
|
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span className={styles.thumbnailBig} style={thumbnailDimensions}>
|
<span className={styles.thumbnailBig} style={thumbnailDimensions}>
|
||||||
{thumbnailComponent}
|
{thumbnailComponent}
|
||||||
|
{noThumbnailLink}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -619,7 +619,7 @@ const PostMedia = ({
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{(hasThumbnail || (!hasThumbnail && !showThumbnail) || spoiler) && (
|
{(hasThumbnail || (!hasThumbnail && !showThumbnail) || spoiler || Boolean(commentMediaInfo?.url)) && (
|
||||||
<div className={styles.fileThumbnail}>
|
<div className={styles.fileThumbnail}>
|
||||||
<CommentMedia
|
<CommentMedia
|
||||||
commentMediaInfo={commentMediaInfo}
|
commentMediaInfo={commentMediaInfo}
|
||||||
|
|||||||
@@ -404,10 +404,9 @@ const PostMediaContent = ({ post, link }: { post: any; link: string }) => {
|
|||||||
const [showThumbnail, setShowThumbnail] = useState(true);
|
const [showThumbnail, setShowThumbnail] = useState(true);
|
||||||
const { thumbnailUrl, linkWidth, linkHeight, spoiler, deleted, removed, parentCid } = post || {};
|
const { thumbnailUrl, linkWidth, linkHeight, spoiler, deleted, removed, parentCid } = post || {};
|
||||||
const commentMediaInfo = useCommentMediaInfo(link, thumbnailUrl, linkWidth, linkHeight);
|
const commentMediaInfo = useCommentMediaInfo(link, thumbnailUrl, linkWidth, linkHeight);
|
||||||
const hasThumbnail = getHasThumbnail(commentMediaInfo, link);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
hasThumbnail && (
|
commentMediaInfo && (
|
||||||
<CommentMedia
|
<CommentMedia
|
||||||
commentMediaInfo={commentMediaInfo}
|
commentMediaInfo={commentMediaInfo}
|
||||||
deleted={deleted}
|
deleted={deleted}
|
||||||
|
|||||||
Reference in New Issue
Block a user