Skip to content

Commit a8d8693

Browse files
style: better handle responsiveness in opening selection modal
1 parent 3cf141f commit a8d8693

1 file changed

Lines changed: 162 additions & 148 deletions

File tree

src/components/Openings/OpeningSelectionModal.tsx

Lines changed: 162 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ const PreviewPanel: React.FC<{
288288
isDuplicateSelection,
289289
}) => (
290290
<div
291-
className={`flex w-full flex-col ${activeTab !== 'preview' ? 'hidden md:flex' : 'flex'}`}
291+
className={`flex w-full flex-col overflow-hidden ${activeTab !== 'preview' ? 'hidden md:flex' : 'flex'}`}
292292
>
293293
<div className="hidden h-20 flex-col justify-center gap-1 border-b border-white/10 p-4 md:flex">
294294
<h2 className="text-xl font-bold">{previewOpening.name}</h2>
@@ -306,106 +306,112 @@ const PreviewPanel: React.FC<{
306306
</p>
307307
</div>
308308

309-
<div className="flex flex-1 items-center justify-center p-4">
310-
<div className="aspect-square w-full max-w-[280px] md:max-w-[300px]">
311-
<Chessground
312-
contained
313-
config={{
314-
viewOnly: true,
315-
fen: previewFen,
316-
coordinates: true,
317-
animation: { enabled: true, duration: 200 },
318-
}}
319-
/>
309+
{/* Compact content area - no scrolling */}
310+
<div className="flex flex-1 flex-col overflow-hidden">
311+
{/* Compact chessboard section */}
312+
<div className="flex items-center justify-center p-2 md:p-3">
313+
<div className="aspect-square w-full max-w-[180px] md:max-w-[200px]">
314+
<Chessground
315+
contained
316+
config={{
317+
viewOnly: true,
318+
fen: previewFen,
319+
coordinates: true,
320+
animation: { enabled: true, duration: 200 },
321+
}}
322+
/>
323+
</div>
320324
</div>
321-
</div>
322325

323-
{/* Selection Controls */}
324-
<div className="flex flex-col gap-4 border-t border-white/10 p-4">
325-
{/* Color Selection */}
326-
<div>
327-
<p className="mb-2 text-sm font-medium">Play as:</p>
328-
<div className="flex gap-2">
329-
<button
330-
onClick={() => setSelectedColor('white')}
331-
className={`flex items-center gap-2 rounded px-3 py-2 transition-colors ${
332-
selectedColor === 'white'
333-
? 'bg-human-4 text-white'
334-
: 'bg-background-2 hover:bg-background-3'
335-
}`}
336-
>
337-
<div className="relative h-5 w-5">
338-
<Image
339-
src="/assets/pieces/white king.svg"
340-
fill={true}
341-
alt="white king"
342-
/>
343-
</div>
344-
White
345-
</button>
346-
<button
347-
onClick={() => setSelectedColor('black')}
348-
className={`flex items-center gap-2 rounded px-3 py-2 transition-colors ${
349-
selectedColor === 'black'
350-
? 'bg-human-4 text-white'
351-
: 'bg-background-2 hover:bg-background-3'
352-
}`}
326+
{/* Compact configuration options */}
327+
<div className="flex flex-col gap-2 p-2 md:gap-3 md:p-3">
328+
{/* Color Selection */}
329+
<div>
330+
<p className="mb-1 text-xs font-medium md:text-sm">Play as:</p>
331+
<div className="flex gap-2">
332+
<button
333+
onClick={() => setSelectedColor('white')}
334+
className={`flex items-center gap-2 rounded px-2 py-1 text-xs transition-colors md:px-3 md:py-2 md:text-sm ${
335+
selectedColor === 'white'
336+
? 'bg-human-4 text-white'
337+
: 'bg-background-2 hover:bg-background-3'
338+
}`}
339+
>
340+
<div className="relative h-4 w-4 md:h-5 md:w-5">
341+
<Image
342+
src="/assets/pieces/white king.svg"
343+
fill={true}
344+
alt="white king"
345+
/>
346+
</div>
347+
White
348+
</button>
349+
<button
350+
onClick={() => setSelectedColor('black')}
351+
className={`flex items-center gap-2 rounded px-2 py-1 text-xs transition-colors md:px-3 md:py-2 md:text-sm ${
352+
selectedColor === 'black'
353+
? 'bg-human-4 text-white'
354+
: 'bg-background-2 hover:bg-background-3'
355+
}`}
356+
>
357+
<div className="relative h-4 w-4 md:h-5 md:w-5">
358+
<Image
359+
src="/assets/pieces/black king.svg"
360+
fill={true}
361+
alt="black king"
362+
/>
363+
</div>
364+
Black
365+
</button>
366+
</div>
367+
</div>
368+
369+
{/* Maia Version Selection */}
370+
<div>
371+
<p className="mb-1 text-xs font-medium md:text-sm">Opponent:</p>
372+
<select
373+
value={selectedMaiaVersion.id}
374+
onChange={(e) => {
375+
const version = MAIA_VERSIONS.find((v) => v.id === e.target.value)
376+
if (version) {
377+
setSelectedMaiaVersion(version)
378+
}
379+
}}
380+
className="w-full rounded bg-background-2 p-2 text-xs focus:outline-none md:text-sm"
353381
>
354-
<div className="relative h-5 w-5">
355-
<Image
356-
src="/assets/pieces/black king.svg"
357-
fill={true}
358-
alt="black king"
359-
/>
360-
</div>
361-
Black
362-
</button>
382+
{MAIA_VERSIONS.map((version) => (
383+
<option key={version.id} value={version.id}>
384+
{version.name}
385+
</option>
386+
))}
387+
</select>
363388
</div>
364-
</div>
365389

366-
{/* Maia Version Selection */}
367-
<div>
368-
<p className="mb-2 text-sm font-medium">Opponent:</p>
369-
<select
370-
value={selectedMaiaVersion.id}
371-
onChange={(e) => {
372-
const version = MAIA_VERSIONS.find((v) => v.id === e.target.value)
373-
if (version) {
374-
setSelectedMaiaVersion(version)
390+
{/* Move Count Configuration */}
391+
<div>
392+
<p className="mb-1 text-xs font-medium md:text-sm">
393+
Target Move Count: {targetMoveNumber}
394+
</p>
395+
<input
396+
type="range"
397+
min="5"
398+
max="30"
399+
value={targetMoveNumber}
400+
onChange={(e) =>
401+
setTargetMoveNumber(parseInt(e.target.value) || 10)
375402
}
376-
}}
377-
className="w-full rounded bg-background-2 p-2 text-sm focus:outline-none"
378-
>
379-
{MAIA_VERSIONS.map((version) => (
380-
<option key={version.id} value={version.id}>
381-
{version.name}
382-
</option>
383-
))}
384-
</select>
385-
</div>
386-
387-
{/* Move Count Configuration */}
388-
<div>
389-
<p className="mb-2 text-sm font-medium">
390-
Target Move Count: {targetMoveNumber}
391-
</p>
392-
<input
393-
type="range"
394-
min="5"
395-
max="30"
396-
value={targetMoveNumber}
397-
onChange={(e) => setTargetMoveNumber(parseInt(e.target.value) || 10)}
398-
className="w-full accent-human-4"
399-
/>
400-
<div className="mt-1 flex justify-between text-xs text-secondary">
401-
<span>5</span>
402-
<span>30</span>
403+
className="w-full accent-human-4"
404+
/>
405+
<div className="mt-1 flex justify-between text-xs text-secondary">
406+
<span>5</span>
407+
<span>30</span>
408+
</div>
403409
</div>
404-
<p className="mt-1 text-xs text-secondary">
405-
How many moves you want to play in this opening
406-
</p>
407410
</div>
411+
</div>
408412

413+
{/* Fixed button section - always visible */}
414+
<div className="flex-shrink-0 border-t border-white/10 bg-background-1 p-3 md:p-4">
409415
<button
410416
onClick={addSelection}
411417
disabled={isDuplicateSelection(previewOpening, previewVariation)}
@@ -435,7 +441,7 @@ const SelectedPanel: React.FC<{
435441
handleStartDrilling,
436442
}) => (
437443
<div
438-
className={`flex w-full flex-col overflow-y-scroll ${activeTab !== 'selected' ? 'hidden md:flex' : 'flex'} md:border-l md:border-white/10`}
444+
className={`flex w-full flex-col overflow-hidden ${activeTab !== 'selected' ? 'hidden md:flex' : 'flex'} md:border-l md:border-white/10`}
439445
>
440446
<div className="hidden h-20 flex-col justify-center gap-1 border-b border-white/10 p-4 md:flex">
441447
<h2 className="text-xl font-bold">
@@ -450,72 +456,80 @@ const SelectedPanel: React.FC<{
450456
<p className="text-xs text-secondary">Tap to remove</p>
451457
</div>
452458

453-
<div className="red-scrollbar flex flex-1 flex-col items-center justify-start overflow-y-auto">
459+
{/* Compact selections list - with constrained scrolling */}
460+
<div className="flex flex-1 flex-col overflow-hidden">
454461
{selections.length === 0 ? (
455-
<p className="my-auto max-w-xs px-4 text-center text-secondary">
456-
No openings selected yet. Choose openings from the Browse tab to start
457-
drilling.
458-
</p>
462+
<div className="flex flex-1 items-center justify-center">
463+
<p className="max-w-xs px-4 text-center text-xs text-secondary md:text-sm">
464+
No openings selected yet. Choose openings from the Browse tab to
465+
start drilling.
466+
</p>
467+
</div>
459468
) : (
460-
<div className="flex w-full flex-col">
461-
{selections.map((selection) => (
462-
<div
463-
tabIndex={0}
464-
role="button"
465-
key={selection.id}
466-
onKeyDown={(e) => {
467-
if (e.key === 'Enter' || e.key === ' ') {
468-
removeSelection(selection.id)
469-
}
470-
}}
471-
onClick={() => removeSelection(selection.id)}
472-
className="group flex cursor-pointer items-center justify-between border-b border-white/5 p-4 transition-colors hover:bg-human-2/10"
473-
>
474-
<div className="min-w-0 flex-1">
475-
<div className="flex items-center gap-3">
476-
<div className="relative h-5 w-5 flex-shrink-0">
477-
<Image
478-
src={
479-
selection.playerColor === 'white'
480-
? '/assets/pieces/white king.svg'
481-
: '/assets/pieces/black king.svg'
482-
}
483-
fill={true}
484-
alt={`${selection.playerColor} king`}
485-
/>
486-
</div>
487-
<div className="flex min-w-0 flex-1 flex-col">
488-
<span className="truncate text-sm font-medium text-primary">
489-
{selection.opening.name}
490-
</span>
491-
<div className="flex items-center gap-1 text-xs text-secondary">
492-
{selection.variation && (
493-
<span className="truncate">
494-
{selection.variation.name}
495-
</span>
496-
)}
497-
<span>
498-
v. Maia {selection.maiaVersion.replace('maia_kdd_', '')}{' '}
499-
469+
<div className="red-scrollbar flex-1 overflow-y-auto">
470+
<div className="flex w-full flex-col">
471+
{selections.map((selection) => (
472+
<div
473+
tabIndex={0}
474+
role="button"
475+
key={selection.id}
476+
onKeyDown={(e) => {
477+
if (e.key === 'Enter' || e.key === ' ') {
478+
removeSelection(selection.id)
479+
}
480+
}}
481+
onClick={() => removeSelection(selection.id)}
482+
className="group flex cursor-pointer items-center justify-between border-b border-white/5 p-3 transition-colors hover:bg-human-2/10 md:p-4"
483+
>
484+
<div className="min-w-0 flex-1">
485+
<div className="flex items-center gap-3">
486+
<div className="relative h-4 w-4 flex-shrink-0 md:h-5 md:w-5">
487+
<Image
488+
src={
489+
selection.playerColor === 'white'
490+
? '/assets/pieces/white king.svg'
491+
: '/assets/pieces/black king.svg'
492+
}
493+
fill={true}
494+
alt={`${selection.playerColor} king`}
495+
/>
496+
</div>
497+
<div className="flex min-w-0 flex-1 flex-col">
498+
<span className="truncate text-xs font-medium text-primary md:text-sm">
499+
{selection.opening.name}
500500
</span>
501-
<span>{selection.targetMoveNumber} moves</span>
501+
<div className="flex items-center gap-1 text-xs text-secondary">
502+
{selection.variation && (
503+
<span className="truncate">
504+
{selection.variation.name}
505+
</span>
506+
)}
507+
<span>
508+
v. Maia{' '}
509+
{selection.maiaVersion.replace('maia_kdd_', '')}
510+
</span>
511+
<span>{selection.targetMoveNumber} moves</span>
512+
</div>
502513
</div>
503514
</div>
504515
</div>
516+
<button className="ml-2 text-secondary transition-colors group-hover:text-human-4">
517+
<span className="material-symbols-outlined text-sm">
518+
close
519+
</span>
520+
</button>
505521
</div>
506-
<button className="ml-2 text-secondary transition-colors group-hover:text-human-4">
507-
<span className="material-symbols-outlined text-sm">close</span>
508-
</button>
509-
</div>
510-
))}
522+
))}
523+
</div>
511524
</div>
512525
)}
513526
</div>
514527

515-
<div className="border-t border-white/10 p-4">
528+
{/* Fixed button section - always visible */}
529+
<div className="flex-shrink-0 border-t border-white/10 bg-background-1 p-3 md:p-4">
516530
{/* Drill Count Configuration */}
517-
<div className="mb-4">
518-
<p className="mb-2 text-sm font-medium">
531+
<div className="mb-3 md:mb-4">
532+
<p className="mb-1 text-xs font-medium md:mb-2 md:text-sm">
519533
Number of Drills: {drillCount}
520534
</p>
521535
<input
@@ -721,7 +735,7 @@ export const OpeningSelectionModal: React.FC<Props> = ({
721735
/>
722736

723737
{/* Main Content - Responsive Layout */}
724-
<div className="grid w-full flex-1 grid-cols-1 overflow-y-auto md:grid-cols-3">
738+
<div className="grid w-full flex-1 grid-cols-1 overflow-hidden md:grid-cols-3">
725739
<BrowsePanel
726740
activeTab={activeTab}
727741
filteredOpenings={filteredOpenings}

0 commit comments

Comments
 (0)