From 6d76dbb4dc96266c20f92775be4c6d4798a2fa3d Mon Sep 17 00:00:00 2001 From: Salief Date: Sun, 2 Jun 2024 17:08:04 -0400 Subject: [PATCH 1/8] drop generic thumbnails, add item fallback comp --- apps/site/components/client/ChannelCard2.tsx | 8 +- apps/site/components/server/ChannelCard.tsx | 17 ++- apps/site/components/server/ItemCard.tsx | 6 +- apps/site/components/server/ItemFallback.tsx | 141 ++++++++++++++++++ apps/site/components/server/Thumbnails.tsx | 49 ------ .../server/channel/ThumbnailNameCreator.tsx | 7 +- apps/site/components/server/index.ts | 2 +- 7 files changed, 165 insertions(+), 65 deletions(-) create mode 100644 apps/site/components/server/ItemFallback.tsx delete mode 100644 apps/site/components/server/Thumbnails.tsx diff --git a/apps/site/components/client/ChannelCard2.tsx b/apps/site/components/client/ChannelCard2.tsx index a25bbec3..2a7d1900 100644 --- a/apps/site/components/client/ChannelCard2.tsx +++ b/apps/site/components/client/ChannelCard2.tsx @@ -5,7 +5,7 @@ import { import { Flex, Stack, Typography, Public } from '@/design-system' import type { Channel, ChannelRoles } from '@/gql' import Image from 'next/image' -import { GenericThumbnailSmall } from '@/server' +import { ItemFallback } from '@/server' import { w3sUrlFromCid } from '@/lib' import { UsernameNoFetch } from '@/client' import { truncateText } from '@/utils' @@ -57,9 +57,9 @@ export function ChannelCard2({ ) : (
{metadata?.length ? ( - ) : ( diff --git a/apps/site/components/server/ChannelCard.tsx b/apps/site/components/server/ChannelCard.tsx index 1ebb6736..29684f66 100644 --- a/apps/site/components/server/ChannelCard.tsx +++ b/apps/site/components/server/ChannelCard.tsx @@ -9,7 +9,7 @@ import { truncateText } from '@/utils' import { Flex, Stack, Typography, Public } from '@/design-system' import type { Adds, Channel, ChannelRoles } from '@/gql' import { type MediaAssetObject, w3sUrlFromCid } from '@/lib' -import { GenericThumbnailLarge, Username } from '@/server' +import { ItemFallback, Username } from '@/server' import { kv } from '@vercel/kv' import { muxClient } from '@/config/mux' import { isVideo } from '@/lib' @@ -113,11 +113,16 @@ export async function ChannelCard({ ) : ( - + )} {/* Channel name & creator */} diff --git a/apps/site/components/server/ItemCard.tsx b/apps/site/components/server/ItemCard.tsx index b4ecbc19..5accea60 100644 --- a/apps/site/components/server/ItemCard.tsx +++ b/apps/site/components/server/ItemCard.tsx @@ -5,7 +5,7 @@ import { import { Flex, Stack, Typography, Public } from '@/design-system' import type { Adds, ChannelRoles } from '@/gql' import { type MediaAssetObject, w3sUrlFromCid, isVideo } from '@/lib' -import { GenericThumbnailLarge, Username } from '@/server' +import { Username, ItemFallback } from '@/server' import { kv } from '@vercel/kv' import Image from 'next/image' import Link from 'next/link' @@ -23,6 +23,8 @@ export async function ItemCard({ add?.item?.uri as string, ) + console.log('Item metadata', itemMetadata?.contentType) + const videoThumbnail = { isVideo: isVideo({ mimeType: itemMetadata?.contentType as string }), thumbnailReady: false, @@ -79,7 +81,7 @@ export async function ItemCard({ priority={true} /> ) : ( - + )} diff --git a/apps/site/components/server/ItemFallback.tsx b/apps/site/components/server/ItemFallback.tsx new file mode 100644 index 00000000..ee6a6efc --- /dev/null +++ b/apps/site/components/server/ItemFallback.tsx @@ -0,0 +1,141 @@ +import { cn, Flex } from '@/design-system' +import { P, match } from 'ts-pattern' +import { isVideo, isAudio, isGlb, isPdf, isMarkdown } from '@/lib' + +export function ItemFallback({ + contentType, + className, + size, +}: { + contentType: string + className?: string + size?: 'xs' | 'sm' | 'md' | 'lg' +}) { + return ( + + {match(contentType) + .with( + P.when((type: string) => isAudio({ mimeType: type })), + () => , + ) + .with( + P.when((type: string) => isVideo({ mimeType: type })), + () => , + ) + .with( + P.when((type: string) => isMarkdown({ mimeType: type })), + () => , + ) + .with( + P.when((type: string) => isGlb({ mimeType: type })), + () => , + ) + .with( + P.when((type: string) => isPdf({ mimeType: type })), + () => , + ) + .otherwise(() => ( + + ))} + + ) +} + +export function AudioFallback() { + return ( +
+ + + +
+ ) +} + +export function VideoFallback() { + return ( +
+ + + + +
+ ) +} + +export function TextFallback() { + return ( +
+ + + + +
+ ) +} + +export function ThreeDFallback() { + return ( +
+ + + + +
+ ) +} + +export function FileFallback() { + return ( +
+ + + + +
+ ) +} + +export function Unsupported() { + return ( +
+ + + +
+ ) +} diff --git a/apps/site/components/server/Thumbnails.tsx b/apps/site/components/server/Thumbnails.tsx deleted file mode 100644 index 4e5567cc..00000000 --- a/apps/site/components/server/Thumbnails.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import { Stack, Typography, cn } from '@/design-system' -import { truncateText } from '@/utils' - -function extractFileExtension(mimeType: string): string { - if (!mimeType) { - return '' - } - const lastSlashIndex = mimeType.lastIndexOf('/') - if (lastSlashIndex !== -1) { - return `.${mimeType.substring(lastSlashIndex + 1)}` - } - return '' -} - -export function GenericThumbnailLarge({ - text, - className, -}: { text: string; className?: string }) { - return ( - - - {extractFileExtension(text)} - - - ) -} - -export function GenericThumbnailSmall({ - text, - className, -}: { text: string; className?: string }) { - return ( - - - {truncateText(extractFileExtension(text), 5, false)} - - - ) -} diff --git a/apps/site/components/server/channel/ThumbnailNameCreator.tsx b/apps/site/components/server/channel/ThumbnailNameCreator.tsx index 5559bc7e..82a296bf 100644 --- a/apps/site/components/server/channel/ThumbnailNameCreator.tsx +++ b/apps/site/components/server/channel/ThumbnailNameCreator.tsx @@ -2,7 +2,7 @@ import { Stack, Typography } from '@/design-system' import type { Item } from '@/gql' import { ipfsUrlToCid, w3sUrlFromCid } from '@/lib' import { VIDEO_THUMBNAIL_TYPES_TO_RENDER } from 'constants/thumbnails' -import { GenericThumbnailSmall, Username } from '@/server' +import { ItemFallback, Username } from '@/server' import { truncateText } from '@/utils' import Image from 'next/image' import { muxClient } from '@/config/mux' @@ -89,9 +89,10 @@ export async function ThumbnailNameCreator({ />
) : ( - )} diff --git a/apps/site/components/server/index.ts b/apps/site/components/server/index.ts index d894d12f..9ce205bf 100644 --- a/apps/site/components/server/index.ts +++ b/apps/site/components/server/index.ts @@ -4,8 +4,8 @@ export * from './channel' // Individual components export * from './ChannelCard' export * from './ItemCard' +export * from './ItemFallback' export * from './ItemSidebar' export * from './MarqueeWrapper' export * from './RiverLogo' -export * from './Thumbnails' export * from './Username' From 765c8e6bc7390206ebb8dcdc681eae860646eb84 Mon Sep 17 00:00:00 2001 From: Salief Date: Sun, 2 Jun 2024 18:11:27 -0400 Subject: [PATCH 2/8] adjust for sizing edge cases --- apps/site/components/server/ChannelCard.tsx | 9 +-------- apps/site/components/server/ItemCard.tsx | 2 -- apps/site/components/server/ItemFallback.tsx | 8 ++++---- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/apps/site/components/server/ChannelCard.tsx b/apps/site/components/server/ChannelCard.tsx index 29684f66..08db1570 100644 --- a/apps/site/components/server/ChannelCard.tsx +++ b/apps/site/components/server/ChannelCard.tsx @@ -113,16 +113,9 @@ export async function ChannelCard({ ) : ( - // )} {/* Channel name & creator */} diff --git a/apps/site/components/server/ItemCard.tsx b/apps/site/components/server/ItemCard.tsx index 5accea60..d1d915e0 100644 --- a/apps/site/components/server/ItemCard.tsx +++ b/apps/site/components/server/ItemCard.tsx @@ -23,8 +23,6 @@ export async function ItemCard({ add?.item?.uri as string, ) - console.log('Item metadata', itemMetadata?.contentType) - const videoThumbnail = { isVideo: isVideo({ mimeType: itemMetadata?.contentType as string }), thumbnailReady: false, diff --git a/apps/site/components/server/ItemFallback.tsx b/apps/site/components/server/ItemFallback.tsx index ee6a6efc..52bc0b04 100644 --- a/apps/site/components/server/ItemFallback.tsx +++ b/apps/site/components/server/ItemFallback.tsx @@ -52,7 +52,7 @@ export function ItemFallback({ export function AudioFallback() { return ( -
+
+
+
+
Date: Sun, 2 Jun 2024 18:26:03 -0400 Subject: [PATCH 3/8] further adjustments to audio fallback comp and text based fallback comps --- apps/site/components/server/ItemFallback.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/site/components/server/ItemFallback.tsx b/apps/site/components/server/ItemFallback.tsx index 52bc0b04..5c5a227a 100644 --- a/apps/site/components/server/ItemFallback.tsx +++ b/apps/site/components/server/ItemFallback.tsx @@ -25,7 +25,7 @@ export function ItemFallback({ {match(contentType) .with( P.when((type: string) => isAudio({ mimeType: type })), - () => , + () => , ) .with( P.when((type: string) => isVideo({ mimeType: type })), @@ -50,9 +50,9 @@ export function ItemFallback({ ) } -export function AudioFallback() { +export function AudioFallback({ size }: { size?: 'xs' | 'sm' | 'md' | 'lg' }) { return ( -
+
+
+
+
Date: Sun, 2 Jun 2024 18:34:41 -0400 Subject: [PATCH 4/8] adjust margin for text based fallback comps --- apps/site/components/server/ItemFallback.tsx | 38 ++++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/apps/site/components/server/ItemFallback.tsx b/apps/site/components/server/ItemFallback.tsx index 5c5a227a..9307bec6 100644 --- a/apps/site/components/server/ItemFallback.tsx +++ b/apps/site/components/server/ItemFallback.tsx @@ -77,9 +77,25 @@ export function VideoFallback() { ) } +export function FileFallback() { + return ( +
+ + + + +
+ ) + } + export function TextFallback() { return ( -
+
+
- - - - -
- ) -} - export function Unsupported() { return ( -
+
Date: Sun, 2 Jun 2024 18:40:24 -0400 Subject: [PATCH 5/8] add size prop to text based fallback comps for additional styling --- apps/site/components/server/ItemFallback.tsx | 61 ++++++++++++-------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/apps/site/components/server/ItemFallback.tsx b/apps/site/components/server/ItemFallback.tsx index 9307bec6..248a1a79 100644 --- a/apps/site/components/server/ItemFallback.tsx +++ b/apps/site/components/server/ItemFallback.tsx @@ -33,18 +33,18 @@ export function ItemFallback({ ) .with( P.when((type: string) => isMarkdown({ mimeType: type })), - () => , + () => , ) .with( P.when((type: string) => isGlb({ mimeType: type })), - () => , + () => , ) .with( P.when((type: string) => isPdf({ mimeType: type })), () => , ) .otherwise(() => ( - + ))} ) @@ -78,24 +78,29 @@ export function VideoFallback() { } export function FileFallback() { - return ( -
- - - - -
- ) - } + return ( +
+ + + + +
+ ) +} -export function TextFallback() { +export function TextFallback({ size }: { size?: 'xs' | 'sm' | 'md' | 'lg' }) { return ( -
+
+
+
Date: Sun, 2 Jun 2024 18:44:52 -0400 Subject: [PATCH 6/8] make margin conditional to size as well --- apps/site/components/server/ItemFallback.tsx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/apps/site/components/server/ItemFallback.tsx b/apps/site/components/server/ItemFallback.tsx index 248a1a79..a4f94c71 100644 --- a/apps/site/components/server/ItemFallback.tsx +++ b/apps/site/components/server/ItemFallback.tsx @@ -97,8 +97,8 @@ export function TextFallback({ size }: { size?: 'xs' | 'sm' | 'md' | 'lg' }) { return (
@@ -119,8 +119,8 @@ export function ThreeDFallback({ size }: { size?: 'xs' | 'sm' | 'md' | 'lg' }) { return (
@@ -140,10 +140,7 @@ export function ThreeDFallback({ size }: { size?: 'xs' | 'sm' | 'md' | 'lg' }) { export function Unsupported({ size }: { size?: 'xs' | 'sm' | 'md' | 'lg' }) { return (
Date: Sun, 2 Jun 2024 19:03:06 -0400 Subject: [PATCH 7/8] adjust margins on text based fallback comps --- apps/site/components/server/ItemFallback.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/site/components/server/ItemFallback.tsx b/apps/site/components/server/ItemFallback.tsx index a4f94c71..092574aa 100644 --- a/apps/site/components/server/ItemFallback.tsx +++ b/apps/site/components/server/ItemFallback.tsx @@ -97,7 +97,10 @@ export function TextFallback({ size }: { size?: 'xs' | 'sm' | 'md' | 'lg' }) { return (
@@ -119,7 +122,10 @@ export function ThreeDFallback({ size }: { size?: 'xs' | 'sm' | 'md' | 'lg' }) { return (
From 79217aee04d8fc117a40d385eae56161a05b7c1e Mon Sep 17 00:00:00 2001 From: Salief Date: Sun, 2 Jun 2024 19:11:43 -0400 Subject: [PATCH 8/8] fix letter cutoff on 3d fallback --- apps/site/components/server/ItemFallback.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/site/components/server/ItemFallback.tsx b/apps/site/components/server/ItemFallback.tsx index 092574aa..4a2028c0 100644 --- a/apps/site/components/server/ItemFallback.tsx +++ b/apps/site/components/server/ItemFallback.tsx @@ -122,7 +122,7 @@ export function ThreeDFallback({ size }: { size?: 'xs' | 'sm' | 'md' | 'lg' }) { return (