Merge remote-tracking branch 'origin/codex/ops-weekly-leaderboard-ranking'

This commit is contained in:
2569718930@qq.com
2026-06-09 12:17:26 +08:00
4 changed files with 86 additions and 19 deletions
@@ -0,0 +1,27 @@
import fs from "node:fs";
import path from "node:path";
function assert(condition: unknown, message: string): asserts condition {
if (!condition) throw new Error(message);
}
export function runTests() {
const projectRoot = process.cwd();
const usersPageSource = fs.readFileSync(
path.join(projectRoot, "components", "ops", "users", "UsersPageClient.tsx"),
"utf8",
);
assert(
usersPageSource.includes("leaderboardName") &&
usersPageSource.includes("String(entry.username || \"\").trim()") &&
usersPageSource.includes("TG${entry.telegram_id}"),
"ops users leaderboard must fall back when username is blank",
);
assert(
usersPageSource.includes("本周暂无积分记录") &&
usersPageSource.includes("本周积分") &&
!usersPageSource.includes("entry.username ?? `TG${entry.telegram_id}`"),
"ops users leaderboard must show weekly points clearly and avoid zero-point fake rankings",
);
}
@@ -7,6 +7,13 @@ import { Button } from "@/components/ui/button";
import { opsApi } from "@/lib/ops-api";
import type { OpsUser, LeaderboardEntry } from "@/types/ops";
function leaderboardName(entry: LeaderboardEntry) {
const username = String(entry.username || "").trim();
if (username) return username;
if (entry.telegram_id != null) return `TG${entry.telegram_id}`;
return "未知用户";
}
export function UsersPageClient() {
const [query, setQuery] = useState("");
const [searching, setSearching] = useState(false);
@@ -130,16 +137,16 @@ export function UsersPageClient() {
<CardHeader><CardTitle> Top {leaderboard.length}</CardTitle></CardHeader>
<CardContent>
{leaderboard.length === 0 ? (
<span className="text-slate-500 text-sm"></span>
<span className="text-slate-500 text-sm"></span>
) : (
<ol className="space-y-1">
{leaderboard.map((entry, i) => (
<li key={entry.telegram_id || i} className="flex justify-between text-sm py-1.5 border-b border-white/5">
<span>
<span className="text-slate-500 w-6 inline-block">#{entry.rank ?? i + 1}</span>
<span className="text-white">{entry.username ?? `TG${entry.telegram_id}`}</span>
<span className="text-white">{leaderboardName(entry)}</span>
</span>
<span className="text-cyan-400 font-medium">{entry.weekly_points ?? 0} </span>
<span className="text-cyan-400 font-medium"> {entry.weekly_points ?? 0} </span>
</li>
))}
</ol>