From f9aca60d6f3f3854efd3d4e2db304e31524338c1 Mon Sep 17 00:00:00 2001 From: Innei Date: Mon, 16 Jun 2025 23:22:56 +0800 Subject: [PATCH] refactor(ui): re-design rsshub page ui - Improved the layout and styling of the ActionSetting, Recommendations, UserProfileModal, Trending, and RSSHub components for better visual consistency and responsiveness. - Adjusted class names to center elements and enhance spacing, ensuring a more cohesive user experience. - Updated the UserAvatar component to display either the user's name or handle when the name is not available. - Refactored the discover page to include a more structured header and additional content sections, improving overall navigation and accessibility. These changes aim to enhance the user interface and provide a more intuitive experience across the application. Signed-off-by: Innei --- .../src/modules/action/action-setting.tsx | 8 +- .../src/modules/discover/recommendations.tsx | 2 +- .../profile/user-profile-modal.electron.tsx | 2 +- .../renderer/src/modules/trending/index.tsx | 2 +- .../renderer/src/modules/user/UserAvatar.tsx | 2 +- .../(layer)/(subview)/discover/index.tsx | 120 +++-- .../(main)/(layer)/(subview)/rsshub/index.tsx | 431 ++++++++++-------- packages/internal/store/src/user/store.ts | 52 ++- 8 files changed, 363 insertions(+), 256 deletions(-) diff --git a/apps/desktop/layer/renderer/src/modules/action/action-setting.tsx b/apps/desktop/layer/renderer/src/modules/action/action-setting.tsx index 08d807321..05391b3a8 100644 --- a/apps/desktop/layer/renderer/src/modules/action/action-setting.tsx +++ b/apps/desktop/layer/renderer/src/modules/action/action-setting.tsx @@ -75,7 +75,13 @@ export const ActionSetting = () => { const actionQuery = usePrefetchActions() if (actionQuery.isPending) { - return } size="large" /> + return ( + } + size="large" + /> + ) } const hasActions = actions.length > 0 diff --git a/apps/desktop/layer/renderer/src/modules/discover/recommendations.tsx b/apps/desktop/layer/renderer/src/modules/discover/recommendations.tsx index 8887df1c1..5191a3313 100644 --- a/apps/desktop/layer/renderer/src/modules/discover/recommendations.tsx +++ b/apps/desktop/layer/renderer/src/modules/discover/recommendations.tsx @@ -34,7 +34,7 @@ export function Recommendations() { } return ( -
+
diff --git a/apps/desktop/layer/renderer/src/modules/profile/user-profile-modal.electron.tsx b/apps/desktop/layer/renderer/src/modules/profile/user-profile-modal.electron.tsx index acd3f35c8..8d97961c3 100644 --- a/apps/desktop/layer/renderer/src/modules/profile/user-profile-modal.electron.tsx +++ b/apps/desktop/layer/renderer/src/modules/profile/user-profile-modal.electron.tsx @@ -238,7 +238,7 @@ const UserInfo = ({ userInfo }: { userInfo: PickedUser }) => { const whoami = useWhoami() const follow = useFollow() return ( -
+
+
- {!hideName &&
{renderUserData?.name}
} + {!hideName &&
{renderUserData?.name || renderUserData?.handle}
}
) } diff --git a/apps/desktop/layer/renderer/src/pages/(main)/(layer)/(subview)/discover/index.tsx b/apps/desktop/layer/renderer/src/pages/(main)/(layer)/(subview)/discover/index.tsx index 200fb7b1f..e2522cd12 100644 --- a/apps/desktop/layer/renderer/src/pages/(main)/(layer)/(subview)/discover/index.tsx +++ b/apps/desktop/layer/renderer/src/pages/(main)/(layer)/(subview)/discover/index.tsx @@ -73,55 +73,81 @@ export function Component() { }) return ( -
-
{t("words.discover")}
- { - setSearch( - (search) => { - search.set("type", val) - return new URLSearchParams(search) - }, - { replace: true }, - ) - }} - className="w-full" - > - - +
+ {/* Simple Header */} +
+

{t("words.discover")}

+
+ +
+ { + setSearch( + (search) => { + search.set("type", val) + return new URLSearchParams(search) + }, + { replace: true }, + ) + }} + className="w-full" + > + {/* Tab Navigation */} +
+ + + {currentTabs.map((tab) => ( + { + if (tab.disabled) { + presentActivationModal() + } + }} + > + {t(tab.name)} + + ))} + + +
+ + {/* Tab Content */} +
{currentTabs.map((tab) => ( - { - if (tab.disabled) { - presentActivationModal() - } - }} - > - {t(tab.name)} - + +
+ {createElement(TabComponent[tab.value]! || TabComponent.default, { + type: tab.value, + })} +
+
))} - - - {currentTabs.map((tab) => ( - -
- {createElement(TabComponent[tab.value]! || TabComponent.default, { - type: tab.value, - })} -
-
- ))} - - - - - - - +
+
+ + {/* Additional Content Sections */} +
+ + +
+

Trending

+ +
+ + + +
+

Recommendations

+ + + +
+
+
) } diff --git a/apps/desktop/layer/renderer/src/pages/(main)/(layer)/(subview)/rsshub/index.tsx b/apps/desktop/layer/renderer/src/pages/(main)/(layer)/(subview)/rsshub/index.tsx index 9d696ff25..24351e267 100644 --- a/apps/desktop/layer/renderer/src/pages/(main)/(layer)/(subview)/rsshub/index.tsx +++ b/apps/desktop/layer/renderer/src/pages/(main)/(layer)/(subview)/rsshub/index.tsx @@ -1,15 +1,8 @@ import { Logo } from "@follow/components/icons/logo.jsx" import { Button } from "@follow/components/ui/button/index.js" -import { - Table, - TableBody, - TableCell, - TableHead, - TableHeader, - TableRow, -} from "@follow/components/ui/table/index.jsx" -import { EllipsisTextWithTooltip } from "@follow/components/ui/typography/index.js" import type { RSSHubModel } from "@follow/models" +import { cn, formatNumber } from "@follow/utils/utils" +import { memo } from "react" import { useTranslation } from "react-i18next" import RSSHubIconUrl from "~/assets/rsshub-icon.png?url" @@ -27,6 +20,7 @@ import { Queries } from "~/queries" import { useSetRSSHubMutation } from "~/queries/rsshub" const RSSHubIcon = new URL(RSSHubIconUrl, import.meta.url).href + export function Component() { const { t } = useTranslation("settings") const { present } = useModalStack() @@ -36,32 +30,49 @@ export function Component() { const list = useAuthQuery(Queries.rsshub.list()) return ( -
-
- -
-
{t("words.rsshub", { ns: "common" })}
-
{t("rsshub.description")}
- -
{t("rsshub.public_instances")}
- +

{t("words.rsshub", { ns: "common" })}

+

+ {t("rsshub.description")} +

+
+ +
+ {/* Add Instance Section */} +
+ +
+ + {/* Instances Section */} +
+
+

{t("rsshub.public_instances")}

+
+ +
+
) } -function List({ data }: { data?: RSSHubModel[] }) { +type InstanceItem = RSSHubModel | { id: string; isOfficial: true } + +const InstanceCard = memo(({ item }: { item: InstanceItem }) => { const { t } = useTranslation("settings") const me = whoami() const status = useAuthQuery(Queries.rsshub.status()) @@ -69,175 +80,211 @@ function List({ data }: { data?: RSSHubModel[] }) { const presetTOTPModal = useTOTPModalWrapper(setRSSHubMutation.mutateAsync) const { present } = useModalStack() + const isOfficial = "isOfficial" in item && item.isOfficial + const instance = isOfficial ? ({} as Partial) : (item as RSSHubModel) + + const isInUse = isOfficial + ? !status?.data?.usage?.rsshubId + : status?.data?.usage?.rsshubId === instance.id + const isOwner = !isOfficial && instance.ownerUserId === me?.id + const hasError = !isOfficial && !!instance.errorMessage + + const headerIcon = isOfficial ? ( + + ) : ( + + ) + + const title = isOfficial ? "Folo Official" : "" + const price = isOfficial ? 0 : instance.price + const description = isOfficial ? "Folo Built-in RSSHub" : instance.description + + const usersStat = isOfficial ? "*" : instance.userCount || 0 + const limitStat = isOfficial + ? t("rsshub.table.unlimited") + : instance.userLimit == null + ? t("rsshub.table.unlimited") + : instance.userLimit > 1 + ? instance.userLimit + : t("rsshub.table.private") + + const tags = ( + <> + {isOfficial && ( + + {t("rsshub.table.official")} + + )} + {isInUse && ( + + {t("rsshub.table.inuse")} + + )} + {isOwner && ( + + {t("rsshub.table.yours")} + + )} + {hasError && Error} + + ) + + const containerClassName = cn( + "border-fill-secondary relative rounded-lg border p-4", + isOfficial ? "bg-fill-vibrant-quaternary" : "bg-fill-vibrant-quinary", + isInUse && "ring-accent/20 ring-2", + hasError && "border-red/30 bg-red/5", + ) + + const instanceUserCountExceptOwner = isOfficial + ? 0 + : instance.userCount + ? instance.userCount - (instance.ownerUserId === me?.id ? 1 : 0) + : 0 + return ( - - - - - - {t("rsshub.table.owner")} - - - {t("rsshub.table.description")} - - - {t("rsshub.table.price")} - - - {t("rsshub.table.userCount")} - - - {t("rsshub.table.userLimit")} - - - - - - - {t("rsshub.table.official")} - - - - Folo - - - Folo Built-in RSSHub - - - 0 - - - * - {t("rsshub.table.unlimited")} - - {!status?.data?.usage?.rsshubId && ( - - )} - {!!status?.data?.usage?.rsshubId && ( - - )} - - - {data - ?.sort((a, b) => { - // in use first - if (status?.data?.usage?.rsshubId === a.id) { - return -1 - } - if (status?.data?.usage?.rsshubId === b.id) { - return 1 - } + + + )} + +
+ {isOfficial ? ( +
+ {isInUse ? ( + + ) : ( + + )} +
+ ) : ( + + )} +
+ + + ) +}) - if (a.errorMessage && !b.errorMessage) { - return 1 - } - if (!a.errorMessage && b.errorMessage) { - return -1 - } +function List({ data }: { data?: RSSHubModel[] }) { + const status = useAuthQuery(Queries.rsshub.status()) - const loadA = Math.min((a.userCount ?? 0) / (a.userLimit ?? Infinity), 1) - const loadB = Math.min((b.userCount ?? 0) / (b.userLimit ?? Infinity), 1) + const sortedData: InstanceItem[] = [ + // Official instance first + { + id: "official", + isOfficial: true, + }, + // Then user instances + ...(data?.sort((a, b) => { + // in use first + if (status?.data?.usage?.rsshubId === a.id) { + return -1 + } + if (status?.data?.usage?.rsshubId === b.id) { + return 1 + } - // full load last - if (loadA === 1 && loadB === 1) { - return a.price - b.price - } - if (loadA === 1) { - return 1 - } - if (loadB === 1) { - return -1 - } + if (a.errorMessage && !b.errorMessage) { + return 1 + } + if (!a.errorMessage && b.errorMessage) { + return -1 + } - return a.price - b.price || loadA - loadB - }) - .map((instance) => { - const instanceUserCountExceptOwner = instance.userCount - ? instance.userCount - (instance.ownerUserId === me?.id ? 1 : 0) - : 0 + const loadA = Math.min((a.userCount ?? 0) / (a.userLimit ?? Infinity), 1) + const loadB = Math.min((b.userCount ?? 0) / (b.userLimit ?? Infinity), 1) - return ( - - - {(() => { - const flag: string[] = [] - if (status?.data?.usage?.rsshubId === instance.id) { - flag.push(t("rsshub.table.inuse")) - } - if (instance.ownerUserId === me?.id) { - flag.push(t("rsshub.table.yours")) - } - return flag.join(" / ") - })()} - - - - - - - {instance.description} - - - - - {instance.price} - - - {instance.userCount} - - {instance.userLimit === null - ? t("rsshub.table.unlimited") - : instance.userLimit > 1 - ? instance.userLimit - : t("rsshub.table.private")} - - -
- - {me?.id === instance.ownerUserId && ( - - )} - {me?.id === instance.ownerUserId && ( - - )} -
-
-
- ) - })} -
-
+ // full load last + if (loadA === 1 && loadB === 1) { + return a.price - b.price + } + if (loadA === 1) { + return 1 + } + if (loadB === 1) { + return -1 + } + + return a.price - b.price || loadA - loadB + }) || []), + ] + + return ( +
+ {sortedData.map((item) => ( + + ))} +
) } diff --git a/packages/internal/store/src/user/store.ts b/packages/internal/store/src/user/store.ts index cd14b1e2b..3b30cf935 100644 --- a/packages/internal/store/src/user/store.ts +++ b/packages/internal/store/src/user/store.ts @@ -2,6 +2,7 @@ import { UserRole } from "@follow/constants" import type { UserSchema } from "@follow/database/schemas/types" import { UserService } from "@follow/database/services/user" import type { AuthSession } from "@follow/shared/hono" +import { create, indexedResolver, windowScheduler } from "@yornaath/batshit" import { apiClient, authClient } from "../context" import type { Hydratable } from "../internal/base" @@ -31,6 +32,34 @@ const get = useUserStore.getState const immerSet = createImmerSetter(useUserStore) class UserSyncService { + private userBatcher = create({ + fetcher: async (userIds: string[]) => { + const res = await apiClient().profiles.batch.$post({ + json: { ids: userIds }, + }) + + if (res.code === 0) { + const { whoami } = get() + const usersObject = res.data + const usersArray = Object.values(usersObject) + + immerSet((state) => { + for (const user of usersArray) { + state.users[user.id] = { + email: null, + isMe: whoami?.id === user.id, + ...user, + } + } + }) + return usersObject + } + return {} + }, + resolver: indexedResolver(), + scheduler: windowScheduler(100), + }) + async whoami() { const res = (await (apiClient()["better-auth"] as any)[ "get-session" @@ -153,19 +182,18 @@ class UserSyncService { async fetchUser(userId: string | undefined) { if (!userId) return null - const res = await apiClient().profiles.$get({ query: { id: userId } }) - if (res.code === 0) { - const { whoami } = get() - immerSet((state) => { - state.users[userId] = { - email: null, - isMe: whoami?.id === userId, - ...res.data, - } - }) - } - return res.data + // 使用批处理器获取用户 + const user = await this.userBatcher.fetch(userId) + return user || null + } + + async fetchUsers(userIds: string[]) { + const validUserIds = userIds.filter(Boolean) + if (validUserIds.length === 0) return [] + + const users = await Promise.all(validUserIds.map((id) => this.userBatcher.fetch(id))) + return users.filter(Boolean) } }