Reward users for helping build the app: wiki pages, mission planning markers (queued until the mission completes), surveys, and manual awards. Contribution XP folds into the existing virtual profile total, so it flows into the level ladder, sidebar XP display, dashboard, and profile. - contribution-entries ledger collection + profile progression.contributions.xpEarned bucket - src/lib/contributions service (record/grant/expire/revoke, caps, idempotency, leaderboard) with a pure rules module - per-mission planning-map delegation (missions:update grants) and a completed/cancelled map lock - wiki, survey, and marker action/hook integration - contribution:* event types, muteable notifications, permissions group, event targets - profile Contributions section and /contributions leaderboard - migration, reconcile tool, and integration tests
116 lines
4.1 KiB
TypeScript
116 lines
4.1 KiB
TypeScript
import { ClientDate } from "@/components/frontend/ClientDate";
|
|
import { Item, ItemContent } from "@/components/ui/item";
|
|
import { cn } from "@/lib/utils";
|
|
import { ClockIcon, SparkleIcon } from "lucide-react";
|
|
import type { ContributionSummaryRow } from "@/lib/contributions";
|
|
import { CONTRIBUTION_RULES } from "@/lib/contributions/rules";
|
|
|
|
const STATUS_STYLES: Record<string, string> = {
|
|
granted: "text-emerald-400 border-emerald-500/40",
|
|
queued: "text-amber-400 border-amber-500/40",
|
|
revoked: "text-rose-400 border-rose-500/40",
|
|
expired: "text-muted-foreground border-border",
|
|
};
|
|
|
|
const STATUS_LABELS: Record<string, string> = {
|
|
granted: "Granted",
|
|
queued: "Queued",
|
|
revoked: "Revoked",
|
|
expired: "Expired",
|
|
};
|
|
|
|
/**
|
|
* Granted / queued contribution XP totals plus a recent history list.
|
|
* Server-rendered; the profile page queries the ledger and passes rows in.
|
|
*/
|
|
export function ContributionHistory({
|
|
granted,
|
|
queued,
|
|
rows,
|
|
isOwner,
|
|
}: {
|
|
granted: number;
|
|
queued: number;
|
|
rows: ContributionSummaryRow[];
|
|
isOwner: boolean;
|
|
}) {
|
|
return (
|
|
<div className="flex flex-col gap-3">
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<Item variant="outline" size="sm">
|
|
<ItemContent>
|
|
<span className="text-xs uppercase tracking-wider text-muted-foreground">
|
|
Granted XP
|
|
</span>
|
|
<span className="text-2xl font-bold font-mono text-emerald-400">
|
|
{granted.toLocaleString()}
|
|
</span>
|
|
</ItemContent>
|
|
</Item>
|
|
<Item variant="outline" size="sm">
|
|
<ItemContent>
|
|
<span className="text-xs uppercase tracking-wider text-muted-foreground">
|
|
Queued XP
|
|
</span>
|
|
<span className="text-2xl font-bold font-mono text-amber-400">
|
|
{queued.toLocaleString()}
|
|
</span>
|
|
<span className="text-[10px] text-muted-foreground">
|
|
Granted when the mission completes
|
|
</span>
|
|
</ItemContent>
|
|
</Item>
|
|
</div>
|
|
|
|
{rows.length > 0 ? (
|
|
<div className="border border-border rounded-lg overflow-hidden">
|
|
<ul className="divide-y divide-border/50">
|
|
{rows.map((row) => (
|
|
<li key={row.id} className="flex items-center gap-3 px-4 py-2.5">
|
|
{row.status === "queued" ? (
|
|
<ClockIcon className="size-3.5 shrink-0 text-amber-400" />
|
|
) : (
|
|
<SparkleIcon className="size-3.5 shrink-0 text-muted-foreground" />
|
|
)}
|
|
<div className="min-w-0 flex-1">
|
|
<p className="truncate text-sm">{row.summary}</p>
|
|
<p className="text-[11px] text-muted-foreground">
|
|
{CONTRIBUTION_RULES[row.type]?.label ?? row.type}
|
|
{row.revokedReason ? ` \u00b7 ${row.revokedReason}` : ""}
|
|
</p>
|
|
</div>
|
|
<span className="shrink-0 font-mono text-sm tabular-nums text-emerald-400">
|
|
+{row.points}
|
|
</span>
|
|
<span
|
|
className={cn(
|
|
"shrink-0 rounded-sm border px-1.5 py-0.5 text-[10px] uppercase tracking-wide",
|
|
STATUS_STYLES[row.status] ?? "text-muted-foreground border-border",
|
|
)}
|
|
>
|
|
{STATUS_LABELS[row.status] ?? row.status}
|
|
</span>
|
|
<span className="hidden shrink-0 text-xs text-muted-foreground sm:block">
|
|
<ClientDate
|
|
date={row.grantedAt ?? row.createdAt}
|
|
options={{ month: "short", day: "numeric" }}
|
|
/>
|
|
</span>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
) : (
|
|
<Item variant="muted">
|
|
<ItemContent>
|
|
<p className="text-sm text-muted-foreground italic">
|
|
{isOwner
|
|
? "You have not earned any contribution XP yet. Edit the wiki, help plan a mission, or answer a survey."
|
|
: "No contributions on record yet."}
|
|
</p>
|
|
</ItemContent>
|
|
</Item>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|