Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions packages/session-ui/src/v2/components/session-review-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ResizeHandle } from "@opencode/ui/resize-handle"
import { useLocale } from "@kobalte/core/i18n"
import { makeEventListener } from "@solid-primitives/event-listener"
import { prefersReducedMotion } from "@opencode/ui/motion"
import { Show, createEffect, createMemo, createSignal, on, onCleanup, untrack, type JSX } from "solid-js"
import { Show, createEffect, createMemo, createSignal, on, onCleanup, onMount, untrack, type JSX } from "solid-js"
import { getWorkerPool } from "../../pierre/worker"
import {
SIDEBAR_EXIT_TIMEOUT_MS,
Expand All @@ -31,6 +31,9 @@ export const SESSION_REVIEW_V2_SIDEBAR_WIDTH_MIN = 200

export const SESSION_REVIEW_V2_SIDEBAR_WIDTH_MAX = 480

// Width of the file preview kept beside a sidebar that is limited by a narrow panel.
const SESSION_REVIEW_V2_PREVIEW_WIDTH_MIN = 120

export type SessionReviewExpandMode = "expand" | "collapse"

export type SessionReviewV2Props = {
Expand Down Expand Up @@ -83,7 +86,17 @@ export type SessionReviewV2SidebarProps = {
export function SessionReviewV2Sidebar(props: SessionReviewV2SidebarProps) {
const i18n = useI18n()
const [resizing, setResizing] = createSignal(false)
const width = () => props.width ?? SESSION_REVIEW_V2_SIDEBAR_WIDTH_DEFAULT
const [room, setRoom] = createSignal<number>()
let root: HTMLDivElement | undefined
// The stored width can exceed a panel narrowed after it was set; render at most the panel's width, less a little
// room for the preview, so the sidebar and its resize handle stay inside it, while the stored width comes back when
// the panel widens again.
const width = () => {
const stored = props.width ?? SESSION_REVIEW_V2_SIDEBAR_WIDTH_DEFAULT
const available = room()
if (available === undefined) return stored
return Math.min(stored, Math.max(0, available - SESSION_REVIEW_V2_PREVIEW_WIDTH_MIN))
}
const minWidth = () => props.minWidth ?? SESSION_REVIEW_V2_SIDEBAR_WIDTH_MIN
const maxWidth = () => props.maxWidth ?? SESSION_REVIEW_V2_SIDEBAR_WIDTH_MAX
const [presence, setPresence] = createSignal(createSidebarPresenceState(untrack(() => props.open)))
Expand Down Expand Up @@ -112,10 +125,18 @@ export function SessionReviewV2Sidebar(props: SessionReviewV2SidebarProps) {
)
onCleanup(() => clearTimeout(exitTimer))

onMount(() => {
const body = root?.closest<HTMLElement>('[data-slot="session-review-v2-body"]')
if (!body || typeof ResizeObserver === "undefined") return
const observer = new ResizeObserver(() => setRoom(body.clientWidth || undefined))
observer.observe(body)
onCleanup(() => observer.disconnect())
})

const closing = () => presence().status === "closing"

return (
<div data-component="session-review-v2-sidebar-root">
<div data-component="session-review-v2-sidebar-root" ref={root}>
<Show when={selectSidebarMounted(presence())}>
<aside
data-slot="session-review-v2-sidebar"
Expand Down
Loading