Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(today): make the sidebar sections share the pane height (#108994)

Shy Alter5a2aa71c8ddb
diff --git a/frontend/src/layout/today/TodayPaneSection.tsx b/frontend/src/layout/today/TodayPaneSection.tsx
index 4b76cc1031bc..805542218e48 100644
--- a/frontend/src/layout/today/TodayPaneSection.tsx
+++ b/frontend/src/layout/today/TodayPaneSection.tsx
@@ -1,10 +1,13 @@
-import { ReactNode } from 'react'
+import { ReactNode, RefCallback } from 'react'
import { IconChevronDown, IconChevronRight } from '@posthog/icons'
import { cn } from 'lib/utils/css-classes'
-interface TodayPaneSectionProps {
+import { TodayPaneSectionResizeHandle } from './TodayPaneSectionResizeHandle'
+import { TodaySectionResizer } from './useTodaySectionLayout'
+
+export interface TodayPaneSectionProps {
label: string
open: boolean
count: number
@@ -12,6 +15,11 @@ interface TodayPaneSectionProps {
actions?: JSX.Element | null
divider?: boolean
dataAttr: string
+ height: number
+ animate: boolean
+ resizer?: TodaySectionResizer
+ resizing?: boolean
+ contentRef: RefCallback<HTMLElement>
children: ReactNode
}
@@ -23,12 +31,18 @@ export function TodayPaneSection({
actions,
divider = false,
dataAttr,
+ height,
+ animate,
+ resizer,
+ resizing = false,
+ contentRef,
children,
}: TodayPaneSectionProps): JSX.Element {
const Caret = open ? IconChevronDown : IconChevronRight
return (
<section aria-label={label} className={cn('TodayPaneSection', divider && 'TodayPaneSection--divider')}>
<div className="TodayPaneSection__header">
+ {resizer && <TodayPaneSectionResizeHandle label={label} active={resizing} resizer={resizer} />}
<button
type="button"
className="TodayPaneSection__toggle Today__label"
@@ -42,7 +56,19 @@ export function TodayPaneSection({
</button>
{open && actions && <div className="TodayPaneSection__actions">{actions}</div>}
</div>
- {open && <div className="TodayPaneSection__body">{children}</div>}
+ <div
+ className={cn('TodayPaneSection__viewport', animate && 'TodayPaneSection__viewport--animate')}
+ // eslint-disable-next-line react/forbid-dom-props
+ style={{ height: open ? height : 0 }}
+ >
+ {open && (
+ <div className="TodayPaneSection__scroll">
+ <div ref={contentRef} className="TodayPaneSection__body">
+ {children}
+ </div>
+ </div>
+ )}
+ </div>
</section>
)
}
diff --git a/frontend/src/layout/today/TodayPaneSectionResizeHandle.tsx b/frontend/src/layout/today/TodayPaneSectionResizeHandle.tsx
new file mode 100644
index 000000000000..a03e70182fab
--- /dev/null
+++ b/frontend/src/layout/today/TodayPaneSectionResizeHandle.tsx
@@ -0,0 +1,33 @@
+import { cn } from 'lib/utils/css-classes'
+
+import { TodaySectionResizer } from './useTodaySectionLayout'
+
+interface TodayPaneSectionResizeHandleProps {
+ label: string
+ active: boolean
+ resizer: TodaySectionResizer
+}
+
+export function TodayPaneSectionResizeHandle({
+ label,
+ active,
+ resizer,
+}: TodayPaneSectionResizeHandleProps): JSX.Element {
+ return (
+ <button
+ type="button"
+ className={cn('TodayPaneSection__resize', active && 'TodayPaneSection__resize--active')}
+ aria-label={`Resize ${label}`}
+ title="Drag to resize. Double-click to reset."
+ data-attr="today-section-resize"
+ onPointerDown={resizer.onPointerDown}
+ onPointerMove={resizer.onPointerMove}
+ onPointerUp={resizer.onPointerUp}
+ onPointerCancel={resizer.onPointerUp}
+ onKeyDown={resizer.onKeyDown}
+ onDoubleClick={resizer.onDoubleClick}
+ >
+ <span className="TodayPaneSection__resize-line" />
+ </button>
+ )
+}
diff --git a/frontend/src/layout/today/TodayShell.scss b/frontend/src/layout/today/TodayShell.scss
index e6a70ee0d724..e4584b7aebe0 100644
--- a/frontend/src/layout/today/TodayShell.scss
+++ b/frontend/src/layout/today/TodayShell.scss
@@ -46,6 +46,16 @@
scrollbar-width: thin;
}
+.TodayPane__sections {
+ display: flex;
+ flex: 1 1 auto;
+ flex-direction: column;
+ min-height: 0;
+ padding: 0 4px;
+ margin: 18px 0 8px;
+ overflow: hidden;
+}
+
.TodayPane__heading {
margin: 26px 8px 8px;
letter-spacing: 0.08em;
@@ -53,24 +63,73 @@
.TodayPaneSection {
display: flex;
+ flex: none;
flex-direction: column;
- padding-bottom: 8px;
-
- &:first-child {
- margin-top: 12px;
- }
- &--divider {
+ &--divider > .TodayPaneSection__header {
border-top: 1px solid var(--today-line);
}
}
.TodayPaneSection__header {
+ position: relative;
+ box-sizing: border-box;
display: flex;
+ flex: none;
gap: 4px;
align-items: center;
- height: 32px;
- margin-top: 4px;
+ height: 36px;
+ padding-top: 4px;
+}
+
+.TodayPaneSection__resize {
+ position: absolute;
+ top: -4px;
+ right: 0;
+ left: 0;
+ z-index: 1;
+ display: flex;
+ align-items: center;
+ height: 9px;
+ touch-action: none;
+ cursor: row-resize;
+ outline: none;
+}
+
+.TodayPaneSection__resize-line {
+ width: 100%;
+ height: 2px;
+ background: var(--today-focus-border);
+ border-radius: 1px;
+ opacity: 0;
+ transition: opacity 0.16s;
+
+ .TodayPaneSection__resize:hover &,
+ .TodayPaneSection__resize:focus-visible &,
+ .TodayPaneSection__resize--active & {
+ opacity: 1;
+ }
+}
+
+.TodayPaneSection__viewport {
+ flex: none;
+ min-height: 0;
+ overflow: hidden;
+
+ &--animate {
+ transition: height 0.2s var(--today-ease);
+
+ @media (prefers-reduced-motion: reduce) {
+ transition: none;
+ }
+ }
+}
+
+.TodayPaneSection__scroll {
+ height: 100%;
+ overflow-y: auto;
+ scrollbar-color: var(--today-input-border) transparent;
+ scrollbar-width: thin;
}
.TodayPaneSection__toggle {
@@ -114,6 +173,7 @@
display: flex;
flex-direction: column;
gap: 1px;
+ padding-bottom: 8px;
}
.TodaySpaceFeed {
diff --git a/frontend/src/layout/today/TodaySpacesSidebar.tsx b/frontend/src/layout/today/TodaySpacesSidebar.tsx
index bd33262ed4af..ebcdacaf530a 100644
--- a/frontend/src/layout/today/TodaySpacesSidebar.tsx
+++ b/frontend/src/layout/today/TodaySpacesSidebar.tsx
@@ -10,10 +10,11 @@ import { cn } from 'lib/utils/css-classes'
import { urls } from 'scenes/urls'
import { TodayPaneRow } from './TodayPaneRow'
-import { TodayPaneSection } from './TodayPaneSection'
+import { TodayPaneSection, TodayPaneSectionProps } from './TodayPaneSection'
import { TodaySessionRow } from './TodaySessionRow'
-import { spaceLabel, todaySpacesLogic } from './todaySpacesLogic'
+import { TodayWorkSectionId, spaceLabel, todaySpacesLogic } from './todaySpacesLogic'
import { TodayWorkItem, shortTimeAgo } from './todayWorkItems'
+import { useTodaySectionLayout } from './useTodaySectionLayout'
export function TodaySpacesSidebar(): JSX.Element {
const {
@@ -54,6 +55,27 @@ export function TodaySpacesSidebar(): JSX.Element {
)
const hasPinned = pinnedItems.length > 0
+ const layoutSections: { id: TodayWorkSectionId; open: boolean }[] = [
+ ...(hasPinned ? [{ id: 'pinned' as const, open: !collapsedSections.includes('pinned') }] : []),
+ { id: 'recent', open: !collapsedSections.includes('recent') },
+ { id: 'spaces', open: !collapsedSections.includes('spaces') },
+ ]
+ const layout = useTodaySectionLayout(layoutSections)
+ const sectionLayout = (
+ id: TodayWorkSectionId
+ ): Pick<TodayPaneSectionProps, 'open' | 'height' | 'animate' | 'resizer' | 'resizing' | 'contentRef'> => {
+ const index = layoutSections.findIndex((section) => section.id === id)
+ const section = layoutSections[index]
+ const previous = index > 0 ? layoutSections[index - 1] : null
+ return {
+ open: section.open,
+ height: layout.heights[id],
+ animate: layout.measured && layout.dragging === null,
+ resizer: previous?.open && section.open ? layout.resizer(previous.id, id) : undefined,
+ resizing: layout.dragging === id,
+ contentRef: layout.measureRefs[id],
+ }
+ }
return (
<div className="TodayPane">
@@ -66,11 +88,11 @@ export function TodaySpacesSidebar(): JSX.Element {
<IconPlus />
New chat
</button>
- <div className="TodayPane__scroll">
+ <div className="TodayPane__sections" ref={layout.measureRefs.area}>
{hasPinned && (
<TodayPaneSection
label="Pinned"
- open={!collapsedSections.includes('pinned')}
+ {...sectionLayout('pinned')}
count={pinnedItems.length}
onToggle={() => toggleSection('pinned')}
dataAttr="today-section-pinned"
@@ -80,7 +102,7 @@ export function TodaySpacesSidebar(): JSX.Element {
)}
<TodayPaneSection
label="Recent"
- open={!collapsedSections.includes('recent')}
+ {...sectionLayout('recent')}
count={recentItems.length}
onToggle={() => toggleSection('recent')}
divider={hasPinned}
@@ -137,7 +159,7 @@ export function TodaySpacesSidebar(): JSX.Element {
</TodayPaneSection>
<TodayPaneSection
label="Spaces"
- open={!collapsedSections.includes('spaces')}
+ {...sectionLayout('spaces')}
count={visibleSpaces.length}
onToggle={() => toggleSection('spaces')}
divider
diff --git a/frontend/src/layout/today/todaySectionLayout.test.ts b/frontend/src/layout/today/todaySectionLayout.test.ts
new file mode 100644
index 000000000000..194f4e10af8c
--- /dev/null
+++ b/frontend/src/layout/today/todaySectionLayout.test.ts
@@ -0,0 +1,75 @@
+import {
+ PreferredTodaySectionHeights,
+ TodaySectionHeights,
+ TodaySectionInput,
+ layoutTodaySections,
+ resizeTodaySections,
+} from './todaySectionLayout'
+
+const section = (id: TodaySectionInput['id'], contentHeight: number, open = true): TodaySectionInput => ({
+ id,
+ open,
+ contentHeight,
+})
+
+describe('todaySectionLayout', () => {
+ test.each<[string, TodaySectionInput[], number, PreferredTodaySectionHeights, TodaySectionHeights]>([
+ [
+ 'recent absorbs the height the short sections leave',
+ [section('pinned', 100), section('recent', 50), section('spaces', 80)],
+ 600,
+ {},
+ { pinned: 100, recent: 420, spaces: 80 },
+ ],
+ [
+ 'long sections stop at the share cap',
+ [section('recent', 1000), section('spaces', 1000)],
+ 500,
+ {},
+ { pinned: 0, recent: 300, spaces: 200 },
+ ],
+ [
+ 'a dragged height wins over the share cap',
+ [section('recent', 1000), section('spaces', 1000)],
+ 500,
+ { spaces: 120 },
+ { pinned: 0, recent: 380, spaces: 120 },
+ ],
+ [
+ 'a collapsed section gets no height and spaces fill in its place',
+ [section('pinned', 100), section('recent', 1000, false), section('spaces', 1000)],
+ 600,
+ {},
+ { pinned: 100, recent: 0, spaces: 500 },
+ ],
+ [
+ 'short sections do not grow past their content when recent is collapsed',
+ [section('pinned', 50), section('recent', 1000, false), section('spaces', 80)],
+ 600,
+ {},
+ { pinned: 50, recent: 0, spaces: 80 },
+ ],
+ [
+ 'other sections shrink so recent keeps its minimum height',
+ [section('pinned', 500), section('recent', 500)],
+ 100,
+ { pinned: 90 },
+ { pinned: 44, recent: 56, spaces: 0 },
+ ],
+ ])('%s', (_, sections, available, preferred, expected) => {
+ expect(layoutTodaySections(sections, available, preferred)).toEqual(expected)
+ })
+
+ test('a drag clamps the lower section at its minimum and never stores the filling section', () => {
+ expect(
+ resizeTodaySections({
+ sections: [section('recent', 1000), section('spaces', 1000)],
+ heights: { pinned: 0, recent: 300, spaces: 200 },
+ upper: 'recent',
+ lower: 'spaces',
+ delta: 500,
+ preferred: {},
+ })
+ ).toEqual({ spaces: 40 })
+ })
+})
diff --git a/frontend/src/layout/today/todaySectionLayout.ts b/frontend/src/layout/today/todaySectionLayout.ts
new file mode 100644
index 000000000000..af3e64eb82bf
--- /dev/null
+++ b/frontend/src/layout/today/todaySectionLayout.ts
@@ -0,0 +1,116 @@
+import type { TodayWorkSectionId } from './todaySpacesLogic'
+
+export type TodaySectionHeights = Record<TodayWorkSectionId, number>
+
+export type PreferredTodaySectionHeights = Partial<Record<TodayWorkSectionId, number>>
+
+export interface TodaySectionInput {
+ id: TodayWorkSectionId
+ open: boolean
+ contentHeight: number
+}
+
+const FILL_ORDER: readonly TodayWorkSectionId[] = ['recent', 'spaces', 'pinned']
+
+export const TODAY_SECTION_HEADER_HEIGHT = 36
+const SHARE_CAP = 0.4
+const MIN_FILL_HEIGHT = 56
+const MIN_DRAG_HEIGHT = 40
+const STRETCHING_SECTION: TodayWorkSectionId = 'recent'
+
+function fillingSection(sections: readonly TodaySectionInput[]): TodayWorkSectionId | null {
+ return FILL_ORDER.find((id) => sections.some((section) => section.id === id && section.open)) ?? null
+}
+
+export function layoutTodaySections(
+ sections: readonly TodaySectionInput[],
+ available: number,
+ preferred: PreferredTodaySectionHeights = {}
+): TodaySectionHeights {
+ const heights: TodaySectionHeights = { pinned: 0, recent: 0, spaces: 0 }
+ const fill = fillingSection(sections)
+ if (fill === null || available <= 0) {
+ return heights
+ }
+
+ const open = sections.filter((section) => section.open)
+ const fillSection = open.find((section) => section.id === fill)
+ if (!fillSection) {
+ return heights
+ }
+ const others = open.filter((section) => section.id !== fill)
+ const share = Math.round(available * SHARE_CAP)
+
+ let used = 0
+ for (const section of others) {
+ const wanted = preferred[section.id] ?? share
+ heights[section.id] = Math.floor(Math.max(0, Math.min(section.contentHeight, wanted)))
+ used += heights[section.id]
+ }
+
+ const fillFloor = Math.min(fillSection.contentHeight, MIN_FILL_HEIGHT)
+ if (available - used < fillFloor && used > 0) {
+ const scale = Math.max(0, available - fillFloor) / used
+ used = 0
+ for (const section of others) {
+ heights[section.id] = Math.floor(heights[section.id] * scale)
+ used += heights[section.id]
+ }
+ }
+
+ const rest = Math.max(0, available - used)
+ heights[fill] = Math.floor(fill === STRETCHING_SECTION ? rest : Math.min(fillSection.contentHeight, rest))
+
+ let leftover = available - used - heights[fill]
+ for (const id of FILL_ORDER) {
+ if (leftover <= 0) {
+ break
+ }
+ const section = others.find((candidate) => candidate.id === id)
+ if (!section || preferred[id] !== undefined) {
+ continue
+ }
+ const grow = Math.floor(Math.min(leftover, section.contentHeight - heights[id]))
+ if (grow <= 0) {
+ continue
+ }
+ heights[id] += grow
+ leftover -= grow
+ }
+
+ return heights
+}
+
+export function resizeTodaySections({
+ sections,
+ heights,
+ upper,
+ lower,
+ delta,
+ preferred,
+}: {
+ sections: readonly TodaySectionInput[]
+ heights: TodaySectionHeights
+ upper: TodayWorkSectionId
+ lower: TodayWorkSectionId
+ delta: number
+ preferred: PreferredTodaySectionHeights
+}): PreferredTodaySectionHeights {
+ const contentOf = (id: TodayWorkSectionId): number =>
+ sections.find((section) => section.id === id)?.contentHeight ?? 0
+ const shrinkable = (id: TodayWorkSectionId): number => Math.max(0, heights[id] - MIN_DRAG_HEIGHT)
+ const growable = (id: TodayWorkSectionId): number =>
+ id === STRETCHING_SECTION ? Number.POSITIVE_INFINITY : Math.max(0, contentOf(id) - heights[id])
+ const min = -Math.min(shrinkable(upper), growable(lower))
+ const max = Math.min(growable(upper), shrinkable(lower))
+ const applied = Math.max(min, Math.min(max, delta))
+ const fill = fillingSection(sections)
+ const next = { ...preferred }
+ if (upper !== fill) {
+ next[upper] = heights[upper] + applied
+ }
+ if (lower !== fill) {
+ next[lower] = heights[lower] - applied
+ }
+ return next
+}
diff --git a/frontend/src/layout/today/todaySpacesLogic.ts b/frontend/src/layout/today/todaySpacesLogic.ts
index 81194f05561a..29a91fe23c79 100644
--- a/frontend/src/layout/today/todaySpacesLogic.ts
+++ b/frontend/src/layout/today/todaySpacesLogic.ts
@@ -55,6 +55,7 @@ export interface todaySpacesLogicValues {
recentTasks: TaskListItemApi[]
recentTasksLoading: boolean
recentTasksUnavailable: boolean
+ sectionHeights: Partial<Record<TodayWorkSectionId, number>>
sortedSpaces: ChannelDTOApi[]
spaces: ChannelDTOApi[]
spacesLoading: boolean
@@ -109,9 +110,19 @@ export interface todaySpacesLogicActions {
spaces: ChannelDTOApi[]
payload?: any
}
+ resetSectionPair: (
+ upper: TodayWorkSectionId,
+ lower: TodayWorkSectionId
+ ) => {
+ lower: TodayWorkSectionId
+ upper: TodayWorkSectionId
+ }
setBrowsingSpaces: (browsingSpaces: boolean) => {
browsingSpaces: boolean
}
+ setSectionHeights: (heights: Partial<Record<TodayWorkSectionId, number>>) => {
+ heights: Partial<Record<TodayWorkSectionId, number>>
+ }
toggleSection: (sectionId: TodayWorkSectionId) => {
sectionId: TodayWorkSectionId
}
@@ -155,6 +166,8 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([
actions({
toggleSection: (sectionId: TodayWorkSectionId) => ({ sectionId }),
setBrowsingSpaces: (browsingSpaces: boolean) => ({ browsingSpaces }),
+ setSectionHeights: (heights: Partial<Record<TodayWorkSectionId, number>>) => ({ heights }),
+ resetSectionPair: (upper: TodayWorkSectionId, lower: TodayWorkSectionId) => ({ upper, lower }),
}),
loaders(({ values }) => ({
spaces: [
@@ -213,6 +226,17 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([
state.includes(sectionId) ? state.filter((id) => id !== sectionId) : [...state, sectionId],
},
],
+ sectionHeights: [
+ {} as Partial<Record<TodayWorkSectionId, number>>,
+ { persist: true },
+ {
+ setSectionHeights: (_, { heights }) => heights,
+ resetSectionPair: (state, { upper, lower }) => {
+ const { [upper]: _upper, [lower]: _lower, ...rest } = state
+ return rest
+ },
+ },
+ ],
browsingSpaces: [
false,
{ persist: true },
diff --git a/frontend/src/layout/today/useTodaySectionLayout.ts b/frontend/src/layout/today/useTodaySectionLayout.ts
new file mode 100644
index 000000000000..f16d6a673337
--- /dev/null
+++ b/frontend/src/layout/today/useTodaySectionLayout.ts
@@ -0,0 +1,150 @@
+import { useActions, useValues } from 'kea'
+import { KeyboardEvent, PointerEvent, RefCallback, useLayoutEffect, useMemo, useRef, useState } from 'react'
+
+import {
+ PreferredTodaySectionHeights,
+ TODAY_SECTION_HEADER_HEIGHT,
+ TodaySectionHeights,
+ layoutTodaySections,
+ resizeTodaySections,
+} from './todaySectionLayout'
+import { TodayWorkSectionId, todaySpacesLogic } from './todaySpacesLogic'
+
+const KEYBOARD_STEP = 16
+
+type MeasuredKey = TodayWorkSectionId | 'area'
+
+export interface TodaySectionResizer {
+ onPointerDown: (event: PointerEvent<HTMLElement>) => void
+ onPointerMove: (event: PointerEvent<HTMLElement>) => void
+ onPointerUp: (event: PointerEvent<HTMLElement>) => void
+ onKeyDown: (event: KeyboardEvent<HTMLElement>) => void
+ onDoubleClick: () => void
+}
+
+interface Drag {
+ lower: TodayWorkSectionId
+ startY: number
+ start: TodaySectionHeights
+ preferred: PreferredTodaySectionHeights
+}
+
+function useMeasuredHeights(): {
+ measuredHeights: Partial<Record<MeasuredKey, number>>
+ measureRefs: Record<MeasuredKey, RefCallback<HTMLElement>>
+} {
+ const [measuredHeights, setMeasuredHeights] = useState<Partial<Record<MeasuredKey, number>>>({})
+ const elements = useRef(new Map<MeasuredKey, HTMLElement>())
+ const observer = useRef<ResizeObserver | null>(null)
+
+ const measure = useMemo(
+ () => (): void =>
+ setMeasuredHeights((previous) => {
+ const next = { ...previous }
+ for (const [key, element] of elements.current) {
+ next[key] = key === 'area' ? element.clientHeight : element.offsetHeight
+ }
+ return Object.entries(next).every(([key, value]) => previous[key as MeasuredKey] === value)
+ ? previous
+ : next
+ }),
+ []
+ )
+
+ useLayoutEffect(() => {
+ const resizeObserver = new ResizeObserver(measure)
+ observer.current = resizeObserver
+ for (const element of elements.current.values()) {
+ resizeObserver.observe(element)
+ }
+ measure()
+ return () => {
+ resizeObserver.disconnect()
+ observer.current = null
+ }
+ }, [measure])
+
+ const measureRefs = useMemo(() => {
+ const ref =
+ (key: MeasuredKey): RefCallback<HTMLElement> =>
+ (element) => {
+ const previous = elements.current.get(key)
+ if (previous && previous !== element) {
+ observer.current?.unobserve(previous)
+ elements.current.delete(key)
+ }
+ if (element) {
+ elements.current.set(key, element)
+ observer.current?.observe(element)
+ measure()
+ }
+ }
+ return { area: ref('area'), pinned: ref('pinned'), recent: ref('recent'), spaces: ref('spaces') }
+ }, [measure])
+
+ return { measuredHeights, measureRefs }
+}
+
+export function useTodaySectionLayout(sections: readonly { id: TodayWorkSectionId; open: boolean }[]): {
+ measureRefs: Record<MeasuredKey, RefCallback<HTMLElement>>
+ heights: TodaySectionHeights
+ measured: boolean
+ dragging: TodayWorkSectionId | null
+ resizer: (upper: TodayWorkSectionId, lower: TodayWorkSectionId) => TodaySectionResizer
+} {
+ const { sectionHeights } = useValues(todaySpacesLogic)
+ const { setSectionHeights, resetSectionPair } = useActions(todaySpacesLogic)
+ const { measuredHeights, measureRefs } = useMeasuredHeights()
+ const [drag, setDrag] = useState<Drag | null>(null)
+
+ const areaHeight = measuredHeights.area ?? 0
+ const inputs = sections.map((section) => ({ ...section, contentHeight: measuredHeights[section.id] ?? 0 }))
+ const heights = layoutTodaySections(
+ inputs,
+ areaHeight - TODAY_SECTION_HEADER_HEIGHT * sections.length,
+ drag?.preferred ?? sectionHeights
+ )
+ const measured =
+ areaHeight > 0 && sections.every((section) => !section.open || measuredHeights[section.id] !== undefined)
+
+ const resizer = (upper: TodayWorkSectionId, lower: TodayWorkSectionId): TodaySectionResizer => {
+ const resize = (delta: number, base: TodaySectionHeights): PreferredTodaySectionHeights =>
+ resizeTodaySections({ sections: inputs, heights: base, upper, lower, delta, preferred: sectionHeights })
+ const active = drag?.lower === lower ? drag : null
+ return {
+ onPointerDown: (event) => {
+ if (event.button !== 0) {
+ return
+ }
+ event.preventDefault()
+ event.currentTarget.setPointerCapture(event.pointerId)
+ setDrag({ lower, startY: event.clientY, start: heights, preferred: sectionHeights })
+ },
+ onPointerMove: (event) => {
+ if (!active) {
+ return
+ }
+ setDrag({ ...active, preferred: resize(event.clientY - active.startY, active.start) })
+ },
+ onPointerUp: (event) => {
+ if (!active) {
+ return
+ }
+ if (event.clientY !== active.startY) {
+ setSectionHeights(resize(event.clientY - active.startY, active.start))
+ }
+ setDrag(null)
+ },
+ onKeyDown: (event) => {
+ if (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') {
+ return
+ }
+ event.preventDefault()
+ setSectionHeights(resize(event.key === 'ArrowUp' ? -KEYBOARD_STEP : KEYBOARD_STEP, heights))
+ },
+ onDoubleClick: () => resetSectionPair(upper, lower),
+ }
+ }
+
+ return { measureRefs, heights, measured, dragging: drag?.lower ?? null, resizer }
+}