-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
534 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/app/(panel)/_components/poekmon-shared/poekmon-shared-account-usage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
"use client"; | ||
|
||
import { cn } from "@/lib/utils"; | ||
import { Progress } from "@/components/ui/progress"; | ||
import StatusLabel from "@/components/custom/status-label"; | ||
import { type PoekmonSharedInstanceData } from "@/schema/service/poekmon-shared.schema"; | ||
import { api } from "@/trpc/react"; | ||
|
||
export default function PoekmonSharedAccountUsage({ | ||
instanceId, | ||
className, | ||
}: { | ||
instanceId: string; | ||
className?: string; | ||
}) { | ||
const accountInfoQuery = api.serviceInstance.getPoekmonSharedAccountInfo.useQuery({ id: instanceId }); | ||
|
||
const getBackgroundColor = (value: number) => { | ||
let color; | ||
if (value < 0.2) { | ||
color = "bg-green-500"; | ||
} else if (value < 0.6) { | ||
color = "bg-yellow-500"; | ||
} else if (value < 0.9) { | ||
color = "bg-orange-500"; | ||
} else { | ||
color = "bg-red-500"; | ||
} | ||
return color; | ||
}; | ||
|
||
let alloment = "n/a"; | ||
let balance = "n/a"; | ||
let percentage = 0; | ||
let message_point_reset_time = "n/a"; | ||
const accountInfo = accountInfoQuery.data; | ||
if (accountInfo !== null && accountInfo !== undefined) { | ||
alloment = accountInfo.message_point_alloment.toString(); | ||
balance = accountInfo.message_point_balance.toString(); | ||
if (accountInfo.message_point_alloment !== 0) { | ||
percentage = 1 - accountInfo.message_point_balance / accountInfo.message_point_alloment; | ||
} | ||
message_point_reset_time = new Date(accountInfo.message_point_reset_time / 1000).toLocaleString(); | ||
} | ||
|
||
return ( | ||
<div className={cn("flex w-full flex-col", className)}> | ||
<span className="text-md my-3 font-semibold">Poe 账号概况</span> | ||
<div className="flex w-full flex-col space-y-2"> | ||
<div className="flex w-full max-w-[500px] flex-row items-center justify-between text-sm"> | ||
<span>积分使用情况</span> | ||
<div className="flex flex-row items-center space-x-2"> | ||
<span> | ||
{balance} / {alloment} | ||
</span> | ||
<Progress | ||
value={Math.min(percentage * 100, 100)} | ||
className={cn("w-[120px] max-w-full md:w-[200px]")} | ||
indicatorClassName={getBackgroundColor(percentage)} | ||
/> | ||
</div> | ||
</div> | ||
<div className="flex w-full max-w-[500px] flex-row items-center justify-between text-sm"> | ||
<span>积分刷新时间</span> | ||
<div className="flex flex-row items-center space-x-2"> | ||
<span>{message_point_reset_time ?? "n/a"}</span> | ||
</div> | ||
</div> | ||
<div className="flex w-full max-w-[500px] flex-row items-center justify-between text-sm"> | ||
<span>订阅状态</span> | ||
<div className="flex flex-row items-center space-x-2"> | ||
<span>{accountInfo?.subscription_active ? "活跃" : "无"}</span> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
71 changes: 71 additions & 0 deletions
71
src/app/(panel)/_components/poekmon-shared/poekmon-shared-statistics.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"use client"; | ||
|
||
import { Icons } from "@/components/icons"; | ||
import { cn } from "@/lib/utils"; | ||
import { api } from "@/trpc/react"; | ||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; | ||
|
||
export function PoekmonSharedInstanceUsageStatistics({ | ||
instanceId, | ||
className, | ||
}: { | ||
instanceId: string; | ||
className?: string; | ||
}) { | ||
const sumResult = api.resourceLog.sumPoekmonSharedResourceLogsInDurationWindowsByInstance.useQuery({ | ||
durationWindows: ["10m", "1h", "8h", "24h"], | ||
instanceId, | ||
}); | ||
|
||
const allLogsAreEmpty = sumResult.data?.every((item) => item.stats.count === 0); | ||
|
||
return ( | ||
<div className={cn("flex flex-col", className)}> | ||
<span className="text-md py-3 font-semibold">最近使用情况</span> | ||
{!allLogsAreEmpty && ( | ||
<div className="flex flex-col space-y-2 text-sm"> | ||
{sumResult.data?.map((item) => ( | ||
<div key={item.durationWindow} className="flex w-full flex-row justify-between"> | ||
<div>Last {item.durationWindow}</div> | ||
<TooltipProvider delayDuration={0}> | ||
<Tooltip> | ||
<TooltipTrigger> | ||
<div className="flex flex-row space-x-2"> | ||
{/* <span>{item.stats.userCount}</span> | ||
<span>{item.stats.count}</span> | ||
<span>{item.stats.sumUtf8Length ?? 0}</span> */} | ||
<div className="flex flex-row items-center"> | ||
{" "} | ||
<Icons.user className="mr-2 h-4 w-4" /> {item.stats.userCount} | ||
</div> | ||
<div className="flex flex-row items-center"> | ||
{" "} | ||
<Icons.message className="mr-2 h-4 w-4" /> {item.stats.count} | ||
</div> | ||
<div className="flex flex-row items-center"> | ||
{" "} | ||
<Icons.fileBarChart className="mr-2 h-4 w-4" /> | ||
{item.stats.sumPoints} | ||
</div> | ||
</div> | ||
</TooltipTrigger> | ||
<TooltipContent side="left"> | ||
<p> | ||
最近 {item.durationWindow}:{item.stats.userCount} 用户使用,请求 {item.stats.count} 次,消耗{" "} | ||
{item.stats.sumPoints} 积分点数 | ||
</p> | ||
</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
</div> | ||
))} | ||
</div> | ||
)} | ||
{allLogsAreEmpty && ( | ||
<div className="mx-auto flex h-[80px] w-full flex-row items-center justify-center align-middle"> | ||
<span className="text-sm text-muted-foreground">No statistics available</span> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.