-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.tsx
52 lines (50 loc) · 1.09 KB
/
common.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import Link from "next/link";
import { Game } from "./convex/search";
import { Id } from "./convex/_generated/dataModel";
function getProfileLink(
className: string,
name: string,
id: string | Id<"users"> | null
) {
if (!id) {
return <></>;
}
if (typeof id == "string") {
return <span className={className}>{name}</span>;
} else {
return (
<Link className={className} href={`/user/${id}`}>
{name}
</Link>
);
}
}
export function gameTitle(state: Game) {
const player1Span = getProfileLink(
"whitePlayer",
state.player1Name,
state.player1
);
const player2Span = getProfileLink(
"blackPlayer",
state.player2Name,
state.player2
);
const context = state.resultContext;
if (state.player1Name && state.player2Name) {
return (
<div>
<div>
{player1Span} vs {player2Span}
</div>
{context && <div>{context}</div>}
</div>
);
} else if (state.player1Name) {
return player1Span;
} else if (state.player2Name) {
return player2Span;
} else {
return <div></div>;
}
}