Skip to content

Commit 44cab04

Browse files
Refine practice modal drill queue layout
1 parent 0cb30d5 commit 44cab04

1 file changed

Lines changed: 45 additions & 66 deletions

File tree

src/components/Openings/OpeningSelectionModal.tsx

Lines changed: 45 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ const getMaiaOpponentName = (maiaVersion: string) =>
7474
MAIA3_OPPONENT_RATINGS.find((version) => version.id === maiaVersion)?.name ??
7575
maiaVersion
7676

77-
const getSelectionTitle = (selection: OpeningSelection) =>
78-
selection.opening.name
79-
8077
const getSelectionDetailLine = (selection: OpeningSelection) => {
8178
if (
8279
selection.opening.categoryType === 'endgame' &&
@@ -87,10 +84,6 @@ const getSelectionDetailLine = (selection: OpeningSelection) => {
8784
.join(', ')
8885
}
8986

90-
if (selection.variation?.name) {
91-
return selection.variation.name
92-
}
93-
9487
return selection.opening.categoryType === 'custom' ? 'Custom position' : null
9588
}
9689

@@ -99,6 +92,34 @@ const getSelectionConfigurationTags = (selection: OpeningSelection) => [
9992
selection.playerColor === 'white' ? 'White' : 'Black',
10093
]
10194

95+
const getSelectionConfigurationText = (selection: OpeningSelection) => {
96+
const items = [...getSelectionConfigurationTags(selection)]
97+
98+
if (selection.opening.categoryType === 'endgame') {
99+
items.push(`${selection.endgamePositions?.length ?? 0} positions`)
100+
} else {
101+
items.push(
102+
selection.targetMoveNumber === null
103+
? '∞ moves'
104+
: `${selection.targetMoveNumber} moves`,
105+
)
106+
}
107+
108+
return items.join(' · ')
109+
}
110+
111+
const SelectionTitle: React.FC<{
112+
selection: OpeningSelection
113+
className?: string
114+
}> = ({ selection, className = 'text-[13px]' }) => (
115+
<p className={`truncate ${className}`}>
116+
<span className="font-medium text-white">{selection.opening.name}</span>
117+
{selection.variation && (
118+
<span className="text-white/55">: {selection.variation.name}</span>
119+
)}
120+
</p>
121+
)
122+
102123
interface Props {
103124
openings: Opening[]
104125
endgames?: Opening[]
@@ -1163,11 +1184,9 @@ const DrillStudioPanel: React.FC<{
11631184
) : (
11641185
<div className="grid max-h-48 grid-cols-1 gap-1 overflow-y-auto 2xl:grid-cols-2">
11651186
{selections.map((selection) => {
1166-
const isEndgame =
1167-
selection.opening.categoryType === 'endgame'
11681187
const detailLine = getSelectionDetailLine(selection)
1169-
const configurationTags =
1170-
getSelectionConfigurationTags(selection)
1188+
const configurationText =
1189+
getSelectionConfigurationText(selection)
11711190

11721191
const isActive =
11731192
previewOpening.id === selection.opening.id &&
@@ -1192,30 +1211,15 @@ const DrillStudioPanel: React.FC<{
11921211
}`}
11931212
>
11941213
<div className="min-w-0 flex-1">
1195-
<p className="truncate text-[13px] font-medium text-white">
1196-
{getSelectionTitle(selection)}
1197-
</p>
1214+
<SelectionTitle selection={selection} />
11981215
{detailLine && (
11991216
<p className="truncate text-[11px] text-white/40">
12001217
{detailLine}
12011218
</p>
12021219
)}
1203-
<div className="mt-1 flex flex-wrap gap-1">
1204-
{configurationTags.map((tag) => (
1205-
<span
1206-
key={`${selection.id}-${tag}`}
1207-
className="rounded-full border border-white/10 bg-white/[0.05] px-2 py-0.5 text-[10px] font-medium text-white/60"
1208-
>
1209-
{tag}
1210-
</span>
1211-
))}
1212-
{isEndgame && (
1213-
<span className="rounded-full border border-white/10 bg-white/[0.05] px-2 py-0.5 text-[10px] font-medium text-white/60">
1214-
{selection.endgamePositions?.length ?? 0}{' '}
1215-
positions
1216-
</span>
1217-
)}
1218-
</div>
1220+
<p className="mt-1 truncate text-[10px] text-white/50">
1221+
{configurationText}
1222+
</p>
12191223
</div>
12201224
<button
12211225
onClick={(e) => {
@@ -1303,7 +1307,7 @@ const SelectedPanel: React.FC<{
13031307
const isEndgameSelection =
13041308
getOpeningCategory(selection.opening) === 'endgame'
13051309
const detailLine = getSelectionDetailLine(selection)
1306-
const configurationTags = getSelectionConfigurationTags(selection)
1310+
const configurationText = getSelectionConfigurationText(selection)
13071311

13081312
return (
13091313
<div
@@ -1331,9 +1335,12 @@ const SelectedPanel: React.FC<{
13311335
)}
13321336
<div className="min-w-0 flex-1">
13331337
<div className="flex flex-wrap items-center gap-2">
1334-
<span className="truncate text-xs font-medium text-primary md:text-sm">
1335-
{getSelectionTitle(selection)}
1336-
</span>
1338+
<div className="min-w-0">
1339+
<SelectionTitle
1340+
selection={selection}
1341+
className="text-xs md:text-sm"
1342+
/>
1343+
</div>
13371344
{selection.opening.isCustom && (
13381345
<span className="rounded border border-human-4/40 bg-human-4/10 px-2 py-0.5 text-xxs font-semibold uppercase tracking-wide text-human-2">
13391346
Custom
@@ -1343,24 +1350,9 @@ const SelectedPanel: React.FC<{
13431350
{detailLine && (
13441351
<p className="text-xs text-white/70">{detailLine}</p>
13451352
)}
1346-
<div className="mt-1 flex flex-wrap gap-1">
1347-
{configurationTags.map((tag) => (
1348-
<span
1349-
key={`${selection.id}-${tag}`}
1350-
className="rounded-full border border-white/10 bg-white/[0.05] px-2 py-0.5 text-[10px] font-medium text-white/60"
1351-
>
1352-
{tag}
1353-
</span>
1354-
))}
1355-
{isEndgameSelection && (
1356-
<span className="rounded-full border border-white/10 bg-white/[0.05] px-2 py-0.5 text-[10px] font-medium text-white/60">
1357-
{(
1358-
selection.endgamePositions?.length ?? 0
1359-
).toLocaleString()}{' '}
1360-
positions
1361-
</span>
1362-
)}
1363-
</div>
1353+
<p className="mt-1 text-xxs text-secondary">
1354+
{configurationText}
1355+
</p>
13641356
</div>
13651357
</div>
13661358
</div>
@@ -2076,20 +2068,6 @@ export const OpeningSelectionModal: React.FC<Props> = ({
20762068
}
20772069
}, [hasTrackedModalOpen, initialSelections.length])
20782070

2079-
// Update the ID to reflect the new settings
2080-
useEffect(() => {
2081-
setSelections((prevSelections) =>
2082-
prevSelections.map((selection) => ({
2083-
...selection,
2084-
maiaVersion: selectedMaiaVersion.id,
2085-
targetMoveNumber:
2086-
getOpeningCategory(selection.opening) === 'endgame'
2087-
? null
2088-
: targetMoveNumber,
2089-
})),
2090-
)
2091-
}, [selectedMaiaVersion.id, targetMoveNumber])
2092-
20932071
const handleStartTour = () => {
20942072
startTour(tourConfigs.openingDrill.id, tourConfigs.openingDrill.steps, true)
20952073
}
@@ -2664,6 +2642,7 @@ export const OpeningSelectionModal: React.FC<Props> = ({
26642642
setPreviewOpening(selection.opening)
26652643
setPreviewVariation(selection.variation ?? null)
26662644
setSelectedColor(selection.playerColor)
2645+
setTargetMoveNumber(selection.targetMoveNumber)
26672646
const maiaVersion = MAIA3_OPPONENT_RATINGS.find(
26682647
(version) => version.id === selection.maiaVersion,
26692648
)

0 commit comments

Comments
 (0)