From bac3cd0ffb4d15dc821db7450f99ca6815949a9e Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 6 May 2025 19:38:20 +0800 Subject: [PATCH] feat(desktop): optimzie feed card styles --- .../src/modules/discover/feed-card.tsx | 193 +++++++++--------- .../src/modules/discover/feed-form.tsx | 21 +- .../renderer/src/modules/discover/form.tsx | 2 +- .../src/modules/feed/feed-summary.tsx | 19 +- .../renderer/src/modules/trending/index.tsx | 3 +- packages/internal/shared/src/hono.ts | 1 + 6 files changed, 125 insertions(+), 114 deletions(-) diff --git a/apps/desktop/layer/renderer/src/modules/discover/feed-card.tsx b/apps/desktop/layer/renderer/src/modules/discover/feed-card.tsx index a43559c05..bf7c433b5 100644 --- a/apps/desktop/layer/renderer/src/modules/discover/feed-card.tsx +++ b/apps/desktop/layer/renderer/src/modules/discover/feed-card.tsx @@ -1,5 +1,5 @@ import { Button } from "@follow/components/ui/button/index.js" -import { Card, CardContent, CardFooter, CardHeader } from "@follow/components/ui/card/index.jsx" +import { Card, CardContent, CardHeader } from "@follow/components/ui/card/index.jsx" import { RelativeTime } from "@follow/components/ui/datetime/index.js" import { getBackgroundGradient } from "@follow/utils/color" import { cn } from "@follow/utils/utils" @@ -21,9 +21,7 @@ import { FollowSummary } from "../feed/feed-summary" const numberFormatter = new Intl.NumberFormat("en-US", {}) -type DiscoverItem = Awaited>["data"][number] & { - view?: number -} +type DiscoverItem = Awaited>["data"][number] export const FeedCard: FC<{ item: DiscoverItem @@ -35,6 +33,8 @@ export const FeedCard: FC<{ followButtonClassName?: string followedButtonClassName?: string className?: string + simple?: boolean + hideButtons?: boolean }> = memo( ({ item, @@ -45,6 +45,8 @@ export const FeedCard: FC<{ followButtonClassName, followedButtonClassName, className, + simple, + hideButtons, }) => { const follow = useFollow() const { t } = useTranslation() @@ -62,108 +64,111 @@ export const FeedCard: FC<{ )} > {children} - - + + {item.docs ? ( - + - + ) : ( <> - {!!item.entries?.length && ( - -
- {item.entries - .filter((e) => !!e) - .map((entry) => ( - - ))} -
-
- )} - -
- {!!item.analytics?.subscriptionCount && ( -
- + +
+
+ {!!item.analytics?.subscriptionCount && ( +
+ - - {numberFormatter.format(item.analytics.subscriptionCount)}{" "} - {t("feed.follower", { count: item.analytics.subscriptionCount })} - -
- )} - {item.analytics?.updatesPerWeek ? ( -
- - - {t("feed.entry_week", { count: item.analytics.updatesPerWeek ?? 0 })} - -
- ) : item.analytics?.latestEntryPublishedAt ? ( -
- - {t("feed.updated_at")} - -
- ) : null} -
- -
- {!isSubscribed && ( - - )} -
)} - > - {isSubscribed ? t("feed.actions.followed") : t("feed.actions.follow")} - + {!simple && + (item.analytics?.updatesPerWeek ? ( +
+ + + {t("feed.entry_week", { count: item.analytics.updatesPerWeek ?? 0 })} + +
+ ) : item.analytics?.latestEntryPublishedAt ? ( +
+ + {t("feed.updated_at")} + +
+ ) : null)} +
+ + {!hideButtons && ( +
+ {!isSubscribed && ( + + )} + +
+ )}
- + {!!item.entries?.length && ( +
+
+ {item.entries + .filter((e) => !!e) + .map((entry) => ( + + ))} +
+
+ )} + )} diff --git a/apps/desktop/layer/renderer/src/modules/discover/feed-form.tsx b/apps/desktop/layer/renderer/src/modules/discover/feed-form.tsx index 537a5af6d..58b3d66f4 100644 --- a/apps/desktop/layer/renderer/src/modules/discover/feed-form.tsx +++ b/apps/desktop/layer/renderer/src/modules/discover/feed-form.tsx @@ -1,5 +1,4 @@ import { Button } from "@follow/components/ui/button/index.js" -import { Card, CardHeader } from "@follow/components/ui/card/index.jsx" import { Form, FormControl, @@ -15,7 +14,7 @@ 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" +import type { EntryModelSimple, FeedAnalyticsModel, FeedModel } from "@follow/models/types" import { tracker } from "@follow/tracker" import { cn } from "@follow/utils/utils" import { zodResolver } from "@hookform/resolvers/zod" @@ -32,7 +31,6 @@ import { useAuthQuery, useI18n } from "~/hooks/common" import { apiClient } from "~/lib/api-fetch" import { tipcClient } from "~/lib/client" import { toastFetchError } from "~/lib/error-parser" -import { FollowSummary } from "~/modules/feed/feed-summary" import { feed as feedQuery, useFeedQuery } from "~/queries/feed" import { subscription as subscriptionQuery } from "~/queries/subscriptions" import { useFeedByIdOrUrl } from "~/store/feed" @@ -40,6 +38,7 @@ import { useSubscriptionByFeedId } from "~/store/subscription" import { feedUnreadActions } from "~/store/unread" import { ViewSelectorRadioGroup } from "../shared/ViewSelectorRadioGroup" +import { FeedCard } from "./feed-card" const formSchema = z.object({ view: z.string(), @@ -106,6 +105,7 @@ export const FeedForm: Component<{ subscriptionData: feedQuery.data?.subscription, entries: feedQuery.data?.entries, feed, + analytics: feedQuery.data?.analytics, placeholderRef, }} /> @@ -164,6 +164,7 @@ const FeedInnerForm = ({ subscriptionData, feed, entries, + analytics, placeholderRef, }: { @@ -179,6 +180,7 @@ const FeedInnerForm = ({ } feed: FeedModel entries?: EntryModelSimple[] + analytics?: FeedAnalyticsModel placeholderRef: React.RefObject }) => { @@ -275,11 +277,14 @@ const FeedInnerForm = ({ return (
- - - - - +
))}
diff --git a/apps/desktop/layer/renderer/src/modules/feed/feed-summary.tsx b/apps/desktop/layer/renderer/src/modules/feed/feed-summary.tsx index cb433e70a..523ec7627 100644 --- a/apps/desktop/layer/renderer/src/modules/feed/feed-summary.tsx +++ b/apps/desktop/layer/renderer/src/modules/feed/feed-summary.tsx @@ -11,10 +11,12 @@ export function FollowSummary({ feed, docs, className, + simple, }: { feed: FeedOrListRespModel docs?: string className?: string + simple?: boolean }) { let feedText: string | undefined @@ -39,24 +41,21 @@ export function FollowSummary({
- + - {feed.description} - -
-
-
- -
- {feedText}
+ {!simple && ( + + {feed.description} + + )} ) } diff --git a/apps/desktop/layer/renderer/src/modules/trending/index.tsx b/apps/desktop/layer/renderer/src/modules/trending/index.tsx index 1a7ffa47a..b60eed283 100644 --- a/apps/desktop/layer/renderer/src/modules/trending/index.tsx +++ b/apps/desktop/layer/renderer/src/modules/trending/index.tsx @@ -131,11 +131,12 @@ export function Trending({