refactor: split picture item stateless to avoid circular dependency
This commit is contained in:
@@ -1,19 +1,11 @@
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
|
||||
import { ArticleItem, ArticleItemSkeleton, ArticleItemStateLess } from "./article-item"
|
||||
import { AudioItem, AudioItemSkeleton, AudioItemStateLess } from "./audio-item"
|
||||
import {
|
||||
NotificationItem,
|
||||
NotificationItemSkeleton,
|
||||
NotificationItemStateLess,
|
||||
} from "./notification-item"
|
||||
import { PictureItem, PictureItemSkeleton, PictureItemStateLess } from "./picture-item"
|
||||
import {
|
||||
SocialMediaItem,
|
||||
SocialMediaItemSkeleton,
|
||||
SocialMediaItemStateLess,
|
||||
} from "./social-media-item"
|
||||
import { VideoItem, VideoItemSkeleton, VideoItemStateLess } from "./video-item"
|
||||
import { ArticleItem, ArticleItemSkeleton } from "./article-item"
|
||||
import { AudioItem, AudioItemSkeleton } from "./audio-item"
|
||||
import { NotificationItem, NotificationItemSkeleton } from "./notification-item"
|
||||
import { PictureItem, PictureItemSkeleton } from "./picture-item"
|
||||
import { SocialMediaItem, SocialMediaItemSkeleton } from "./social-media-item"
|
||||
import { VideoItem, VideoItemSkeleton } from "./video-item"
|
||||
|
||||
const ItemMap = {
|
||||
[FeedViewType.Articles]: ArticleItem,
|
||||
@@ -27,19 +19,6 @@ export const getItemComponentByView = (view: FeedViewType) => {
|
||||
return ItemMap[view] || ArticleItem
|
||||
}
|
||||
|
||||
const StatelessItemMap = {
|
||||
[FeedViewType.Articles]: ArticleItemStateLess,
|
||||
[FeedViewType.SocialMedia]: SocialMediaItemStateLess,
|
||||
[FeedViewType.Pictures]: PictureItemStateLess,
|
||||
[FeedViewType.Videos]: VideoItemStateLess,
|
||||
[FeedViewType.Audios]: AudioItemStateLess,
|
||||
[FeedViewType.Notifications]: NotificationItemStateLess,
|
||||
}
|
||||
|
||||
export const getStatelessItemComponentByView = (view: FeedViewType) => {
|
||||
return StatelessItemMap[view] || ArticleItemStateLess
|
||||
}
|
||||
|
||||
const SkeletonItemMap = {
|
||||
[FeedViewType.Articles]: ArticleItemSkeleton,
|
||||
[FeedViewType.SocialMedia]: SocialMediaItemSkeleton,
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { Skeleton } from "@follow/components/ui/skeleton/index.jsx"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
|
||||
import { RelativeTime } from "~/components/ui/datetime"
|
||||
import { Media } from "~/components/ui/media"
|
||||
import { FeedIcon } from "~/modules/feed/feed-icon"
|
||||
import { FeedTitle } from "~/modules/feed/feed-title"
|
||||
|
||||
import type { EntryItemStatelessProps } from "../types"
|
||||
|
||||
export function PictureItemStateLess({ entry, feed }: EntryItemStatelessProps) {
|
||||
return (
|
||||
<div className="relative mx-auto max-w-md rounded-md bg-theme-background text-zinc-700 transition-colors dark:text-neutral-400">
|
||||
<div className="relative">
|
||||
<div className="p-1.5">
|
||||
<div className="relative flex gap-2 overflow-x-auto">
|
||||
<div
|
||||
className={cn(
|
||||
"relative flex w-full shrink-0 items-center overflow-hidden rounded-md",
|
||||
!entry.media?.[0].url && "aspect-square",
|
||||
)}
|
||||
>
|
||||
{entry.media?.[0] ? (
|
||||
<Media
|
||||
thumbnail
|
||||
src={entry.media[0].url}
|
||||
type={entry.media[0].type}
|
||||
previewImageUrl={entry.media[0].preview_image_url}
|
||||
className="size-full overflow-hidden"
|
||||
mediaContainerClassName={"w-auto h-auto rounded"}
|
||||
loading="lazy"
|
||||
proxy={{
|
||||
width: 0,
|
||||
height: 0,
|
||||
}}
|
||||
height={entry.media[0].height}
|
||||
width={entry.media[0].width}
|
||||
blurhash={entry.media[0].blurhash}
|
||||
/>
|
||||
) : (
|
||||
<Skeleton className="size-full overflow-hidden" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="relative flex-1 px-2 pb-3 pt-1 text-sm">
|
||||
<div className="relative mb-1 mt-1.5 truncate font-medium leading-none">
|
||||
{entry.title}
|
||||
</div>
|
||||
<div className="mt-1 flex items-center gap-1 truncate text-[13px]">
|
||||
<FeedIcon feed={feed} fallback className="size-4" />
|
||||
<FeedTitle feed={feed} />
|
||||
<span className="text-zinc-500">·</span>
|
||||
{!!entry.publishedAt && <RelativeTime date={entry.publishedAt} />}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -12,22 +12,18 @@ import type { PropsWithChildren } from "react"
|
||||
import { memo, useContext, useEffect, useMemo, useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { RelativeTime } from "~/components/ui/datetime"
|
||||
import { Media } from "~/components/ui/media"
|
||||
import { SwipeMedia } from "~/components/ui/media/SwipeMedia"
|
||||
import { ReactVirtuosoItemPlaceholder } from "~/components/ui/placeholder"
|
||||
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { filterSmallMedia } from "~/lib/utils"
|
||||
import { EntryContent } from "~/modules/entry-content"
|
||||
import { FeedIcon } from "~/modules/feed/feed-icon"
|
||||
import { FeedTitle } from "~/modules/feed/feed-title"
|
||||
import { useEntry } from "~/store/entry/hooks"
|
||||
import { useImageDimensions } from "~/store/image"
|
||||
|
||||
import { usePreviewMedia } from "../../../components/ui/media/hooks"
|
||||
import { EntryItemWrapper } from "../layouts/EntryItemWrapper"
|
||||
import { GridItem, GridItemFooter } from "../templates/grid-item-template"
|
||||
import type { EntryItemStatelessProps, UniversalItemProps } from "../types"
|
||||
import type { UniversalItemProps } from "../types"
|
||||
|
||||
export function PictureItem({ entryId, entryPreview, translation }: UniversalItemProps) {
|
||||
const entry = useEntry(entryId) || entryPreview
|
||||
@@ -205,57 +201,6 @@ const MasonryItemFixedDimensionWrapper = (
|
||||
)
|
||||
}
|
||||
|
||||
export function PictureItemStateLess({ entry, feed }: EntryItemStatelessProps) {
|
||||
return (
|
||||
<div className="relative mx-auto max-w-md rounded-md bg-theme-background text-zinc-700 transition-colors dark:text-neutral-400">
|
||||
<div className="relative">
|
||||
<div className="p-1.5">
|
||||
<div className="relative flex gap-2 overflow-x-auto">
|
||||
<div
|
||||
className={cn(
|
||||
"relative flex w-full shrink-0 items-center overflow-hidden rounded-md",
|
||||
!entry.media?.[0].url && "aspect-square",
|
||||
)}
|
||||
>
|
||||
{entry.media?.[0] ? (
|
||||
<Media
|
||||
thumbnail
|
||||
src={entry.media[0].url}
|
||||
type={entry.media[0].type}
|
||||
previewImageUrl={entry.media[0].preview_image_url}
|
||||
className="size-full overflow-hidden"
|
||||
mediaContainerClassName={"w-auto h-auto rounded"}
|
||||
loading="lazy"
|
||||
proxy={{
|
||||
width: 0,
|
||||
height: 0,
|
||||
}}
|
||||
height={entry.media[0].height}
|
||||
width={entry.media[0].width}
|
||||
blurhash={entry.media[0].blurhash}
|
||||
/>
|
||||
) : (
|
||||
<Skeleton className="size-full overflow-hidden" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="relative flex-1 px-2 pb-3 pt-1 text-sm">
|
||||
<div className="relative mb-1 mt-1.5 truncate font-medium leading-none">
|
||||
{entry.title}
|
||||
</div>
|
||||
<div className="mt-1 flex items-center gap-1 truncate text-[13px]">
|
||||
<FeedIcon feed={feed} fallback className="size-4" />
|
||||
<FeedTitle feed={feed} />
|
||||
<span className="text-zinc-500">·</span>
|
||||
{!!entry.publishedAt && <RelativeTime date={entry.publishedAt} />}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const PictureItemSkeleton = (
|
||||
<div className="relative max-w-md rounded-md bg-theme-background text-zinc-700 transition-colors dark:text-neutral-400">
|
||||
<div className="relative">
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
import type { FC } from "react"
|
||||
import { memo } from "react"
|
||||
|
||||
import { ArticleItemStateLess } from "./Items/article-item"
|
||||
import { AudioItemStateLess } from "./Items/audio-item"
|
||||
import { NotificationItemStateLess } from "./Items/notification-item"
|
||||
import { PictureItemStateLess } from "./Items/picture-item-stateless"
|
||||
import { SocialMediaItemStateLess } from "./Items/social-media-item"
|
||||
import { VideoItemStateLess } from "./Items/video-item"
|
||||
import type { EntryItemStatelessProps } from "./types"
|
||||
|
||||
const StatelessItemMap = {
|
||||
[FeedViewType.Articles]: ArticleItemStateLess,
|
||||
[FeedViewType.SocialMedia]: SocialMediaItemStateLess,
|
||||
[FeedViewType.Pictures]: PictureItemStateLess,
|
||||
[FeedViewType.Videos]: VideoItemStateLess,
|
||||
[FeedViewType.Audios]: AudioItemStateLess,
|
||||
[FeedViewType.Notifications]: NotificationItemStateLess,
|
||||
}
|
||||
|
||||
const getStatelessItemComponentByView = (view: FeedViewType) => {
|
||||
return StatelessItemMap[view] || ArticleItemStateLess
|
||||
}
|
||||
|
||||
export const EntryItemStateless: FC<EntryItemStatelessProps> = memo((props) => {
|
||||
const Item = getStatelessItemComponentByView(props.view as FeedViewType)
|
||||
|
||||
return <Item {...props} />
|
||||
})
|
||||
@@ -11,14 +11,10 @@ import type { FlatEntryModel } from "~/store/entry"
|
||||
import { useEntry } from "~/store/entry/hooks"
|
||||
|
||||
import { ReactVirtuosoItemPlaceholder } from "../../components/ui/placeholder"
|
||||
import {
|
||||
getItemComponentByView,
|
||||
getSkeletonItemComponentByView,
|
||||
getStatelessItemComponentByView,
|
||||
} from "./Items"
|
||||
import { getItemComponentByView, getSkeletonItemComponentByView } from "./Items"
|
||||
import { EntryItemWrapper } from "./layouts/EntryItemWrapper"
|
||||
import { girdClassNames } from "./styles"
|
||||
import type { EntryItemStatelessProps, EntryListItemFC } from "./types"
|
||||
import type { EntryListItemFC } from "./types"
|
||||
|
||||
interface EntryItemProps {
|
||||
entryId: string
|
||||
@@ -57,12 +53,6 @@ export const EntryItem: FC<EntryItemProps> = memo(({ entryId, view }) => {
|
||||
return <EntryItemImpl entry={entry} view={view} />
|
||||
})
|
||||
|
||||
export const EntryItemStateless: FC<EntryItemStatelessProps> = memo((props) => {
|
||||
const Item = getStatelessItemComponentByView(props.view as FeedViewType)
|
||||
|
||||
return <Item {...props} />
|
||||
})
|
||||
|
||||
const LoadingCircleFallback = (
|
||||
<div className="center mt-2">
|
||||
<LoadingCircle size="medium" />
|
||||
|
||||
@@ -6,7 +6,7 @@ import { cloneElement, forwardRef } from "react"
|
||||
|
||||
import { useI18n } from "~/hooks/common"
|
||||
|
||||
import { EntryItemStateless } from "../entry-column/item"
|
||||
import { EntryItemStateless } from "../entry-column/item-stateless"
|
||||
|
||||
export const ViewSelectorRadioGroup = forwardRef<
|
||||
HTMLInputElement,
|
||||
|
||||
Reference in New Issue
Block a user