From a14f6940fcc62e2a7105cf3be9c479aee745561b Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sat, 3 May 2025 13:13:47 +0800 Subject: [PATCH] feat(desktop): discover feed card module --- .../src/modules/discover/feed-card.tsx | 208 ++++++++++++++++++ .../renderer/src/modules/discover/form.tsx | 204 +---------------- 2 files changed, 213 insertions(+), 199 deletions(-) create mode 100644 apps/desktop/layer/renderer/src/modules/discover/feed-card.tsx diff --git a/apps/desktop/layer/renderer/src/modules/discover/feed-card.tsx b/apps/desktop/layer/renderer/src/modules/discover/feed-card.tsx new file mode 100644 index 000000000..b3c0083e9 --- /dev/null +++ b/apps/desktop/layer/renderer/src/modules/discover/feed-card.tsx @@ -0,0 +1,208 @@ +import { Button } from "@follow/components/ui/button/index.js" +import { Card, CardContent, CardFooter, CardHeader } from "@follow/components/ui/card/index.jsx" +import { RelativeTime } from "@follow/components/ui/datetime/index.js" +import { getBackgroundGradient } from "@follow/utils/color" +import type { FC } from "react" +import { memo } from "react" +import { useTranslation } from "react-i18next" + +import { Media } from "~/components/ui/media" +import { useFollow } from "~/hooks/biz/useFollow" +import { getRouteParams } from "~/hooks/biz/useRouteParams" +import { useFeedSafeUrl } from "~/hooks/common/useFeedSafeUrl" +import type { apiClient } from "~/lib/api-fetch" +import { UrlBuilder } from "~/lib/url-builder" + +import { FollowSummary } from "../feed/feed-summary" + +const numberFormatter = new Intl.NumberFormat("en-US", {}) + +type DiscoverSearchData = Awaited>["data"] + +export const FeedCard: FC<{ + item: DiscoverSearchData[number] + onSuccess?: (item: DiscoverSearchData[number]) => void + onUnSubscribed?: (item: DiscoverSearchData[number]) => void + children?: React.ReactNode +}> = memo(({ item, onSuccess, children }) => { + const follow = useFollow() + const { t } = useTranslation() + + return ( + + {children} + + + + {item.docs ? ( + + + + + + ) : ( + <> + {!!item.entries?.length && ( + +
+ {item.entries + .filter((e) => !!e) + .map((entry) => ( + + ))} +
+
+ )} + +
+
+ + + + {numberFormatter.format(item.subscriptionCount ?? 0)}{" "} + {t("feed.follower", { count: item.subscriptionCount ?? 0 })} + +
+ {item.updatesPerWeek ? ( +
+ + {t("feed.entry_week", { count: item.updatesPerWeek ?? 0 })} +
+ ) : item.entries?.[0]?.publishedAt ? ( +
+ + {t("feed.updated_at")} + +
+ ) : null} +
+ +
+ + +
+
+ + )} +
+ ) +}) + +const SearchResultContent: FC<{ + entry: NonUndefined[number] +}> = memo(({ entry }) => { + const safeUrl = useFeedSafeUrl(entry.id) + return ( + +
+ +
+
+ {entry.title ? ( +
+ {entry.title} +
+ ) : ( +
+ + {entry.url || "Untitled"} +
+ )} +
+ +
+
+
+ ) +}) + +const FeedCardMediaThumbnail: FC<{ + entry: NonUndefined[number] +}> = ({ entry }) => { + const [, , , bgAccent, bgAccentLight] = getBackgroundGradient( + entry.title || entry.url || "Untitled", + ) + + if (entry.media?.[0]) { + return ( +
+ +
+
+ ) + } + + return ( +
+
+
+ {entry.title ? ( +
+ {entry.title.slice(0, 1).toUpperCase()} +
+ ) : ( + + )} +
+
+
+ ) +} diff --git a/apps/desktop/layer/renderer/src/modules/discover/form.tsx b/apps/desktop/layer/renderer/src/modules/discover/form.tsx index b879cbfcf..e9320c365 100644 --- a/apps/desktop/layer/renderer/src/modules/discover/form.tsx +++ b/apps/desktop/layer/renderer/src/modules/discover/form.tsx @@ -1,7 +1,5 @@ import { useMobile } from "@follow/components/hooks/useMobile.js" import { Button } from "@follow/components/ui/button/index.js" -import { Card, CardContent, CardFooter, CardHeader } from "@follow/components/ui/card/index.jsx" -import { RelativeTime } from "@follow/components/ui/datetime/index.js" import { Form, FormControl, @@ -13,28 +11,23 @@ import { import { Input } from "@follow/components/ui/input/index.js" import { SegmentGroup, SegmentItem } from "@follow/components/ui/segment/index.js" import { ResponsiveSelect } from "@follow/components/ui/select/responsive.js" -import { getBackgroundGradient } from "@follow/utils/color" import { zodResolver } from "@hookform/resolvers/zod" import { repository } from "@pkg" import { useMutation } from "@tanstack/react-query" import { produce } from "immer" import { atom, useAtomValue, useStore } from "jotai" -import type { ChangeEvent, FC } from "react" -import { memo, useCallback, useState } from "react" +import type { ChangeEvent } from "react" +import { useCallback, useState } from "react" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" import { z } from "zod" import { useIsInMASReview } from "~/atoms/server-configs" -import { Media } from "~/components/ui/media" import { useModalStack } from "~/components/ui/modal/stacked/hooks" -import { useFollow } from "~/hooks/biz/useFollow" import { getRouteParams } from "~/hooks/biz/useRouteParams" -import { useFeedSafeUrl } from "~/hooks/common/useFeedSafeUrl" import { apiClient } from "~/lib/api-fetch" -import { UrlBuilder } from "~/lib/url-builder" -import { FollowSummary } from "../feed/feed-summary" +import { FeedCard } from "./feed-card" import { FeedForm } from "./feed-form" const formSchema = z.object({ @@ -42,8 +35,6 @@ const formSchema = z.object({ target: z.enum(["feeds", "lists"]), }) -const numberFormatter = new Intl.NumberFormat("en-US", {}) - const info: Record< string, { @@ -237,7 +228,7 @@ export function DiscoverForm({ type = "search" }: { type?: string }) { className="w-full max-w-[540px]" data-testid="discover-form" > -
+
{discoverSearchData?.map((item) => ( - ) } - -const SearchCard: FC<{ - item: DiscoverSearchData[number] - onSuccess: (item: DiscoverSearchData[number]) => void - onUnSubscribed?: (item: DiscoverSearchData[number]) => void -}> = memo(({ item, onSuccess }) => { - const follow = useFollow() - const { t } = useTranslation() - - return ( - - - - - {item.docs ? ( - - - - - - ) : ( - <> - - {!!item.entries?.length && ( -
- {item.entries - .filter((e) => !!e) - .map((entry) => ( - - ))} -
- )} -
- -
-
- - - - {numberFormatter.format(item.subscriptionCount ?? 0)}{" "} - {t("feed.follower", { count: item.subscriptionCount ?? 0 })} - -
- {item.updatesPerWeek ? ( -
- - {t("feed.entry_week", { count: item.updatesPerWeek ?? 0 })} -
- ) : item.entries?.[0]?.publishedAt ? ( -
- - {t("feed.updated_at")} - -
- ) : null} -
- -
- - -
-
- - )} -
- ) -}) - -const FeedCardMediaThumbnail: FC<{ - entry: NonUndefined[number] -}> = ({ entry }) => { - const [, , , bgAccent, bgAccentLight] = getBackgroundGradient( - entry.title || entry.url || "Untitled", - ) - - if (entry.media?.[0]) { - return ( -
- -
-
- ) - } - - return ( -
-
-
- {entry.title ? ( -
- {entry.title.slice(0, 1).toUpperCase()} -
- ) : ( - - )} -
-
-
- ) -} - -const SearchResultContent: FC<{ - entry: NonUndefined[number] -}> = memo(({ entry }) => { - const safeUrl = useFeedSafeUrl(entry.id) - return ( - -
- -
-
- {entry.title ? ( -
- {entry.title} -
- ) : ( -
- - {entry.url || "Untitled"} -
- )} -
- -
-
-
- ) -})