2026-04-15 17:02:00 -07:00
|
|
|
"use client";
|
|
|
|
|
|
2026-05-02 03:32:05 +05:30
|
|
|
import { useQuery } from "@rocicorp/zero/react";
|
2026-04-15 17:02:00 -07:00
|
|
|
import { Progress } from "@/components/ui/progress";
|
|
|
|
|
import { useIsAnonymous } from "@/contexts/anonymous-mode";
|
2026-05-02 03:32:05 +05:30
|
|
|
import { queries } from "@/zero/queries";
|
2026-04-15 17:02:00 -07:00
|
|
|
|
|
|
|
|
export function PremiumTokenUsageDisplay() {
|
|
|
|
|
const isAnonymous = useIsAnonymous();
|
2026-05-02 03:32:05 +05:30
|
|
|
const [me] = useQuery(queries.user.me({}));
|
2026-04-15 17:02:00 -07:00
|
|
|
|
2026-05-02 03:32:05 +05:30
|
|
|
if (isAnonymous || !me) return null;
|
2026-04-15 17:02:00 -07:00
|
|
|
|
|
|
|
|
const usagePercentage = Math.min(
|
2026-05-02 03:32:05 +05:30
|
|
|
(me.premiumTokensUsed / Math.max(me.premiumTokensLimit, 1)) * 100,
|
2026-04-15 17:02:00 -07:00
|
|
|
100
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const formatTokens = (n: number) => {
|
|
|
|
|
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;
|
|
|
|
|
if (n >= 1_000) return `${(n / 1_000).toFixed(0)}K`;
|
|
|
|
|
return n.toLocaleString();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="space-y-1.5">
|
|
|
|
|
<div className="flex justify-between items-center text-xs">
|
|
|
|
|
<span className="text-muted-foreground">
|
2026-05-02 03:32:05 +05:30
|
|
|
{formatTokens(me.premiumTokensUsed)} / {formatTokens(me.premiumTokensLimit)} tokens
|
2026-04-15 17:02:00 -07:00
|
|
|
</span>
|
|
|
|
|
<span className="font-medium">{usagePercentage.toFixed(0)}%</span>
|
|
|
|
|
</div>
|
|
|
|
|
<Progress value={usagePercentage} className="h-1.5 [&>div]:bg-purple-500" />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|