mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(comment media): only show link if valid, show webpage links on mobile
This commit is contained in:
@@ -89,15 +89,16 @@ const Thumbnail = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, linkWid
|
|||||||
return isMobile || isReply ? (
|
return isMobile || isReply ? (
|
||||||
<ThumbnailSmall style={thumbnailDimensions} thumbnailSmallPadding={thumbnailSmallPadding}>
|
<ThumbnailSmall style={thumbnailDimensions} thumbnailSmallPadding={thumbnailSmallPadding}>
|
||||||
{thumbnailComponent}
|
{thumbnailComponent}
|
||||||
{isMobile && !hasThumbnail && linkWithoutThumbnail ? (
|
{isMobile &&
|
||||||
canEmbed(linkWithoutThumbnail) ? (
|
!hasThumbnail &&
|
||||||
|
linkWithoutThumbnail &&
|
||||||
|
(canEmbed(linkWithoutThumbnail) ? (
|
||||||
<span onClick={() => setShowThumbnail(false)}>{getHostname(url)}</span>
|
<span onClick={() => setShowThumbnail(false)}>{getHostname(url)}</span>
|
||||||
) : (
|
) : (
|
||||||
<a href={url} target='_blank' rel='noreferrer'>
|
<a href={url} target='_blank' rel='noreferrer'>
|
||||||
{getHostname(url)}
|
{getHostname(url) || (url.length > 30 ? url.slice(0, 30) + '...' : url)}
|
||||||
</a>
|
</a>
|
||||||
)
|
))}
|
||||||
) : null}
|
|
||||||
</ThumbnailSmall>
|
</ThumbnailSmall>
|
||||||
) : (
|
) : (
|
||||||
<ThumbnailBig style={thumbnailDimensions}>{thumbnailComponent}</ThumbnailBig>
|
<ThumbnailBig style={thumbnailDimensions}>{thumbnailComponent}</ThumbnailBig>
|
||||||
@@ -144,19 +145,22 @@ const Media = ({ commentMediaInfo, isReply, setShowThumbnail }: MediaProps) => {
|
|||||||
|
|
||||||
const CommentMedia = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, linkWidth, showThumbnail, setShowThumbnail }: MediaProps) => {
|
const CommentMedia = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, linkWidth, showThumbnail, setShowThumbnail }: MediaProps) => {
|
||||||
const isMobile = useWindowWidth() < 640;
|
const isMobile = useWindowWidth() < 640;
|
||||||
|
const { type, url } = commentMediaInfo || {};
|
||||||
return (
|
return (
|
||||||
<span className={styles.content}>
|
<span className={styles.content}>
|
||||||
<span className={`${showThumbnail ? styles.show : styles.hide} ${styles.thumbnail}`}>
|
<span className={`${showThumbnail ? styles.show : styles.hide} ${styles.thumbnail}`}>
|
||||||
<Thumbnail
|
{url && (
|
||||||
commentMediaInfo={commentMediaInfo}
|
<Thumbnail
|
||||||
isOutOfFeed={isOutOfFeed}
|
commentMediaInfo={commentMediaInfo}
|
||||||
isReply={isReply}
|
isOutOfFeed={isOutOfFeed}
|
||||||
linkHeight={linkHeight}
|
isReply={isReply}
|
||||||
linkWidth={linkWidth}
|
linkHeight={linkHeight}
|
||||||
showThumbnail={showThumbnail}
|
linkWidth={linkWidth}
|
||||||
setShowThumbnail={setShowThumbnail}
|
showThumbnail={showThumbnail}
|
||||||
/>
|
setShowThumbnail={setShowThumbnail}
|
||||||
{isMobile && commentMediaInfo?.type && <div className={styles.fileInfo}>{commentMediaInfo.type}</div>}
|
/>
|
||||||
|
)}
|
||||||
|
{isMobile && type && <div className={styles.fileInfo}>{type}</div>}
|
||||||
</span>
|
</span>
|
||||||
{!showThumbnail && <Media commentMediaInfo={commentMediaInfo} isReply={isReply} setShowThumbnail={setShowThumbnail} />}
|
{!showThumbnail && <Media commentMediaInfo={commentMediaInfo} isReply={isReply} setShowThumbnail={setShowThumbnail} />}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import useWindowWidth from '../../hooks/use-window-width';
|
|||||||
import styles from './post.module.css';
|
import styles from './post.module.css';
|
||||||
import Markdown from '../markdown';
|
import Markdown from '../markdown';
|
||||||
import CommentMedia from '../comment-media';
|
import CommentMedia from '../comment-media';
|
||||||
|
import { canEmbed } from '../embed';
|
||||||
|
|
||||||
interface PostProps {
|
interface PostProps {
|
||||||
index?: number;
|
index?: number;
|
||||||
@@ -35,6 +36,7 @@ const PostDesktop = ({ post, roles, showAllReplies }: PostProps) => {
|
|||||||
const displayContent = content && !isInPostPage && content.length > 1000 ? content?.slice(0, 1000) + '(...)' : content;
|
const displayContent = content && !isInPostPage && content.length > 1000 ? content?.slice(0, 1000) + '(...)' : content;
|
||||||
|
|
||||||
const commentMediaInfo = getCommentMediaInfo(post);
|
const commentMediaInfo = getCommentMediaInfo(post);
|
||||||
|
const { type, url } = commentMediaInfo || {};
|
||||||
const hasThumbnail = getHasThumbnail(commentMediaInfo, link);
|
const hasThumbnail = getHasThumbnail(commentMediaInfo, link);
|
||||||
const [showThumbnail, setShowThumbnail] = useState(true);
|
const [showThumbnail, setShowThumbnail] = useState(true);
|
||||||
|
|
||||||
@@ -56,15 +58,15 @@ const PostDesktop = ({ post, roles, showAllReplies }: PostProps) => {
|
|||||||
<span className={`${styles.hideButton} ${styles.hideThread}`} />
|
<span className={`${styles.hideButton} ${styles.hideThread}`} />
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{commentMediaInfo?.url && (
|
{url && (
|
||||||
<div className={styles.file}>
|
<div className={styles.file}>
|
||||||
<div className={styles.fileText}>
|
<div className={styles.fileText}>
|
||||||
{t('link')}:{' '}
|
{t('link')}:{' '}
|
||||||
<a href={commentMediaInfo?.url} target='_blank' rel='noopener noreferrer'>
|
<a href={url} target='_blank' rel='noopener noreferrer'>
|
||||||
{commentMediaInfo.url.length > 30 ? commentMediaInfo?.url?.slice(0, 30) + '...' : commentMediaInfo?.url}
|
{url.length > 30 ? url.slice(0, 30) + '...' : url}
|
||||||
</a>{' '}
|
</a>{' '}
|
||||||
({commentMediaInfo?.type})
|
({type})
|
||||||
{!showThumbnail && (commentMediaInfo?.type === 'iframe' || commentMediaInfo?.type === 'video' || commentMediaInfo?.type === 'audio') && (
|
{!showThumbnail && (type === 'iframe' || type === 'video' || type === 'audio') && (
|
||||||
<span>
|
<span>
|
||||||
{' '}
|
{' '}
|
||||||
[
|
[
|
||||||
@@ -191,6 +193,8 @@ const ReplyDesktop = ({ reply, roles }: PostProps) => {
|
|||||||
const authorRole = roles?.[address]?.role;
|
const authorRole = roles?.[address]?.role;
|
||||||
|
|
||||||
const commentMediaInfo = getCommentMediaInfo(reply);
|
const commentMediaInfo = getCommentMediaInfo(reply);
|
||||||
|
const { type, url } = commentMediaInfo || {};
|
||||||
|
const embedUrl = url && new URL(url);
|
||||||
const hasThumbnail = getHasThumbnail(commentMediaInfo, link);
|
const hasThumbnail = getHasThumbnail(commentMediaInfo, link);
|
||||||
const [showThumbnail, setShowThumbnail] = useState(true);
|
const [showThumbnail, setShowThumbnail] = useState(true);
|
||||||
|
|
||||||
@@ -240,14 +244,14 @@ const ReplyDesktop = ({ reply, roles }: PostProps) => {
|
|||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{link && (
|
{url && (
|
||||||
<div className={styles.file}>
|
<div className={styles.file}>
|
||||||
<div className={styles.fileText}>
|
<div className={styles.fileText}>
|
||||||
{t('link')}:{' '}
|
{t('link')}:{' '}
|
||||||
<a href={link} target='_blank' rel='noopener noreferrer'>
|
<a href={link} target='_blank' rel='noopener noreferrer'>
|
||||||
{link.length > 30 ? link?.slice(0, 30) + '...' : link}
|
{link.length > 30 ? link?.slice(0, 30) + '...' : link}
|
||||||
</a>
|
</a>
|
||||||
{!showThumbnail && (commentMediaInfo?.type === 'iframe' || commentMediaInfo?.type === 'video' || commentMediaInfo?.type === 'audio') && (
|
{!showThumbnail && (type === 'iframe' || type === 'video' || type === 'audio') && (
|
||||||
<span>
|
<span>
|
||||||
{' '}
|
{' '}
|
||||||
[
|
[
|
||||||
@@ -257,7 +261,7 @@ const ReplyDesktop = ({ reply, roles }: PostProps) => {
|
|||||||
]
|
]
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{showThumbnail && !hasThumbnail && (
|
{showThumbnail && !hasThumbnail && embedUrl && canEmbed(embedUrl) && (
|
||||||
<span>
|
<span>
|
||||||
{' '}
|
{' '}
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user