mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat(post): add "file deleted" img on error
This commit is contained in:
@@ -113,3 +113,7 @@
|
|||||||
.mediaDesktopOp img, .mediaDesktopOp video, .mediaDesktopOp iframe, .mediaDesktopOp audio {
|
.mediaDesktopOp img, .mediaDesktopOp video, .mediaDesktopOp iframe, .mediaDesktopOp audio {
|
||||||
padding: 3px 20px 5px 0;
|
padding: 3px 20px 5px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fileDeleted {
|
||||||
|
image-rendering: pixelated;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import styles from './comment-media.module.css';
|
import styles from './comment-media.module.css';
|
||||||
import { CommentMediaInfo, getDisplayMediaInfoType, getHasThumbnail } from '../../lib/utils/media-utils';
|
import { CommentMediaInfo, getDisplayMediaInfoType, getHasThumbnail } from '../../lib/utils/media-utils';
|
||||||
@@ -18,26 +18,10 @@ interface MediaProps {
|
|||||||
toggleExpanded?: () => void;
|
toggleExpanded?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ThumbnailProps {
|
|
||||||
style: React.CSSProperties;
|
|
||||||
children: React.ReactNode;
|
|
||||||
thumbnailSmallPadding?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ThumbnailBig = ({ style, children }: ThumbnailProps) => (
|
|
||||||
<span className={styles.thumbnailBig} style={style}>
|
|
||||||
{children}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
|
|
||||||
const ThumbnailSmall = ({ style, children, thumbnailSmallPadding }: ThumbnailProps) => (
|
|
||||||
<span className={`${styles.thumbnailSmall} ${thumbnailSmallPadding}`} style={style}>
|
|
||||||
{children}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
|
|
||||||
const Thumbnail = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, linkWidth, setShowThumbnail }: MediaProps) => {
|
const Thumbnail = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, linkWidth, setShowThumbnail }: MediaProps) => {
|
||||||
const { patternThumbnailUrl, thumbnail, type, url } = commentMediaInfo || {};
|
const { patternThumbnailUrl, thumbnail, type, url } = commentMediaInfo || {};
|
||||||
|
const [hasError, setHasError] = useState(false);
|
||||||
|
const handleError = () => setHasError(true);
|
||||||
|
|
||||||
let displayWidth, displayHeight;
|
let displayWidth, displayHeight;
|
||||||
const isMobile = useWindowWidth() < 640;
|
const isMobile = useWindowWidth() < 640;
|
||||||
@@ -63,7 +47,7 @@ const Thumbnail = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, linkWid
|
|||||||
const hasThumbnail = getHasThumbnail(commentMediaInfo, url);
|
const hasThumbnail = getHasThumbnail(commentMediaInfo, url);
|
||||||
|
|
||||||
if (type === 'image') {
|
if (type === 'image') {
|
||||||
thumbnailComponent = <img src={url} alt='' onClick={() => setShowThumbnail(false)} />;
|
thumbnailComponent = <img src={url} alt='' onError={handleError} onClick={() => setShowThumbnail(false)} />;
|
||||||
} else if (type === 'video') {
|
} else if (type === 'video') {
|
||||||
thumbnailComponent = thumbnail ? <img src={thumbnail} alt='' /> : <video src={`${url}#t=0.001`} onClick={() => setShowThumbnail(false)} />;
|
thumbnailComponent = thumbnail ? <img src={thumbnail} alt='' /> : <video src={`${url}#t=0.001`} onClick={() => setShowThumbnail(false)} />;
|
||||||
} else if (type === 'webpage') {
|
} else if (type === 'webpage') {
|
||||||
@@ -76,15 +60,21 @@ const Thumbnail = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, linkWid
|
|||||||
thumbnailComponent = <audio src={url} controls />;
|
thumbnailComponent = <audio src={url} controls />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasError) {
|
||||||
|
thumbnailComponent = <img className={styles.fileDeleted} src='/assets/filedeleted-res.gif' alt='File deleted' />;
|
||||||
|
}
|
||||||
|
|
||||||
const thumbnailSmallPadding = isMobile ? styles.thumbnailMobile : styles.thumbnailReplyDesktop;
|
const thumbnailSmallPadding = isMobile ? styles.thumbnailMobile : styles.thumbnailReplyDesktop;
|
||||||
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);
|
||||||
|
|
||||||
return isOutOfFeed ? (
|
return hasError ? (
|
||||||
|
<img className={styles.fileDeleted} src='/assets/filedeleted-res.gif' alt='File deleted' />
|
||||||
|
) : isOutOfFeed ? (
|
||||||
<span className={styles.subplebbitAvatar}>{thumbnailComponent}</span>
|
<span className={styles.subplebbitAvatar}>{thumbnailComponent}</span>
|
||||||
) : isMobile || isReply ? (
|
) : isMobile || isReply ? (
|
||||||
<ThumbnailSmall style={thumbnailDimensions} thumbnailSmallPadding={thumbnailSmallPadding}>
|
<span className={`${styles.thumbnailSmall} ${thumbnailSmallPadding}`} style={thumbnailDimensions}>
|
||||||
{thumbnailComponent}
|
{thumbnailComponent}
|
||||||
{isMobile &&
|
{isMobile &&
|
||||||
!hasThumbnail &&
|
!hasThumbnail &&
|
||||||
@@ -96,9 +86,11 @@ const Thumbnail = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, linkWid
|
|||||||
{getHostname(url) || (url.length > 30 ? url.slice(0, 30) + '...' : url)}
|
{getHostname(url) || (url.length > 30 ? url.slice(0, 30) + '...' : url)}
|
||||||
</a>
|
</a>
|
||||||
))}
|
))}
|
||||||
</ThumbnailSmall>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<ThumbnailBig style={thumbnailDimensions}>{thumbnailComponent}</ThumbnailBig>
|
<span className={styles.thumbnailBig} style={thumbnailDimensions}>
|
||||||
|
{thumbnailComponent}
|
||||||
|
</span>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user