Skip to content

Commit d879116

Browse files
Adjust desktop analysis sidebar layout
1 parent 57338a6 commit d879116

3 files changed

Lines changed: 72 additions & 99 deletions

File tree

src/components/Analysis/AnalysisSidebar.tsx

Lines changed: 11 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ import { motion } from 'framer-motion'
1010
import type { DrawShape } from 'chessground/draw'
1111
import { Dispatch, SetStateAction, useCallback, useMemo } from 'react'
1212
import type { ComponentProps, CSSProperties, ReactNode } from 'react'
13-
import { useLocalStorage } from 'src/hooks'
1413
import { useAnalysisController } from 'src/hooks/useAnalysisController'
1514
import type { MaiaEvaluation, StockfishEvaluation } from 'src/types'
16-
17-
type AnalysisViewMode = 'simple' | 'detailed'
1815
type HighlightBoardDescription = ComponentProps<
1916
typeof Highlight
2017
>['boardDescription']
@@ -87,17 +84,8 @@ export const AnalysisSidebar: React.FC<Props> = ({
8784
)
8885

8986
const mockHover = useCallback(() => void 0, [])
90-
const mockSetHoverArrow = useCallback(() => void 0, [])
9187
const mockMakeMove = useCallback(() => void 0, [])
9288

93-
const [analysisViewMode, setAnalysisViewMode] =
94-
useLocalStorage<AnalysisViewMode>('maia-analysis-view-mode', 'simple')
95-
const isSimplifiedView = analysisViewMode !== 'detailed'
96-
97-
const handleToggleViewMode = useCallback(() => {
98-
setAnalysisViewMode(isSimplifiedView ? 'detailed' : 'simple')
99-
}, [isSimplifiedView, setAnalysisViewMode])
100-
10189
const highlightMoveEvaluation = analysisEnabled
10290
? (controller.moveEvaluation as {
10391
maia?: MaiaEvaluation
@@ -132,7 +120,7 @@ export const AnalysisSidebar: React.FC<Props> = ({
132120
colorSanMapping: analysisEnabled ? controller.colorSanMapping : {},
133121
boardDescription: highlightBoardDescription,
134122
currentNode: controller.currentNode ?? undefined,
135-
simplified: isSimplifiedView,
123+
simplified: false,
136124
hideStockfishEvalSummary: hideDetailedBlunderMeter,
137125
hideWhiteWinRateSummary: hideDetailedBlunderMeter,
138126
}
@@ -155,7 +143,7 @@ export const AnalysisSidebar: React.FC<Props> = ({
155143
const moveMapProps = {
156144
moveMap: analysisEnabled ? controller.moveMap : undefined,
157145
colorSanMapping: analysisEnabled ? controller.colorSanMapping : {},
158-
setHoverArrow: analysisEnabled ? setHoverArrow : mockSetHoverArrow,
146+
setHoverArrow,
159147
makeMove: analysisEnabled ? makeMove : mockMakeMove,
160148
playerToMove: analysisEnabled ? (controller.currentNode?.turn ?? 'w') : 'w',
161149
}
@@ -183,9 +171,6 @@ export const AnalysisSidebar: React.FC<Props> = ({
183171
? 'flex items-center gap-1 rounded-md border border-glass-border bg-glass px-2 py-1 text-xs transition-colors hover:bg-glass-stronger'
184172
: 'flex items-center gap-1 rounded-md border border-glass-border bg-glass px-2 py-1 text-xs transition-colors'
185173

186-
const viewButtonClass = `${buttonBase} ${
187-
isSimplifiedView ? 'text-white' : 'text-white/80'
188-
}`
189174
const visibilityButtonClass = `${buttonBase} ${
190175
analysisEnabled ? 'text-white' : 'text-white/80'
191176
}`
@@ -207,19 +192,6 @@ export const AnalysisSidebar: React.FC<Props> = ({
207192
</h3>
208193
</div>
209194
<div className="flex items-center gap-2">
210-
<button
211-
type="button"
212-
onClick={handleToggleViewMode}
213-
className={viewButtonClass}
214-
aria-pressed={isSimplifiedView}
215-
>
216-
<span className="material-symbols-outlined !text-xs text-white/80">
217-
{isSimplifiedView ? 'expand_all' : 'collapse_all'}
218-
</span>
219-
<span className="text-white/90">
220-
{isSimplifiedView ? 'Expand' : 'Collapse'}
221-
</span>
222-
</button>
223195
<button
224196
type="button"
225197
onClick={handleToggleAnalysis}
@@ -263,45 +235,6 @@ export const AnalysisSidebar: React.FC<Props> = ({
263235
)
264236
}
265237

266-
const simplifiedLayout = (
267-
<>
268-
<div className="hidden xl:flex xl:flex-col xl:gap-3">
269-
<div className="relative flex h-full flex-col overflow-hidden rounded-md border border-glass-border bg-glass-strong backdrop-blur-md">
270-
{renderHeader('desktop')}
271-
<div className="flex h-full w-full flex-1">
272-
<SimplifiedAnalysisOverview
273-
highlightProps={highlightProps}
274-
blunderMeterProps={simplifiedBlunderMeterProps}
275-
analysisEnabled={analysisEnabled}
276-
hideBlunderMeter={hideDetailedBlunderMeter}
277-
/>
278-
</div>
279-
{!analysisEnabled &&
280-
renderDisabledOverlay('Enable analysis to see move evaluations', {
281-
offsetTop: true,
282-
})}
283-
</div>
284-
</div>
285-
<div className="flex h-full flex-col gap-3 xl:hidden">
286-
<div className="relative flex overflow-hidden rounded-md border border-glass-border bg-glass-strong pt-10 backdrop-blur-md">
287-
{renderHeader('mobile', 'absolute left-0 top-0 z-10 w-full')}
288-
<div className="flex h-full w-full flex-col gap-3 p-3">
289-
<SimplifiedAnalysisOverview
290-
highlightProps={highlightProps}
291-
blunderMeterProps={simplifiedBlunderMeterProps}
292-
analysisEnabled={analysisEnabled}
293-
hideBlunderMeter={hideDetailedBlunderMeter}
294-
/>
295-
</div>
296-
{!analysisEnabled &&
297-
renderDisabledOverlay('Enable analysis to see move evaluations', {
298-
offsetTop: true,
299-
})}
300-
</div>
301-
</div>
302-
</>
303-
)
304-
305238
const detailedLayout = (
306239
<>
307240
<div className="hidden xl:flex xl:h-full xl:flex-col xl:gap-3">
@@ -312,12 +245,12 @@ export const AnalysisSidebar: React.FC<Props> = ({
312245
<div className="flex h-full w-full flex-col overflow-hidden rounded-md border border-glass-border bg-glass-strong backdrop-blur-md">
313246
{renderHeader('desktop')}
314247
<div className="flex h-full w-full flex-1">
315-
<div className="flex h-full w-auto min-w-[40%] max-w-[40%] border-r border-glass-border">
316-
<Highlight {...highlightProps} />
317-
</div>
318-
<div className="flex h-full w-full">
319-
<MovesByRating {...movesByRatingProps} />
320-
</div>
248+
<SimplifiedAnalysisOverview
249+
highlightProps={{ ...highlightProps, simplified: true }}
250+
blunderMeterProps={simplifiedBlunderMeterProps}
251+
analysisEnabled={analysisEnabled}
252+
hideBlunderMeter={hideDetailedBlunderMeter}
253+
/>
321254
</div>
322255
</div>
323256
{!analysisEnabled &&
@@ -330,8 +263,8 @@ export const AnalysisSidebar: React.FC<Props> = ({
330263
className="desktop-analysis-big-row-2-container relative flex flex-row gap-3"
331264
style={{ height: `calc((${desktopContentHeightCss} - 0.75rem) / 2)` }}
332265
>
333-
<div className="flex h-full w-full flex-col">
334-
<MoveMap {...moveMapProps} />
266+
<div className="relative flex h-full w-full flex-col overflow-hidden rounded-md border border-glass-border bg-glass backdrop-blur-md">
267+
<MovesByRating {...movesByRatingProps} />
335268
</div>
336269
{!hideDetailedBlunderMeter && <BlunderMeter {...blunderMeterProps} />}
337270
{!analysisEnabled &&
@@ -384,9 +317,7 @@ export const AnalysisSidebar: React.FC<Props> = ({
384317
className="desktop-right-column-container flex flex-col gap-3"
385318
style={{ willChange: 'transform, opacity', ...containerStyle }}
386319
>
387-
<div className="min-h-0 flex-1">
388-
{isSimplifiedView ? simplifiedLayout : detailedLayout}
389-
</div>
320+
<div className="min-h-0 flex-1">{detailedLayout}</div>
390321
{footerContent ? <div className="shrink-0">{footerContent}</div> : null}
391322
</motion.div>
392323
)

src/components/Analysis/Highlight.tsx

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,13 @@ export const Highlight: React.FC<Props> = ({
354354
}
355355
}, [boardDescription?.segments?.length])
356356

357-
const useCompactMobileColumnTitles = isMobile && !simplified
357+
const useCompactMobileColumnTitles = isMobile || simplified
358358
const mobileMaiaColumnTitle = `Maia ${currentMaiaModel.slice(-4)}: Human Moves`
359359
const mobileStockfishColumnTitle = 'SF 17: Engine Moves'
360+
const compactTitleRowClass = 'grid h-11 place-items-center'
361+
const splitTitleRowClass = 'grid h-12 place-items-center'
362+
const compactTitleTextClass = 'text-sm font-semibold leading-none'
363+
const splitTitleTextClass = 'text-sm font-semibold leading-none md:text-xxs lg:text-xs'
360364
const stockfishDepth = moveEvaluation?.stockfish?.depth
361365
const stockfishDepthLabel = stockfishDepth ? `d${stockfishDepth}` : null
362366
const openMaiaHeaderPicker = () => {
@@ -387,23 +391,39 @@ export const Highlight: React.FC<Props> = ({
387391
simplified ? 'grid-cols-1' : ''
388392
}`}
389393
>
390-
<div className="flex flex-col items-center justify-start gap-0.5 border-r border-glass-border xl:gap-1">
391-
<div className="relative flex w-full flex-col border-b border-white/5">
394+
<div
395+
className={`flex flex-col items-center justify-start border-r border-glass-border ${
396+
simplified ? 'gap-0' : 'gap-0.5 xl:gap-1'
397+
}`}
398+
>
399+
<div
400+
className={`relative w-full border-b border-white/5 ${
401+
useCompactMobileColumnTitles ? compactTitleRowClass : splitTitleRowClass
402+
}`}
403+
>
392404
{isHomePage ? (
393-
<div className="py-2 text-center text-sm font-semibold text-human-1 md:text-xxs lg:text-xs">
405+
<div
406+
className={`text-center text-human-1 ${
407+
useCompactMobileColumnTitles
408+
? compactTitleTextClass
409+
: splitTitleTextClass
410+
}`}
411+
>
394412
{useCompactMobileColumnTitles
395413
? mobileMaiaColumnTitle
396414
: `Maia ${currentMaiaModel.slice(-4)}`}
397415
</div>
398416
) : (
399417
<>
400418
{useCompactMobileColumnTitles ? (
401-
<div className="flex items-center justify-center py-2 pr-4 text-sm font-semibold text-human-1">
419+
<div
420+
className={`flex items-center justify-center pr-4 text-human-1 ${compactTitleTextClass}`}
421+
>
402422
<select
403423
ref={maiaHeaderSelectRef}
404424
value={currentMaiaModel}
405425
onChange={(e) => setCurrentMaiaModel(e.target.value)}
406-
className="cursor-pointer appearance-none bg-transparent text-center outline-none transition-colors duration-200 hover:text-human-1/80"
426+
className="pointer-events-none absolute inset-0 h-full w-full appearance-none opacity-0"
407427
>
408428
{MAIA_MODELS.map((model) => (
409429
<option
@@ -415,16 +435,16 @@ export const Highlight: React.FC<Props> = ({
415435
</option>
416436
))}
417437
</select>
418-
<span className="ml-0.5 whitespace-nowrap">
419-
: Human Moves
438+
<span className="whitespace-nowrap leading-none">
439+
{mobileMaiaColumnTitle}
420440
</span>
421441
</div>
422442
) : (
423443
<select
424444
ref={maiaHeaderSelectRef}
425445
value={currentMaiaModel}
426446
onChange={(e) => setCurrentMaiaModel(e.target.value)}
427-
className="cursor-pointer appearance-none bg-transparent py-2 text-center text-sm font-semibold text-human-1 outline-none transition-colors duration-200 hover:text-human-1/80 md:text-xxs lg:text-xs"
447+
className={`cursor-pointer appearance-none bg-transparent text-center ${splitTitleTextClass} text-human-1 outline-none transition-colors duration-200 hover:text-human-1/80`}
428448
>
429449
{MAIA_MODELS.map((model) => (
430450
<option
@@ -473,11 +493,15 @@ export const Highlight: React.FC<Props> = ({
473493
)}
474494

475495
<div
476-
className={`flex w-full flex-col items-start justify-center md:items-center ${simplified ? 'p-3' : 'px-2 py-1.5 xl:py-2'}`}
496+
className={`flex w-full flex-col items-start justify-start md:items-center ${
497+
simplified ? 'px-3 pb-2 pt-1.5' : 'px-2 py-1.5 xl:py-2'
498+
}`}
477499
>
478500
{!useCompactMobileColumnTitles && (
479501
<p
480-
className={`mb-1 whitespace-nowrap text-sm font-semibold text-human-2 ${simplified ? 'text-sm' : 'md:text-xxs lg:text-xs'}`}
502+
className={`whitespace-nowrap text-sm font-semibold text-human-2 ${
503+
simplified ? 'mb-0.5 text-sm leading-tight' : 'mb-1 md:text-xxs lg:text-xs'
504+
}`}
481505
>
482506
Human Moves
483507
</p>
@@ -524,16 +548,30 @@ export const Highlight: React.FC<Props> = ({
524548
})}
525549
</div>
526550
</div>
527-
<div className="flex flex-col items-center justify-start gap-0.5 xl:gap-1">
528-
<div className="flex w-full flex-col border-b border-white/5 py-2">
529-
<p className="flex items-baseline justify-center gap-1 whitespace-nowrap text-center text-sm font-semibold text-engine-1 md:text-xxs lg:text-xs">
530-
<span>
551+
<div
552+
className={`flex flex-col items-center justify-start ${
553+
simplified ? 'gap-0' : 'gap-0.5 xl:gap-1'
554+
}`}
555+
>
556+
<div
557+
className={`w-full border-b border-white/5 ${
558+
useCompactMobileColumnTitles ? compactTitleRowClass : splitTitleRowClass
559+
}`}
560+
>
561+
<p
562+
className={`flex items-center justify-center gap-1 whitespace-nowrap text-center text-engine-1 ${
563+
useCompactMobileColumnTitles
564+
? compactTitleTextClass
565+
: splitTitleTextClass
566+
}`}
567+
>
568+
<span className="leading-none">
531569
{useCompactMobileColumnTitles
532570
? mobileStockfishColumnTitle
533571
: 'Stockfish 17'}
534572
</span>
535573
{stockfishDepthLabel && (
536-
<span className="text-[10px] font-normal text-engine-2/75 md:text-[9px] lg:text-[10px]">
574+
<span className="leading-none text-[10px] font-normal text-engine-2/75 md:text-[9px] lg:text-[10px]">
537575
{stockfishDepthLabel}
538576
</span>
539577
)}
@@ -554,11 +592,15 @@ export const Highlight: React.FC<Props> = ({
554592
)}
555593

556594
<div
557-
className={`flex w-full flex-col items-start justify-center ${simplified ? 'p-3' : 'px-2 py-1.5 xl:py-2'} md:items-center`}
595+
className={`flex w-full flex-col items-start justify-start md:items-center ${
596+
simplified ? 'px-3 pb-2 pt-1.5' : 'px-2 py-1.5 xl:py-2'
597+
}`}
558598
>
559599
{!useCompactMobileColumnTitles && (
560600
<p
561-
className={`mb-1 whitespace-nowrap text-sm font-semibold text-engine-2 ${simplified ? 'text-sm' : 'md:text-xxs lg:text-xs'}`}
601+
className={`whitespace-nowrap text-sm font-semibold text-engine-2 ${
602+
simplified ? 'mb-0.5 text-sm leading-tight' : 'mb-1 md:text-xxs lg:text-xs'
603+
}`}
562604
>
563605
Engine Moves
564606
</p>

src/pages/analysis/[...id].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ const Analysis: React.FC<Props> = ({
11991199
() => `calc(max(24rem, ${desktopBoardSizeCss}))`,
12001200
[desktopBoardSizeCss],
12011201
)
1202-
const desktopConfigPanelHeightCss = '12.5rem'
1202+
const desktopConfigPanelHeightCss = '9.5rem'
12031203
const desktopSidebarContentHeightCss = `calc(${desktopColumnTargetHeightCss} - ${desktopConfigPanelHeightCss} - 0.75rem)`
12041204
const desktopBarChromeSize: 'compact' | 'expanded' =
12051205
width >= 1360 ? 'expanded' : 'compact'

0 commit comments

Comments
 (0)