diff --git a/src/components/catalog-row/catalog-row.module.css b/src/components/catalog-row/catalog-row.module.css
index f09270bb..e97bb7c5 100644
--- a/src/components/catalog-row/catalog-row.module.css
+++ b/src/components/catalog-row/catalog-row.module.css
@@ -85,4 +85,14 @@
.post:hover .postMenu {
visibility: visible;
+}
+
+.loadingSkeleton {
+ width: 150px;
+ height: 150px;
+ display: inline-block;
+}
+
+.fileDeleted {
+ image-rendering: pixelated;
}
\ No newline at end of file
diff --git a/src/components/catalog-row/catalog-row.tsx b/src/components/catalog-row/catalog-row.tsx
index 30a19bde..766cd4ff 100644
--- a/src/components/catalog-row/catalog-row.tsx
+++ b/src/components/catalog-row/catalog-row.tsx
@@ -8,34 +8,24 @@ import useFetchGifFirstFrame from '../../hooks/use-fetch-gif-first-frame';
import useCountLinksInReplies from '../../hooks/use-count-links-in-replies';
import PostMenuDesktop from '../post/post-desktop/post-menu-desktop/';
-export const CatalogPostMedia = ({ commentMediaInfo }: { commentMediaInfo: any }) => {
+import React, { useState } from 'react';
+
+interface CatalogPostMediaProps {
+ commentMediaInfo: any;
+ isOutOfFeed?: boolean;
+ linkWidth?: number;
+ linkHeight?: number;
+}
+
+export const CatalogPostMedia = ({ commentMediaInfo, isOutOfFeed, linkWidth, linkHeight }: CatalogPostMediaProps) => {
const { patternThumbnailUrl, thumbnail, type, url } = commentMediaInfo || {};
const iframeThumbnail = patternThumbnailUrl || thumbnail;
const gifFrameUrl = useFetchGifFirstFrame(type === 'gif' ? url : undefined);
- let thumbnailComponent: React.ReactNode = null;
-
- if (type === 'image') {
- thumbnailComponent = ;
- } else if (type === 'video') {
- thumbnailComponent = thumbnail ?
: ;
- } else if (type === 'webpage') {
- thumbnailComponent =
;
- } else if (type === 'iframe') {
- thumbnailComponent = iframeThumbnail ?
: null;
- } else if (type === 'gif' && gifFrameUrl) {
- thumbnailComponent =
;
- } else if (type === 'audio') {
- thumbnailComponent = ;
- }
- return thumbnailComponent;
-};
-
-const CatalogPost = ({ post }: { post: Comment }) => {
- const { t } = useTranslation();
- const { cid, content, isDescription, isRules, link, linkHeight, linkWidth, locked, pinned, replyCount, subplebbitAddress, title } = post || {};
- const commentMediaInfo = getCommentMediaInfo(post);
- const { type } = commentMediaInfo || {};
- const hasThumbnail = getHasThumbnail(commentMediaInfo, link);
+ const [isLoaded, setIsLoaded] = useState(false);
+ const [hasError, setHasError] = useState(false);
+ const handleLoad = () => setIsLoaded(true);
+ const handleError = () => setHasError(true);
+ const loadingStyle = { display: isLoaded ? 'block' : 'none' };
let displayWidth, displayHeight;
const maxThumbnailSize = 150;
@@ -49,13 +39,47 @@ const CatalogPost = ({ post }: { post: Comment }) => {
displayHeight = `${maxThumbnailSize}px`;
}
- if (type === 'audio' || isDescription || isRules) {
+ if (type === 'audio' || isOutOfFeed) {
displayWidth = 'unset';
displayHeight = 'unset';
}
const thumbnailDimensions = { '--width': displayWidth, '--height': displayHeight } as React.CSSProperties;
+ let thumbnailComponent: React.ReactNode = null;
+
+ if (type === 'image' && !hasError) {
+ thumbnailComponent =
;
+ } else if (type === 'video' && !hasError) {
+ thumbnailComponent = thumbnail ? (
+
+ ) : (
+
+ );
+ } else if (type === 'webpage' && !hasError) {
+ thumbnailComponent =
;
+ } else if (type === 'iframe' && iframeThumbnail && !hasError) {
+ thumbnailComponent =
;
+ } else if (type === 'gif' && gifFrameUrl && !hasError) {
+ thumbnailComponent =
;
+ } else if (type === 'audio') {
+ thumbnailComponent = ;
+ }
+
+ return (
+
: thumbnailComponent}
+