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 <tukon479@gmail.com>
This commit is contained in:
@@ -75,7 +75,13 @@ export const ActionSetting = () => {
|
||||
const actionQuery = usePrefetchActions()
|
||||
|
||||
if (actionQuery.isPending) {
|
||||
return <LoadingWithIcon icon={<i className="i-mgc-magic-2-cute-re" />} size="large" />
|
||||
return (
|
||||
<LoadingWithIcon
|
||||
className="flex h-64 items-center justify-center"
|
||||
icon={<i className="i-mgc-magic-2-cute-re" />}
|
||||
size="large"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const hasActions = actions.length > 0
|
||||
|
||||
@@ -34,7 +34,7 @@ export function Recommendations() {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mt-4 w-full max-w-[800px] space-y-6">
|
||||
<div className="mx-auto mt-4 w-full max-w-[800px] space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center justify-center gap-2 text-center text-xl font-bold">
|
||||
<i className="i-mgc-grid-2-cute-re text-xl" />
|
||||
|
||||
@@ -238,7 +238,7 @@ const UserInfo = ({ userInfo }: { userInfo: PickedUser }) => {
|
||||
const whoami = useWhoami()
|
||||
const follow = useFollow()
|
||||
return (
|
||||
<div className="border-fill border-b p-6">
|
||||
<div className="border-fill bg-material-medium border-b p-6">
|
||||
<div className="flex items-start gap-4">
|
||||
<Avatar className="size-20 shrink-0">
|
||||
<AvatarImage
|
||||
|
||||
@@ -70,7 +70,7 @@ export function Trending({
|
||||
})
|
||||
|
||||
return (
|
||||
<div className={cn("mt-4 w-full max-w-[800px] space-y-6", narrow && "max-w-[400px]")}>
|
||||
<div className={cn("mx-auto mt-4 w-full max-w-[800px] space-y-6", narrow && "max-w-[400px]")}>
|
||||
<div
|
||||
className={cn(
|
||||
"justify-between md:flex",
|
||||
|
||||
@@ -74,7 +74,7 @@ export const UserAvatar = ({
|
||||
{renderUserData?.name?.[0]}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
{!hideName && <div>{renderUserData?.name}</div>}
|
||||
{!hideName && <div>{renderUserData?.name || renderUserData?.handle}</div>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -73,55 +73,81 @@ export function Component() {
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="relative flex w-full flex-col items-center gap-8 px-4 pb-8 lg:pb-4">
|
||||
<div className="pt-12 text-2xl font-bold">{t("words.discover")}</div>
|
||||
<Tabs
|
||||
value={search.get("type") || "search"}
|
||||
onValueChange={(val) => {
|
||||
setSearch(
|
||||
(search) => {
|
||||
search.set("type", val)
|
||||
return new URLSearchParams(search)
|
||||
},
|
||||
{ replace: true },
|
||||
)
|
||||
}}
|
||||
className="w-full"
|
||||
>
|
||||
<ScrollArea.ScrollArea flex orientation="horizontal" rootClassName="w-full">
|
||||
<TabsList className="relative flex w-full">
|
||||
<div className="flex size-full flex-col px-6 py-8">
|
||||
{/* Simple Header */}
|
||||
<div className="mx-auto mb-8 max-w-6xl text-center">
|
||||
<h1 className="text-text mb-4 text-3xl font-bold">{t("words.discover")}</h1>
|
||||
</div>
|
||||
|
||||
<div className="mx-auto w-full max-w-6xl">
|
||||
<Tabs
|
||||
value={search.get("type") || "search"}
|
||||
onValueChange={(val) => {
|
||||
setSearch(
|
||||
(search) => {
|
||||
search.set("type", val)
|
||||
return new URLSearchParams(search)
|
||||
},
|
||||
{ replace: true },
|
||||
)
|
||||
}}
|
||||
className="w-full"
|
||||
>
|
||||
{/* Tab Navigation */}
|
||||
<div className="mb-8">
|
||||
<ScrollArea.ScrollArea flex orientation="horizontal" rootClassName="w-full">
|
||||
<TabsList className="relative flex w-full">
|
||||
{currentTabs.map((tab) => (
|
||||
<TabsTrigger
|
||||
key={tab.name}
|
||||
value={tab.value}
|
||||
className={cn(tab.disabled && "cursor-not-allowed opacity-50")}
|
||||
onClick={() => {
|
||||
if (tab.disabled) {
|
||||
presentActivationModal()
|
||||
}
|
||||
}}
|
||||
>
|
||||
{t(tab.name)}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
</ScrollArea.ScrollArea>
|
||||
</div>
|
||||
|
||||
{/* Tab Content */}
|
||||
<div className="space-y-8">
|
||||
{currentTabs.map((tab) => (
|
||||
<TabsTrigger
|
||||
key={tab.name}
|
||||
value={tab.value}
|
||||
className={cn(tab.disabled && "cursor-not-allowed opacity-50")}
|
||||
onClick={() => {
|
||||
if (tab.disabled) {
|
||||
presentActivationModal()
|
||||
}
|
||||
}}
|
||||
>
|
||||
{t(tab.name)}
|
||||
</TabsTrigger>
|
||||
<TabsContent key={tab.name} value={tab.value} className="mt-0">
|
||||
<div className={tab.value === "inbox" ? "" : "flex flex-col items-center"}>
|
||||
{createElement(TabComponent[tab.value]! || TabComponent.default, {
|
||||
type: tab.value,
|
||||
})}
|
||||
</div>
|
||||
</TabsContent>
|
||||
))}
|
||||
</TabsList>
|
||||
</ScrollArea.ScrollArea>
|
||||
{currentTabs.map((tab) => (
|
||||
<TabsContent key={tab.name} value={tab.value} className="mt-8">
|
||||
<div className={tab.value === "inbox" ? "" : "center flex flex-col"}>
|
||||
{createElement(TabComponent[tab.value]! || TabComponent.default, {
|
||||
type: tab.value,
|
||||
})}
|
||||
</div>
|
||||
</TabsContent>
|
||||
))}
|
||||
</Tabs>
|
||||
<Divider className="w-full max-w-[800px]" />
|
||||
<Trending center />
|
||||
<Divider className="w-full max-w-[800px]" />
|
||||
<AppErrorBoundary errorType={ErrorComponentType.RSSHubDiscoverError}>
|
||||
<Recommendations />
|
||||
</AppErrorBoundary>
|
||||
</div>
|
||||
</Tabs>
|
||||
|
||||
{/* Additional Content Sections */}
|
||||
<div className="mt-12 space-y-8">
|
||||
<Divider />
|
||||
|
||||
<div>
|
||||
<h2 className="text-text mb-6 text-center text-xl font-semibold">Trending</h2>
|
||||
<Trending center />
|
||||
</div>
|
||||
|
||||
<Divider />
|
||||
|
||||
<div>
|
||||
<h2 className="text-text mb-6 text-center text-xl font-semibold">Recommendations</h2>
|
||||
<AppErrorBoundary errorType={ErrorComponentType.RSSHubDiscoverError}>
|
||||
<Recommendations />
|
||||
</AppErrorBoundary>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
<div className="relative flex w-full flex-col items-center gap-8 px-4 pb-8 lg:px-20 lg:pb-4">
|
||||
<div className="center">
|
||||
<img src={RSSHubIcon} className="mt-12 size-20" />
|
||||
</div>
|
||||
<div className="text-2xl font-bold">{t("words.rsshub", { ns: "common" })}</div>
|
||||
<div className="max-w-4xl text-sm">{t("rsshub.description")}</div>
|
||||
<Button
|
||||
onClick={() =>
|
||||
present({
|
||||
title: t("rsshub.add_new_instance"),
|
||||
content: ({ dismiss }) => <AddModalContent dismiss={dismiss} />,
|
||||
})
|
||||
}
|
||||
>
|
||||
<div className="flex items-center gap-1">
|
||||
<i className="i-mgc-add-cute-re mr-1 text-base" />
|
||||
<span>{t("rsshub.add_new_instance")}</span>
|
||||
<div className="flex size-full flex-col px-6 py-8">
|
||||
{/* Simple Header */}
|
||||
<div className="mx-auto mb-8 max-w-6xl text-center">
|
||||
<div className="mb-4 flex justify-center">
|
||||
<img src={RSSHubIcon} className="size-16" alt="RSSHub" />
|
||||
</div>
|
||||
</Button>
|
||||
<div className="text-text-secondary text-sm">{t("rsshub.public_instances")}</div>
|
||||
<List data={list?.data} />
|
||||
<h1 className="text-text mb-4 text-3xl font-bold">{t("words.rsshub", { ns: "common" })}</h1>
|
||||
<p className="text-text-secondary mx-auto max-w-2xl text-sm leading-relaxed">
|
||||
{t("rsshub.description")}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="mx-auto w-full max-w-6xl">
|
||||
{/* Add Instance Section */}
|
||||
<div className="mb-8 flex justify-center">
|
||||
<Button
|
||||
onClick={() =>
|
||||
present({
|
||||
title: t("rsshub.add_new_instance"),
|
||||
content: ({ dismiss }) => <AddModalContent dismiss={dismiss} />,
|
||||
})
|
||||
}
|
||||
>
|
||||
<i className="i-mgc-add-cute-re mr-2 size-4" />
|
||||
<span>{t("rsshub.add_new_instance")}</span>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Instances Section */}
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="text-text text-xl font-semibold">{t("rsshub.public_instances")}</h2>
|
||||
</div>
|
||||
<List data={list?.data} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
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<RSSHubModel>) : (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 ? (
|
||||
<Logo className="size-8" />
|
||||
) : (
|
||||
<UserAvatar
|
||||
userId={instance.ownerUserId}
|
||||
className="h-auto justify-start p-0"
|
||||
avatarClassName="size-8"
|
||||
/>
|
||||
)
|
||||
|
||||
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 && (
|
||||
<span className="bg-accent/10 text-accent rounded px-1.5 py-0.5 text-xs">
|
||||
{t("rsshub.table.official")}
|
||||
</span>
|
||||
)}
|
||||
{isInUse && (
|
||||
<span className="bg-green/10 text-green rounded px-1.5 py-0.5 text-xs">
|
||||
{t("rsshub.table.inuse")}
|
||||
</span>
|
||||
)}
|
||||
{isOwner && (
|
||||
<span className="bg-purple/10 text-purple rounded px-1.5 py-0.5 text-xs">
|
||||
{t("rsshub.table.yours")}
|
||||
</span>
|
||||
)}
|
||||
{hasError && <span className="bg-red/10 text-red rounded px-1.5 py-0.5 text-xs">Error</span>}
|
||||
</>
|
||||
)
|
||||
|
||||
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 (
|
||||
<Table containerClassName="mt-2 overflow-x-auto">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="font-bold" size="sm" />
|
||||
<TableHead className="w-[190px] font-bold" size="sm">
|
||||
{t("rsshub.table.owner")}
|
||||
</TableHead>
|
||||
<TableHead className="font-bold" size="sm">
|
||||
{t("rsshub.table.description")}
|
||||
</TableHead>
|
||||
<TableHead className="w-[120px] text-right font-bold" size="sm">
|
||||
{t("rsshub.table.price")}
|
||||
</TableHead>
|
||||
<TableHead className="w-[100px] text-right font-bold" size="sm">
|
||||
{t("rsshub.table.userCount")}
|
||||
</TableHead>
|
||||
<TableHead className="w-[100px] text-right font-bold" size="sm">
|
||||
{t("rsshub.table.userLimit")}
|
||||
</TableHead>
|
||||
<TableCell className="w-[100px]" size="sm" />
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody className="border-t-[12px] border-transparent [&_td]:!px-3">
|
||||
<TableRow>
|
||||
<TableCell className="text-nowrap font-bold">{t("rsshub.table.official")}</TableCell>
|
||||
<TableCell>
|
||||
<span className="flex items-center gap-2">
|
||||
<Logo className="size-6" />
|
||||
Folo
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell>Folo Built-in RSSHub</TableCell>
|
||||
<TableCell>
|
||||
<span className="flex items-center justify-end gap-1">
|
||||
0 <i className="i-mgc-power text-accent" />
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell className="text-right">*</TableCell>
|
||||
<TableCell className="text-right">{t("rsshub.table.unlimited")}</TableCell>
|
||||
<TableCell>
|
||||
{!status?.data?.usage?.rsshubId && (
|
||||
<Button disabled buttonClassName="shrink-0">
|
||||
{t("rsshub.table.inuse")}
|
||||
<div className={containerClassName}>
|
||||
<div className="mb-3 flex items-start justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
{headerIcon}
|
||||
<div>
|
||||
<h3 className="text-text text-sm font-semibold">{title}</h3>
|
||||
<div className="flex items-center gap-1">{tags}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<div className="flex items-center gap-1 text-sm font-medium">
|
||||
{formatNumber(price ?? 0)} <i className="i-mgc-power text-accent size-3" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p className="text-text-secondary mb-3 line-clamp-1 text-xs">{description}</p>
|
||||
|
||||
<div className="flex items-center justify-between text-xs">
|
||||
<div className="flex gap-4">
|
||||
<div>
|
||||
<span className="text-text-secondary">Users:</span>{" "}
|
||||
<span className="text-text">{String(usersStat)}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-text-secondary">Limit:</span>{" "}
|
||||
<span className="text-text">{String(limitStat)}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-3 flex items-center justify-between">
|
||||
<div className="flex gap-1">
|
||||
{!isOfficial && isOwner && (
|
||||
<>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() =>
|
||||
present({
|
||||
title: t("rsshub.table.edit"),
|
||||
content: ({ dismiss }) => (
|
||||
<AddModalContent dismiss={dismiss} instance={instance as RSSHubModel} />
|
||||
),
|
||||
})
|
||||
}
|
||||
>
|
||||
Edit
|
||||
</Button>
|
||||
)}
|
||||
{!!status?.data?.usage?.rsshubId && (
|
||||
<Button onClick={() => presetTOTPModal({ id: null })}>{t("rsshub.table.use")}</Button>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{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
|
||||
}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={!!instanceUserCountExceptOwner}
|
||||
onClick={() =>
|
||||
present({
|
||||
title: t("rsshub.table.delete.label"),
|
||||
content: ({ dismiss }) => (
|
||||
<ConfirmDeleteModalContent dismiss={dismiss} id={instance.id!} />
|
||||
),
|
||||
})
|
||||
}
|
||||
>
|
||||
Del
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
{isOfficial ? (
|
||||
<div>
|
||||
{isInUse ? (
|
||||
<Button disabled size="sm">
|
||||
{t("rsshub.table.inuse")}
|
||||
</Button>
|
||||
) : (
|
||||
<Button size="sm" onClick={() => presetTOTPModal({ id: null })}>
|
||||
{t("rsshub.table.use")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<SelectInstanceButton instance={instance as RSSHubModel} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
|
||||
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 (
|
||||
<TableRow key={instance.id}>
|
||||
<TableCell className="text-nowrap">
|
||||
{(() => {
|
||||
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(" / ")
|
||||
})()}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<UserAvatar
|
||||
userId={instance.ownerUserId}
|
||||
className="h-auto justify-start p-0"
|
||||
avatarClassName="size-6"
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<EllipsisTextWithTooltip className="line-clamp-2">
|
||||
{instance.description}
|
||||
</EllipsisTextWithTooltip>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<span className="flex items-center justify-end gap-1">
|
||||
{instance.price} <i className="i-mgc-power text-accent" />
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell className="text-right">{instance.userCount}</TableCell>
|
||||
<TableCell className="text-right">
|
||||
{instance.userLimit === null
|
||||
? t("rsshub.table.unlimited")
|
||||
: instance.userLimit > 1
|
||||
? instance.userLimit
|
||||
: t("rsshub.table.private")}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<div className="flex w-max items-center gap-2">
|
||||
<SelectInstanceButton instance={instance} />
|
||||
{me?.id === instance.ownerUserId && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
present({
|
||||
title: t("rsshub.table.edit"),
|
||||
content: ({ dismiss }) => (
|
||||
<AddModalContent dismiss={dismiss} instance={instance} />
|
||||
),
|
||||
})
|
||||
}
|
||||
>
|
||||
{t("rsshub.table.edit")}
|
||||
</Button>
|
||||
)}
|
||||
{me?.id === instance.ownerUserId && (
|
||||
<Button
|
||||
variant="outline"
|
||||
disabled={!!instanceUserCountExceptOwner}
|
||||
onClick={() =>
|
||||
present({
|
||||
title: t("rsshub.table.delete.label"),
|
||||
content: ({ dismiss }) => (
|
||||
<ConfirmDeleteModalContent dismiss={dismiss} id={instance.id} />
|
||||
),
|
||||
})
|
||||
}
|
||||
>
|
||||
{t("rsshub.table.delete.label")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
// 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 (
|
||||
<div className="grid gap-3 sm:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3">
|
||||
{sortedData.map((item) => (
|
||||
<InstanceCard key={item.id} item={item} />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user