-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathGameInfo.tsx
More file actions
190 lines (184 loc) · 6.42 KB
/
GameInfo.tsx
File metadata and controls
190 lines (184 loc) · 6.42 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import { useRef } from 'react'
import { useTour } from 'src/contexts'
import { InstructionsType } from 'src/types'
import { tourConfigs } from 'src/constants/tours'
interface Props {
icon: string
title: string
type: InstructionsType
children: React.ReactNode
currentMaiaModel?: string
setCurrentMaiaModel?: (model: string) => void
MAIA_MODELS?: string[]
showGameListButton?: boolean
onGameListClick?: () => void
streamState?: {
isLive: boolean
isConnected: boolean
error: string | null
gameEnded: boolean
}
mobileActions?: React.ReactNode
embedded?: boolean
}
export const GameInfo: React.FC<Props> = ({
icon,
title,
type,
children,
currentMaiaModel,
setCurrentMaiaModel,
MAIA_MODELS,
showGameListButton,
onGameListClick,
streamState,
mobileActions,
embedded = false,
}: Props) => {
const { startTour } = useTour()
const maiaSelectRef = useRef<HTMLSelectElement | null>(null)
const openMaiaModelPicker = () => {
const select = maiaSelectRef.current as
| (HTMLSelectElement & { showPicker?: () => void })
| null
if (!select) return
select.focus()
if (select.showPicker) {
try {
select.showPicker()
return
} catch {
// Fallback for browsers/event timing that reject showPicker.
}
}
select.click()
}
return (
<div
id="analysis-game-list"
className={
embedded
? 'flex w-full flex-col items-start justify-start gap-1 overflow-hidden border-b border-t border-glass-border bg-transparent px-4 py-2 md:border md:p-3'
: 'flex w-full flex-col items-start justify-start gap-1 overflow-hidden border border-b border-t border-glass-border bg-glass px-4 py-2 backdrop-blur-md md:rounded-md md:border md:p-3'
}
>
<div className="flex w-full items-center justify-between">
<div className="flex items-center justify-start gap-1 md:gap-1.5">
<span className="material-symbols-outlined inline-flex w-4 items-center justify-center text-base md:w-5 md:text-xl">
{icon}
</span>
<div className="flex items-center gap-1">
<h2 className="text-sm font-semibold leading-none md:text-lg">
{title}
</h2>
{currentMaiaModel && setCurrentMaiaModel && (
<div className="flex items-center gap-1 text-xs leading-none md:hidden md:text-sm">
<span>using</span>
<div className="relative inline-flex items-center gap-0.5">
<select
ref={maiaSelectRef}
value={currentMaiaModel}
className="edge-dark-select cursor-pointer appearance-none bg-transparent leading-none focus:outline-none"
onChange={(e) => setCurrentMaiaModel(e.target.value)}
>
{MAIA_MODELS?.map((model) => (
<option value={model} key={model}>
{model.replace('maia_kdd_', 'Maia ')}
</option>
))}
</select>
<button
type="button"
className="material-symbols-outlined -ml-0.5 inline-flex h-4 items-center justify-center self-center align-middle text-sm leading-none"
onMouseDown={(e) => {
e.preventDefault()
openMaiaModelPicker()
}}
onClick={(e) => {
e.preventDefault()
}}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault()
openMaiaModelPicker()
}
}}
aria-label="Change Maia model"
>
arrow_drop_down
</button>
</div>
</div>
)}
</div>
{streamState && (
<div className="flex items-center gap-1.5">
<div
className={`h-2 w-2 rounded-full ${
streamState.isLive
? 'animate-pulse bg-red-500'
: streamState.isConnected
? 'bg-green-500'
: 'bg-gray-500'
}`}
/>
<span className="text-xs font-medium text-secondary">
{streamState.isLive
? 'LIVE'
: streamState.isConnected
? 'Connected'
: streamState.gameEnded
? 'Game Ended'
: streamState.error
? 'Disconnected'
: 'Connecting...'}
</span>
</div>
)}
</div>
<div className="flex items-center gap-2">
{mobileActions}
{showGameListButton && (
<button
type="button"
className="flex items-center gap-1 rounded bg-human-4/30 px-2 py-1 text-xxs text-human-2 duration-200 hover:bg-human-4/50 md:hidden md:text-sm"
onClick={onGameListClick}
>
<span className="material-symbols-outlined text-xxs md:text-sm">
format_list_bulleted
</span>
<span>
Switch <span className="hidden md:inline">Game</span>
</span>
</button>
)}
<button
type="button"
className="material-symbols-outlined text-lg duration-200 hover:text-human-3 focus:outline-none"
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
const tourTypeMap: { [key: string]: keyof typeof tourConfigs } = {
againstMaia: 'play',
handAndBrain: 'handBrain',
analysis: 'analysis',
train: 'train',
turing: 'turing',
}
const tourType = tourTypeMap[type]
if (tourType && tourConfigs[tourType]) {
const tourConfig = tourConfigs[tourType]
startTour(tourConfig.id, tourConfig.steps, true)
}
}}
>
help
</button>
</div>
</div>
<div className="flex w-full flex-col text-sm md:text-base">
{children}
</div>
</div>
)
}