|
| 1 | +import Link from "next/link"; |
| 2 | + |
| 3 | +import { |
| 4 | + formatDistanceKm, |
| 5 | + formatDurationSec, |
| 6 | + formatPace, |
| 7 | +} from "@/lib/pace"; |
| 8 | +import type { MemberStats } from "@/lib/members"; |
| 9 | + |
| 10 | +import { PaceChart } from "./PaceChart"; |
| 11 | + |
| 12 | +type Props = { |
| 13 | + stats: MemberStats; |
| 14 | + /** 현재 보고 있는 사람이 본인 페이지인지 (헤더 라벨에만 영향). */ |
| 15 | + isSelf: boolean; |
| 16 | +}; |
| 17 | + |
| 18 | +export function MemberView({ stats, isSelf }: Props) { |
| 19 | + return ( |
| 20 | + <main className="container mx-auto max-w-2xl p-6"> |
| 21 | + <nav className="mb-4 text-xs text-muted-foreground"> |
| 22 | + <Link href="/" className="underline-offset-4 hover:underline"> |
| 23 | + ← 홈 |
| 24 | + </Link> |
| 25 | + <span className="mx-2">·</span> |
| 26 | + <Link |
| 27 | + href="/sessions" |
| 28 | + className="underline-offset-4 hover:underline" |
| 29 | + > |
| 30 | + 아카이브 |
| 31 | + </Link> |
| 32 | + </nav> |
| 33 | + |
| 34 | + <header className="mb-6 flex flex-col gap-1"> |
| 35 | + <h1 className="text-2xl font-bold tracking-tight"> |
| 36 | + {stats.name} |
| 37 | + {stats.role === "ADMIN" && ( |
| 38 | + <span className="ml-2 rounded bg-secondary px-1.5 py-0.5 text-xs"> |
| 39 | + ADMIN |
| 40 | + </span> |
| 41 | + )} |
| 42 | + </h1> |
| 43 | + <p className="text-xs text-muted-foreground"> |
| 44 | + {isSelf ? "내 기록" : "러너 기록"} · 가입{" "} |
| 45 | + {new Intl.DateTimeFormat("ko-KR", { |
| 46 | + year: "numeric", |
| 47 | + month: "2-digit", |
| 48 | + day: "2-digit", |
| 49 | + }).format(stats.joinedAt)} |
| 50 | + </p> |
| 51 | + </header> |
| 52 | + |
| 53 | + <section className="mb-8 grid grid-cols-3 gap-3"> |
| 54 | + <Kpi |
| 55 | + label="누적 거리" |
| 56 | + value={ |
| 57 | + stats.totalDistanceKm > 0 |
| 58 | + ? `${stats.totalDistanceKm.toFixed(1)} km` |
| 59 | + : "—" |
| 60 | + } |
| 61 | + /> |
| 62 | + <Kpi label="참여 횟수" value={`${stats.participationCount} 회`} /> |
| 63 | + <Kpi |
| 64 | + label="평균 페이스" |
| 65 | + value={formatPace(stats.avgPaceSecPerKm)} |
| 66 | + mono |
| 67 | + /> |
| 68 | + </section> |
| 69 | + |
| 70 | + <section className="mb-8 flex flex-col gap-3 rounded-md border p-4"> |
| 71 | + <header className="flex items-baseline justify-between"> |
| 72 | + <h2 className="text-sm font-semibold uppercase text-muted-foreground"> |
| 73 | + 최근 페이스 추이 |
| 74 | + </h2> |
| 75 | + {stats.paceHistory.length > 0 && ( |
| 76 | + <span className="text-xs text-muted-foreground"> |
| 77 | + 최근 {stats.paceHistory.length} 개 |
| 78 | + </span> |
| 79 | + )} |
| 80 | + </header> |
| 81 | + <PaceChart points={stats.paceHistory} /> |
| 82 | + </section> |
| 83 | + |
| 84 | + <section className="flex flex-col gap-3"> |
| 85 | + <h2 className="text-sm font-semibold uppercase text-muted-foreground"> |
| 86 | + 최근 참여 ({stats.recent.length}) |
| 87 | + </h2> |
| 88 | + {stats.recent.length === 0 ? ( |
| 89 | + <p className="rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground"> |
| 90 | + 아직 참여한 세션이 없어요. |
| 91 | + </p> |
| 92 | + ) : ( |
| 93 | + <ul className="flex flex-col divide-y rounded-md border"> |
| 94 | + {stats.recent.map((r) => ( |
| 95 | + <li |
| 96 | + key={`${r.sessionId}-${r.date.toISOString()}`} |
| 97 | + className="flex flex-col gap-1 p-3 sm:flex-row sm:items-center sm:justify-between" |
| 98 | + > |
| 99 | + <Link |
| 100 | + href={`/sessions/${r.sessionId}`} |
| 101 | + className="flex flex-col gap-0.5" |
| 102 | + > |
| 103 | + <span className="text-sm font-medium"> |
| 104 | + {new Intl.DateTimeFormat("ko-KR", { |
| 105 | + year: "numeric", |
| 106 | + month: "2-digit", |
| 107 | + day: "2-digit", |
| 108 | + }).format(r.date)} |
| 109 | + </span> |
| 110 | + <span className="text-xs text-muted-foreground"> |
| 111 | + {r.location} |
| 112 | + </span> |
| 113 | + </Link> |
| 114 | + <div className="flex flex-wrap items-baseline gap-x-3 gap-y-1 text-xs text-muted-foreground"> |
| 115 | + <span>{formatDistanceKm(r.distanceKm)}</span> |
| 116 | + <span>{formatDurationSec(r.durationSec)}</span> |
| 117 | + <span className="font-mono"> |
| 118 | + {formatPace(r.paceSecPerKm)} |
| 119 | + </span> |
| 120 | + </div> |
| 121 | + </li> |
| 122 | + ))} |
| 123 | + </ul> |
| 124 | + )} |
| 125 | + </section> |
| 126 | + </main> |
| 127 | + ); |
| 128 | +} |
| 129 | + |
| 130 | +function Kpi({ |
| 131 | + label, |
| 132 | + value, |
| 133 | + mono, |
| 134 | +}: { |
| 135 | + label: string; |
| 136 | + value: string; |
| 137 | + mono?: boolean; |
| 138 | +}) { |
| 139 | + return ( |
| 140 | + <div className="flex flex-col gap-1 rounded-md border p-3"> |
| 141 | + <span className="text-xs uppercase text-muted-foreground">{label}</span> |
| 142 | + <span className={`text-lg font-semibold ${mono ? "font-mono" : ""}`}> |
| 143 | + {value} |
| 144 | + </span> |
| 145 | + </div> |
| 146 | + ); |
| 147 | +} |
0 commit comments