Skip to content

Commit a0059e9

Browse files
fix: make base openings selectable in drills
1 parent 22ff9c9 commit a0059e9

1 file changed

Lines changed: 58 additions & 53 deletions

File tree

src/components/Openings/OpeningSelectionModal.tsx

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,23 @@ const BrowsePanel: React.FC<{
758758
</div>
759759
)
760760

761+
const selectBrowseItem = (
762+
opening: Opening,
763+
variation: OpeningVariation | null,
764+
) => {
765+
setPreviewOpening(opening)
766+
setPreviewVariation(variation)
767+
trackOpeningPreviewSelected(
768+
opening.name,
769+
opening.id,
770+
!!variation,
771+
variation?.name,
772+
)
773+
if (isMobile) {
774+
onOpeningClick(opening, variation)
775+
}
776+
}
777+
761778
return (
762779
<div
763780
id="opening-drill-browse"
@@ -819,7 +836,6 @@ const BrowsePanel: React.FC<{
819836
category.openings.map((opening) => {
820837
const openingIsBeingPreviewed =
821838
previewOpening.id === opening.id && !previewVariation
822-
const showStandaloneOpening = opening.variations.length === 0
823839
const isCollapsed = searchTerm
824840
? false
825841
: collapsedOpenings.has(opening.id)
@@ -828,30 +844,51 @@ const BrowsePanel: React.FC<{
828844
return (
829845
<div key={opening.id} className="px-3 pb-0.5 pt-2.5">
830846
<div
831-
className={`flex items-start gap-1.5 rounded-md px-2 py-1.5 transition-colors ${hasVariations ? 'cursor-pointer hover:bg-white/[0.03]' : ''}`}
832-
onClick={() => {
833-
if (hasVariations) toggleCollapse(opening.id)
847+
role="button"
848+
tabIndex={0}
849+
className={`flex items-start gap-1.5 rounded-md px-2 py-1.5 transition-colors ${
850+
openingIsBeingPreviewed
851+
? 'bg-white/[0.05]'
852+
: 'cursor-pointer hover:bg-white/[0.03]'
853+
}`}
854+
onClick={() => selectBrowseItem(opening, null)}
855+
onKeyDown={(e) => {
856+
if (e.key === 'Enter' || e.key === ' ') {
857+
selectBrowseItem(opening, null)
858+
}
834859
}}
835-
role={hasVariations ? 'button' : undefined}
836-
tabIndex={hasVariations ? 0 : undefined}
837-
onKeyDown={
838-
hasVariations
839-
? (e) => {
840-
if (e.key === 'Enter' || e.key === ' ')
841-
toggleCollapse(opening.id)
842-
}
843-
: undefined
844-
}
845860
>
846-
{hasVariations && (
847-
<span
848-
className={`material-symbols-outlined mt-0.5 !text-[15px] text-white/30 transition-transform ${isCollapsed ? '-rotate-90' : ''}`}
861+
{hasVariations ? (
862+
<button
863+
type="button"
864+
aria-label={
865+
isCollapsed
866+
? `Expand ${opening.name} variations`
867+
: `Collapse ${opening.name} variations`
868+
}
869+
className="mt-0.5 rounded p-0.5 text-white/30 transition-colors hover:bg-white/[0.05] hover:text-white/60"
870+
onClick={(e) => {
871+
e.stopPropagation()
872+
toggleCollapse(opening.id)
873+
}}
849874
>
850-
expand_more
851-
</span>
875+
<span
876+
className={`material-symbols-outlined !text-[15px] transition-transform ${isCollapsed ? '-rotate-90' : ''}`}
877+
>
878+
expand_more
879+
</span>
880+
</button>
881+
) : (
882+
<span className="mt-0.5 w-[23px] flex-shrink-0" />
852883
)}
853884
<div className="min-w-0 flex-1">
854-
<p className="text-[12px] font-semibold uppercase tracking-[0.04em] text-white/40">
885+
<p
886+
className={`text-[12px] font-semibold uppercase tracking-[0.04em] ${
887+
openingIsBeingPreviewed
888+
? 'text-white'
889+
: 'text-white/40'
890+
}`}
891+
>
855892
{opening.name}
856893
</p>
857894
{opening.pgn && hasVariations && (
@@ -869,26 +906,6 @@ const BrowsePanel: React.FC<{
869906

870907
{!isCollapsed && (
871908
<div className="pl-5">
872-
{showStandaloneOpening
873-
? renderRow(
874-
opening.name,
875-
opening.pgn,
876-
openingIsBeingPreviewed,
877-
() => {
878-
setPreviewOpening(opening)
879-
setPreviewVariation(null)
880-
trackOpeningPreviewSelected(
881-
opening.name,
882-
opening.id,
883-
false,
884-
)
885-
if (isMobile) {
886-
onOpeningClick(opening, null)
887-
}
888-
},
889-
)
890-
: null}
891-
892909
{opening.variations.map((variation) => {
893910
const variationIsBeingPreviewed =
894911
previewOpening.id === opening.id &&
@@ -919,19 +936,7 @@ const BrowsePanel: React.FC<{
919936
return `${moveNum}. ...${suffix}`
920937
})(),
921938
variationIsBeingPreviewed,
922-
() => {
923-
setPreviewOpening(opening)
924-
setPreviewVariation(variation)
925-
trackOpeningPreviewSelected(
926-
opening.name,
927-
opening.id,
928-
true,
929-
variation.name,
930-
)
931-
if (isMobile) {
932-
onOpeningClick(opening, variation)
933-
}
934-
},
939+
() => selectBrowseItem(opening, variation),
935940
)}
936941
</React.Fragment>
937942
)

0 commit comments

Comments
 (0)