fix(modal): feed modal preview view cls
- Added `modalContentClassName` prop to various modal presentations to allow for better content overflow handling. - Updated modal components to utilize the new class for improved layout in specific contexts. - Introduced new `EntryItemSkeleton` component for loading states in entry columns, enhancing user experience during data fetching. Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -47,6 +47,7 @@ const FeedFoundCanBeFollowErrorFallback: FC<AppErrorFallbackProps> = ({ resetErr
|
||||
onClick={() => {
|
||||
present({
|
||||
title: t("feed_form.add_feed"),
|
||||
modalContentClassName: "overflow-visible",
|
||||
content: ({ dismiss }) => (
|
||||
<FeedForm
|
||||
url={feed.url}
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { FC } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useSearchParams } from "react-router"
|
||||
|
||||
import { getItemComponentByView } from "~/modules/entry-column/Items"
|
||||
import { getItemComponentByView } from "~/modules/entry-column/Items/getItemComponentByView"
|
||||
import type { UniversalItemProps } from "~/modules/entry-column/types"
|
||||
import { FeedIcon } from "~/modules/feed/feed-icon"
|
||||
import { FeedTitle } from "~/modules/feed/feed-title"
|
||||
|
||||
@@ -23,8 +23,10 @@ const defaultCtxValue: CurrentModalContentProps = {
|
||||
export const CurrentModalContext = reactCreateContext<CurrentModalContentProps>(defaultCtxValue)
|
||||
export const CurrentModalStateContext = createContextSelector<{
|
||||
isTop: boolean
|
||||
isInModal: boolean
|
||||
}>({
|
||||
isTop: true,
|
||||
isInModal: false,
|
||||
})
|
||||
|
||||
export type ModalContentComponent<T = object> = FC<ModalActionsInternal & T>
|
||||
|
||||
@@ -100,6 +100,8 @@ const actions = {
|
||||
|
||||
export const useCurrentModal = () => useContext(CurrentModalContext)
|
||||
|
||||
export const useIsInModal = () => useContextSelector(CurrentModalStateContext, (v) => v.isInModal)
|
||||
|
||||
export const useResizeableModal = (
|
||||
modalElementRef: React.RefObject<HTMLDivElement>,
|
||||
{
|
||||
|
||||
@@ -66,11 +66,14 @@ export const ModalInternal = memo(
|
||||
) {
|
||||
const {
|
||||
CustomModalComponent,
|
||||
modalClassName,
|
||||
content,
|
||||
title,
|
||||
clickOutsideToDismiss,
|
||||
|
||||
modalClassName,
|
||||
modalContainerClassName,
|
||||
modalContentClassName,
|
||||
|
||||
wrapper: Wrapper = Fragment,
|
||||
max,
|
||||
icon,
|
||||
@@ -268,7 +271,7 @@ export const ModalInternal = memo(
|
||||
>
|
||||
{DragBar}
|
||||
<div
|
||||
className={cn("contents", modalClassName)}
|
||||
className={cn("contents", modalClassName, modalContentClassName)}
|
||||
onClick={stopPropagation}
|
||||
tabIndex={-1}
|
||||
ref={modalElementRef}
|
||||
@@ -380,7 +383,12 @@ export const ModalInternal = memo(
|
||||
</div>
|
||||
<div className="bg-border mx-1 mt-2 h-px shrink-0" />
|
||||
|
||||
<div className="-mx-2 min-h-0 shrink grow overflow-auto p-4">
|
||||
<div
|
||||
className={cn(
|
||||
"-mx-2 min-h-0 shrink grow overflow-auto p-4",
|
||||
modalContentClassName,
|
||||
)}
|
||||
>
|
||||
<ModalContext modalContextProps={ModalContextProps} isTop={!!isTop}>
|
||||
{finalChildren}
|
||||
</ModalContext>
|
||||
@@ -426,6 +434,7 @@ const ModalContext: FC<
|
||||
value={useMemo(
|
||||
() => ({
|
||||
isTop: !!isTop,
|
||||
isInModal: true,
|
||||
}),
|
||||
[isTop],
|
||||
)}
|
||||
|
||||
@@ -16,7 +16,7 @@ export interface ModalProps {
|
||||
clickOutsideToDismiss?: boolean
|
||||
modalClassName?: string
|
||||
modalContainerClassName?: string
|
||||
|
||||
modalContentClassName?: string
|
||||
max?: boolean
|
||||
|
||||
wrapper?: FC
|
||||
|
||||
@@ -257,6 +257,7 @@ export const useFeedActions = ({
|
||||
disabled: isInbox,
|
||||
click: () => {
|
||||
present({
|
||||
modalContentClassName: "overflow-visible",
|
||||
title: t("sidebar.feed_actions.edit_feed"),
|
||||
content: ({ dismiss }) => <FeedForm id={feedId} onSuccess={dismiss} />,
|
||||
})
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import { DEEPLINK_SCHEME } from "@follow/shared/constants"
|
||||
import { useCallback } from "react"
|
||||
|
||||
import { useWhoami } from "~/atoms/user"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { FeedForm } from "~/modules/discover/feed-form"
|
||||
import { ListForm } from "~/modules/discover/list-form"
|
||||
|
||||
import { useI18n } from "../common"
|
||||
|
||||
export const usePresentFeedFormModal = () => {
|
||||
const { present } = useModalStack()
|
||||
const me = useWhoami()
|
||||
const t = useI18n()
|
||||
return useCallback(
|
||||
(
|
||||
params:
|
||||
| {
|
||||
feedId: string
|
||||
}
|
||||
| {
|
||||
listId: string
|
||||
},
|
||||
) => {
|
||||
if (me) {
|
||||
const isList = !!("listId" in params)
|
||||
present({
|
||||
title: isList ? t("sidebar.feed_actions.edit_list") : t("sidebar.feed_actions.edit_feed"),
|
||||
content: ({ dismiss }) =>
|
||||
isList ? (
|
||||
<ListForm id={params.listId} onSuccess={dismiss} />
|
||||
) : (
|
||||
<FeedForm id={params.feedId} onSuccess={dismiss} />
|
||||
),
|
||||
})
|
||||
} else {
|
||||
window.location.href = `${DEEPLINK_SCHEME}add?id=${"feedId" in params ? params.feedId : params.listId}`
|
||||
}
|
||||
},
|
||||
[me, present, t],
|
||||
)
|
||||
}
|
||||
@@ -80,6 +80,7 @@ export const useFollow = () => {
|
||||
|
||||
present({
|
||||
title: `${isFollowed ? `${t("common:words.edit")} ` : ""}${options?.isList ? t("words.lists") : t("words.feeds")}`,
|
||||
modalContentClassName: "overflow-visible",
|
||||
content: ({ dismiss }) => {
|
||||
const onSuccess = () => {
|
||||
options?.onSuccess?.()
|
||||
|
||||
@@ -200,6 +200,7 @@ export const DiscoverFeedForm = ({
|
||||
|
||||
present({
|
||||
title: t("feed_form.add_feed"),
|
||||
modalContentClassName: "overflow-visible",
|
||||
content: () => (
|
||||
<FeedForm
|
||||
url={finalUrl}
|
||||
|
||||
@@ -11,6 +11,8 @@ import {
|
||||
} from "@follow/components/ui/form/index.jsx"
|
||||
import { Input } from "@follow/components/ui/input/index.js"
|
||||
import { LoadingCircle } from "@follow/components/ui/loading/index.jsx"
|
||||
import { RootPortal } from "@follow/components/ui/portal/index.js"
|
||||
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
|
||||
import { Switch } from "@follow/components/ui/switch/index.jsx"
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
import type { EntryModelSimple, FeedModel } from "@follow/models/types"
|
||||
@@ -25,7 +27,7 @@ import { toast } from "sonner"
|
||||
import { z } from "zod"
|
||||
|
||||
import { Autocomplete } from "~/components/ui/auto-completion"
|
||||
import { useCurrentModal } from "~/components/ui/modal/stacked/hooks"
|
||||
import { useCurrentModal, useIsInModal } from "~/components/ui/modal/stacked/hooks"
|
||||
import { useAuthQuery, useI18n } from "~/hooks/common"
|
||||
import { apiClient } from "~/lib/api-fetch"
|
||||
import { tipcClient } from "~/lib/client"
|
||||
@@ -69,85 +71,92 @@ export const FeedForm: Component<{
|
||||
|
||||
const { t } = useTranslation()
|
||||
|
||||
const isInModal = useIsInModal()
|
||||
const rootContainerRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex h-full flex-col",
|
||||
"mx-auto min-h-[420px] w-full max-w-[550px] lg:min-w-[550px]",
|
||||
)}
|
||||
>
|
||||
{feed ? (
|
||||
<FeedInnerForm
|
||||
{...{
|
||||
defaultValues,
|
||||
id,
|
||||
url,
|
||||
<div className="flex flex-col" ref={rootContainerRef}>
|
||||
<ScrollArea.ScrollArea
|
||||
rootClassName={cn(
|
||||
"flex h-full max-h-[calc(100vh-300px)] flex-col",
|
||||
"mx-auto min-h-[420px] w-full max-w-[550px] lg:min-w-[550px]",
|
||||
isInModal && "-mx-4 px-4",
|
||||
)}
|
||||
>
|
||||
{feed ? (
|
||||
<FeedInnerForm
|
||||
{...{
|
||||
defaultValues,
|
||||
id,
|
||||
url,
|
||||
|
||||
onSuccess,
|
||||
subscriptionData: feedQuery.data?.subscription,
|
||||
entries: feedQuery.data?.entries,
|
||||
feed,
|
||||
}}
|
||||
/>
|
||||
) : feedQuery.isLoading ? (
|
||||
<div className="flex flex-1 items-center justify-center">
|
||||
<LoadingCircle size="large" />
|
||||
</div>
|
||||
) : feedQuery.error ? (
|
||||
<div className="center grow flex-col gap-3">
|
||||
<i className="i-mgc-close-cute-re size-7 text-red-500" />
|
||||
<p>{t("feed_form.error_fetching_feed")}</p>
|
||||
<p className="cursor-text select-text break-all px-8 text-center">
|
||||
{getFetchErrorMessage(feedQuery.error)}
|
||||
</p>
|
||||
|
||||
<div className="flex items-center gap-4">
|
||||
<Button
|
||||
variant="text"
|
||||
onClick={() => {
|
||||
feedQuery.refetch()
|
||||
}}
|
||||
>
|
||||
{t("feed_form.retry")}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="primary"
|
||||
onClick={() => {
|
||||
window.open(
|
||||
getNewIssueUrl({
|
||||
body: [
|
||||
"### Info:",
|
||||
"",
|
||||
"Feed URL:",
|
||||
"```",
|
||||
url,
|
||||
"```",
|
||||
"",
|
||||
"Error:",
|
||||
"```",
|
||||
getFetchErrorMessage(feedQuery.error),
|
||||
"```",
|
||||
].join("\n"),
|
||||
title: `Error in fetching feed: ${id ?? url}`,
|
||||
target: "discussion",
|
||||
category: "feed-expired",
|
||||
}),
|
||||
"_blank",
|
||||
)
|
||||
}}
|
||||
>
|
||||
{t("feed_form.feedback")}
|
||||
</Button>
|
||||
onSuccess,
|
||||
subscriptionData: feedQuery.data?.subscription,
|
||||
entries: feedQuery.data?.entries,
|
||||
feed,
|
||||
rootContainerRef,
|
||||
}}
|
||||
/>
|
||||
) : feedQuery.isLoading ? (
|
||||
<div className="flex flex-1 items-center justify-center">
|
||||
<LoadingCircle size="large" />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="center h-full grow flex-col">
|
||||
<i className="i-mgc-question-cute-re mb-6 size-12 text-zinc-500" />
|
||||
<p>{t("feed_form.feed_not_found")}</p>
|
||||
<p>{url}</p>
|
||||
</div>
|
||||
)}
|
||||
) : feedQuery.error ? (
|
||||
<div className="center grow flex-col gap-3">
|
||||
<i className="i-mgc-close-cute-re text-red size-7" />
|
||||
<p>{t("feed_form.error_fetching_feed")}</p>
|
||||
<p className="cursor-text select-text break-all px-8 text-center">
|
||||
{getFetchErrorMessage(feedQuery.error)}
|
||||
</p>
|
||||
|
||||
<div className="flex items-center gap-4">
|
||||
<Button
|
||||
variant="text"
|
||||
onClick={() => {
|
||||
feedQuery.refetch()
|
||||
}}
|
||||
>
|
||||
{t("feed_form.retry")}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="primary"
|
||||
onClick={() => {
|
||||
window.open(
|
||||
getNewIssueUrl({
|
||||
body: [
|
||||
"### Info:",
|
||||
"",
|
||||
"Feed URL:",
|
||||
"```",
|
||||
url,
|
||||
"```",
|
||||
"",
|
||||
"Error:",
|
||||
"```",
|
||||
getFetchErrorMessage(feedQuery.error),
|
||||
"```",
|
||||
].join("\n"),
|
||||
title: `Error in fetching feed: ${id ?? url}`,
|
||||
target: "discussion",
|
||||
category: "feed-expired",
|
||||
}),
|
||||
"_blank",
|
||||
)
|
||||
}}
|
||||
>
|
||||
{t("feed_form.feedback")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="center h-full grow flex-col">
|
||||
<i className="i-mgc-question-cute-re mb-6 size-12 text-zinc-500" />
|
||||
<p>{t("feed_form.feed_not_found")}</p>
|
||||
<p>{url}</p>
|
||||
</div>
|
||||
)}
|
||||
</ScrollArea.ScrollArea>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -160,6 +169,8 @@ const FeedInnerForm = ({
|
||||
subscriptionData,
|
||||
feed,
|
||||
entries,
|
||||
|
||||
rootContainerRef,
|
||||
}: {
|
||||
defaultValues?: z.infer<typeof formSchema>
|
||||
id?: string
|
||||
@@ -173,10 +184,11 @@ const FeedInnerForm = ({
|
||||
}
|
||||
feed: FeedModel
|
||||
entries?: EntryModelSimple[]
|
||||
|
||||
rootContainerRef: React.RefObject<HTMLDivElement>
|
||||
}) => {
|
||||
const subscription = useSubscriptionByFeedId(id || "") || subscriptionData
|
||||
const isSubscribed = !!subscription
|
||||
const buttonRef = useRef<HTMLButtonElement>(null)
|
||||
|
||||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
resolver: zodResolver(formSchema),
|
||||
@@ -367,23 +379,24 @@ const FeedInnerForm = ({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<div className="bg-theme-background absolute inset-x-0 bottom-0 right-[6px] flex flex-1 items-center justify-end gap-4 p-4">
|
||||
{isSubscribed && (
|
||||
<Button
|
||||
type="button"
|
||||
ref={buttonRef}
|
||||
variant="text"
|
||||
onClick={() => {
|
||||
dismiss()
|
||||
}}
|
||||
>
|
||||
{t.common("words.cancel")}
|
||||
<RootPortal to={rootContainerRef.current}>
|
||||
<div className="flex items-center justify-end gap-4 px-4 pt-2">
|
||||
{isSubscribed && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="text"
|
||||
onClick={() => {
|
||||
dismiss()
|
||||
}}
|
||||
>
|
||||
{t.common("words.cancel")}
|
||||
</Button>
|
||||
)}
|
||||
<Button type="submit" isLoading={followMutation.isPending}>
|
||||
{isSubscribed ? t("feed_form.update") : t("feed_form.follow")}
|
||||
</Button>
|
||||
)}
|
||||
<Button ref={buttonRef} type="submit" isLoading={followMutation.isPending}>
|
||||
{isSubscribed ? t("feed_form.update") : t("feed_form.follow")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</RootPortal>
|
||||
</form>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { LoadingCircle } from "@follow/components/ui/loading/index.js"
|
||||
import type { FeedViewType } from "@follow/constants"
|
||||
import { views } from "@follow/constants"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import type { FC } from "react"
|
||||
import { memo } from "react"
|
||||
|
||||
import { getSkeletonItemComponentByView } from "./Items/getSkeletonItemComponentByView"
|
||||
import { girdClassNames } from "./styles"
|
||||
|
||||
const LoadingCircleFallback = (
|
||||
<div className="center mt-2">
|
||||
<LoadingCircle size="medium" />
|
||||
</div>
|
||||
)
|
||||
export const EntryItemSkeleton: FC<{
|
||||
view: FeedViewType
|
||||
count?: number
|
||||
}> = memo(({ view, count = 10 }) => {
|
||||
const SkeletonItem = getSkeletonItemComponentByView(view)
|
||||
|
||||
if (!SkeletonItem) {
|
||||
return LoadingCircleFallback
|
||||
}
|
||||
|
||||
if (count === 1) {
|
||||
return SkeletonItem
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn(views[view]!.gridMode ? girdClassNames : "flex flex-col")}>
|
||||
{Array.from({ length: count }).map((_, index) => (
|
||||
// eslint-disable-next-line @eslint-react/no-array-index-key -- index is unique
|
||||
<div key={index}>{SkeletonItem}</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
})
|
||||
@@ -0,0 +1,20 @@
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
|
||||
import { ArticleItem } from "./article-item"
|
||||
import { AudioItem } from "./audio-item"
|
||||
import { NotificationItem } from "./notification-item"
|
||||
import { PictureItem } from "./picture-item"
|
||||
import { SocialMediaItem } from "./social-media-item"
|
||||
import { VideoItem } from "./video-item"
|
||||
|
||||
const ItemMap = {
|
||||
[FeedViewType.Articles]: ArticleItem,
|
||||
[FeedViewType.SocialMedia]: SocialMediaItem,
|
||||
[FeedViewType.Pictures]: PictureItem,
|
||||
[FeedViewType.Videos]: VideoItem,
|
||||
[FeedViewType.Audios]: AudioItem,
|
||||
[FeedViewType.Notifications]: NotificationItem,
|
||||
}
|
||||
export const getItemComponentByView = (view: FeedViewType) => {
|
||||
return ItemMap[view] || ArticleItem
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
|
||||
import { ArticleItemSkeleton } from "./article-item"
|
||||
import { AudioItemSkeleton } from "./audio-item"
|
||||
import { NotificationItemSkeleton } from "./notification-item"
|
||||
import { PictureItemSkeleton } from "./picture-item"
|
||||
import { SocialMediaItemSkeleton } from "./social-media-item"
|
||||
import { VideoItemSkeleton } from "./video-item"
|
||||
|
||||
const SkeletonItemMap = {
|
||||
[FeedViewType.Articles]: ArticleItemSkeleton,
|
||||
[FeedViewType.SocialMedia]: SocialMediaItemSkeleton,
|
||||
[FeedViewType.Pictures]: PictureItemSkeleton,
|
||||
[FeedViewType.Videos]: VideoItemSkeleton,
|
||||
[FeedViewType.Audios]: AudioItemSkeleton,
|
||||
[FeedViewType.Notifications]: NotificationItemSkeleton,
|
||||
}
|
||||
|
||||
export const getSkeletonItemComponentByView = (view: FeedViewType) => {
|
||||
return SkeletonItemMap[view]
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
|
||||
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,
|
||||
[FeedViewType.SocialMedia]: SocialMediaItem,
|
||||
[FeedViewType.Pictures]: PictureItem,
|
||||
[FeedViewType.Videos]: VideoItem,
|
||||
[FeedViewType.Audios]: AudioItem,
|
||||
[FeedViewType.Notifications]: NotificationItem,
|
||||
}
|
||||
export const getItemComponentByView = (view: FeedViewType) => {
|
||||
return ItemMap[view] || ArticleItem
|
||||
}
|
||||
|
||||
const SkeletonItemMap = {
|
||||
[FeedViewType.Articles]: ArticleItemSkeleton,
|
||||
[FeedViewType.SocialMedia]: SocialMediaItemSkeleton,
|
||||
[FeedViewType.Pictures]: PictureItemSkeleton,
|
||||
[FeedViewType.Videos]: VideoItemSkeleton,
|
||||
[FeedViewType.Audios]: AudioItemSkeleton,
|
||||
[FeedViewType.Notifications]: NotificationItemSkeleton,
|
||||
}
|
||||
|
||||
export const getSkeletonItemComponentByView = (view: FeedViewType) => {
|
||||
return SkeletonItemMap[view]
|
||||
}
|
||||
+67
-52
@@ -1,60 +1,75 @@
|
||||
import { Skeleton } from "@follow/components/ui/skeleton/index.jsx"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import {
|
||||
MasonryItemsAspectRatioContext,
|
||||
MasonryItemsAspectRatioSetterContext,
|
||||
MasonryItemWidthContext,
|
||||
useMasonryItemWidth,
|
||||
} from "@follow/components/ui/masonry/contexts.jsx"
|
||||
import { Masonry } from "@follow/components/ui/masonry/index.js"
|
||||
import { useMeasure } from "@follow/hooks"
|
||||
import { useState } from "react"
|
||||
|
||||
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 { Media, MediaContainerWidthProvider } from "~/components/ui/media"
|
||||
|
||||
import type { EntryItemStatelessProps } from "../types"
|
||||
|
||||
export function PictureItemStateLess({ entry, feed }: EntryItemStatelessProps) {
|
||||
const MasonryRender = ({ data }) => {
|
||||
const { url, type, previewImageUrl, height, width, blurhash } = data
|
||||
const itemWidth = useMasonryItemWidth()
|
||||
|
||||
return (
|
||||
<div className="text-text relative mx-auto max-w-md select-none rounded-md transition-colors">
|
||||
<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-material-opaque">·</span>
|
||||
{!!entry.publishedAt && <RelativeTime date={entry.publishedAt} />}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Media
|
||||
thumbnail
|
||||
src={url}
|
||||
type={type}
|
||||
previewImageUrl={previewImageUrl}
|
||||
className="size-full overflow-hidden"
|
||||
mediaContainerClassName={"w-auto h-auto rounded"}
|
||||
loading="lazy"
|
||||
proxy={{
|
||||
width: itemWidth,
|
||||
height: 0,
|
||||
}}
|
||||
height={height}
|
||||
width={width}
|
||||
blurhash={blurhash}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export function PictureItemStateLess({ entry }: EntryItemStatelessProps) {
|
||||
const [masonryItemsRadio, setMasonryItemsRadio] = useState<Record<string, number>>({})
|
||||
|
||||
const [ref, bounds] = useMeasure()
|
||||
const mediaItems =
|
||||
entry.media?.map((item) => ({
|
||||
url: item.url,
|
||||
type: item.type,
|
||||
previewImageUrl: item.preview_image_url,
|
||||
height: item.height,
|
||||
width: item.width,
|
||||
blurhash: item.blurhash,
|
||||
})) || []
|
||||
|
||||
const currentItemWidth = (bounds.width - 12) / 2
|
||||
|
||||
return (
|
||||
<div className="text-text relative w-full select-none rounded-md transition-colors" ref={ref}>
|
||||
<MasonryItemWidthContext.Provider value={currentItemWidth}>
|
||||
<MasonryItemsAspectRatioContext.Provider value={masonryItemsRadio}>
|
||||
<MasonryItemsAspectRatioSetterContext.Provider value={setMasonryItemsRadio}>
|
||||
<MediaContainerWidthProvider width={currentItemWidth}>
|
||||
<Masonry
|
||||
items={mediaItems}
|
||||
columnGutter={12}
|
||||
columnWidth={currentItemWidth}
|
||||
columnCount={2}
|
||||
overscanBy={2}
|
||||
render={MasonryRender}
|
||||
/>
|
||||
</MediaContainerWidthProvider>
|
||||
</MasonryItemsAspectRatioSetterContext.Provider>
|
||||
</MasonryItemsAspectRatioContext.Provider>
|
||||
</MasonryItemWidthContext.Provider>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ const ActionBar = ({ entryId }: { entryId: string }) => {
|
||||
|
||||
export function SocialMediaItemStateLess({ entry, feed }: EntryItemStatelessProps) {
|
||||
return (
|
||||
<div className="relative m-auto select-none rounded-md text-zinc-700 transition-colors dark:text-neutral-400">
|
||||
<div className="relative select-none rounded-md text-zinc-700 transition-colors dark:text-neutral-400">
|
||||
<div className="relative">
|
||||
<div className="group relative flex px-8 py-6">
|
||||
<FeedIcon className="mr-2 size-9" feed={feed} fallback />
|
||||
@@ -171,7 +171,7 @@ export function SocialMediaItemStateLess({ entry, feed }: EntryItemStatelessProp
|
||||
<div className="relative mt-0.5 text-sm">{entry.description}</div>
|
||||
</div>
|
||||
<div className="mt-2 flex gap-2 overflow-x-auto">
|
||||
{entry.media?.map((media) => (
|
||||
{entry.media?.slice(0, 2).map((media) => (
|
||||
<Media
|
||||
key={media.url}
|
||||
thumbnail
|
||||
|
||||
@@ -18,7 +18,8 @@ import {
|
||||
|
||||
import { useUISettingKey } from "~/atoms/settings/ui"
|
||||
|
||||
import { EntryItem, EntryItemSkeleton } from "./item"
|
||||
import { EntryItemSkeleton } from "./EntryItemSkeleton"
|
||||
import { EntryItem } from "./item"
|
||||
import { PictureMasonry } from "./Items/picture-masonry"
|
||||
import type { EntryListProps } from "./list"
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import { LoadingCircle } from "@follow/components/ui/loading/index.jsx"
|
||||
import type { FeedViewType } from "@follow/constants"
|
||||
import { views } from "@follow/constants"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import type { FC } from "react"
|
||||
import { forwardRef, memo } from "react"
|
||||
|
||||
@@ -9,9 +6,8 @@ import { useEntryTranslation } from "~/store/ai/hook"
|
||||
import type { FlatEntryModel } from "~/store/entry"
|
||||
import { useEntry } from "~/store/entry/hooks"
|
||||
|
||||
import { getItemComponentByView, getSkeletonItemComponentByView } from "./Items"
|
||||
import { getItemComponentByView } from "./Items/getItemComponentByView"
|
||||
import { EntryItemWrapper } from "./layouts/EntryItemWrapper"
|
||||
import { girdClassNames } from "./styles"
|
||||
import type { EntryListItemFC } from "./types"
|
||||
|
||||
interface EntryItemProps {
|
||||
@@ -51,33 +47,3 @@ export const EntryVirtualListItem = forwardRef<
|
||||
</div>
|
||||
)
|
||||
})
|
||||
|
||||
const LoadingCircleFallback = (
|
||||
<div className="center mt-2">
|
||||
<LoadingCircle size="medium" />
|
||||
</div>
|
||||
)
|
||||
|
||||
export const EntryItemSkeleton: FC<{
|
||||
view: FeedViewType
|
||||
count?: number
|
||||
}> = memo(({ view, count = 10 }) => {
|
||||
const SkeletonItem = getSkeletonItemComponentByView(view)
|
||||
|
||||
if (!SkeletonItem) {
|
||||
return LoadingCircleFallback
|
||||
}
|
||||
|
||||
if (count === 1) {
|
||||
return SkeletonItem
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn(views[view]!.gridMode ? girdClassNames : "flex flex-col")}>
|
||||
{Array.from({ length: count }).map((_, index) => (
|
||||
// eslint-disable-next-line @eslint-react/no-array-index-key -- index is unique
|
||||
<div key={index}>{SkeletonItem}</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -29,7 +29,8 @@ import { isListSubscription } from "~/store/subscription"
|
||||
|
||||
import { DateItem } from "./components/DateItem"
|
||||
import { EntryColumnShortcutHandler } from "./EntryColumnShortcutHandler"
|
||||
import { EntryItemSkeleton, EntryVirtualListItem } from "./item"
|
||||
import { EntryItemSkeleton } from "./EntryItemSkeleton"
|
||||
import { EntryVirtualListItem } from "./item"
|
||||
|
||||
export const EntryEmptyList = forwardRef<HTMLDivElement, HTMLMotionProps<"div">>((props, ref) => {
|
||||
const unreadOnly = useGeneralSettingKey("unreadOnly")
|
||||
|
||||
@@ -53,6 +53,7 @@ const CmdNPanel = () => {
|
||||
|
||||
present({
|
||||
title: t("feed_form.add_feed"),
|
||||
modalContentClassName: "overflow-visible",
|
||||
content: () => (
|
||||
<FeedForm
|
||||
url={url}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Card, CardContent, CardHeader } from "@follow/components/ui/card/index.jsx"
|
||||
import { ScrollArea } from "@follow/components/ui/scroll-area/ScrollArea.js"
|
||||
import { FeedViewType, views } from "@follow/constants"
|
||||
import type { EntryModelSimple, FeedModel } from "@follow/models"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
@@ -6,7 +7,7 @@ import { cloneElement, forwardRef } from "react"
|
||||
|
||||
import { useI18n } from "~/hooks/common"
|
||||
|
||||
import { EntryItemSkeleton } from "../entry-column/item"
|
||||
import { EntryItemSkeleton } from "../entry-column/EntryItemSkeleton"
|
||||
import { EntryItemStateless } from "../entry-column/item-stateless"
|
||||
|
||||
export const ViewSelectorRadioGroup = forwardRef<
|
||||
@@ -57,10 +58,14 @@ export const ViewSelectorRadioGroup = forwardRef<
|
||||
))}
|
||||
</CardHeader>
|
||||
{showPreview && (
|
||||
<CardContent className="space-y-2 p-2">
|
||||
{entries.slice(0, 2).map((entry) => (
|
||||
<EntryItemStateless entry={entry} feed={feed} view={view} key={entry.guid} />
|
||||
))}
|
||||
<CardContent className="relative h-64 w-full">
|
||||
<div className="absolute inset-0">
|
||||
<ScrollArea flex rootClassName="h-full" viewportClassName="flex flex-col gap-2">
|
||||
{entries.slice(0, 2).map((entry) => (
|
||||
<EntryItemStateless entry={entry} feed={feed} view={view} key={entry.guid} />
|
||||
))}
|
||||
</ScrollArea>
|
||||
</div>
|
||||
</CardContent>
|
||||
)}
|
||||
{showLoading && <EntryItemSkeleton view={view ?? FeedViewType.Articles} count={2} />}
|
||||
|
||||
Reference in New Issue
Block a user