feat(web): make the room panes resizable

Drag the divider between the conversation and the workspace, or focus
it and use the arrow keys. The width stays between 380px and enough
room for a 420px conversation, and is stored in localStorage so it
survives reloads.

Below 1100px the workspace remains a fixed overlay, so the divider is
hidden there.
This commit is contained in:
vhaudiquet committed 2026-11-28 10:53:30 +01:00
1 parent e579653f75
commit 5be17cf4ef
2 files changed
+219 -3

No files matched your search

+49 -2
View File
@@ -1117,13 +1117,50 @@ button {
bottom: var(--sp-2); bottom: var(--sp-2);
} }
.pane-resizer {
flex: 0 0 var(--sp-2);
position: relative;
cursor: col-resize;
touch-action: none;
background: transparent;
}
.pane-resizer::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: calc(50% - 0.5px);
width: 1px;
background: var(--border);
transition: background-color 120ms ease, width 120ms ease, left 120ms ease;
}
.pane-resizer:hover::before,
.pane-resizer:focus-visible::before,
body.pane-resizing .pane-resizer::before {
left: calc(50% - 1px);
width: 2px;
background: var(--accent);
}
.pane-resizer:focus-visible {
outline: 2px solid var(--accent);
outline-offset: -2px;
}
body.pane-resizing,
body.pane-resizing * {
cursor: col-resize !important;
user-select: none !important;
}
.right-pane { .right-pane {
flex: 0 0 44%; flex: 0 0 var(--pane-width, 44%);
min-width: 380px; min-width: 380px;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
min-height: 0; min-height: 0;
border-left: 1px solid var(--border);
background: var(--surface); background: var(--surface);
container-type: inline-size; container-type: inline-size;
} }
@@ -1614,6 +1651,10 @@ button {
} }
@media (max-width: 1099px) { @media (max-width: 1099px) {
.pane-resizer {
display: none;
}
.right-pane { .right-pane {
position: fixed; position: fixed;
top: 0; top: 0;
@@ -1630,6 +1671,12 @@ button {
} }
} }
@media (min-width: 1100px) {
.chat-column {
min-width: 420px;
}
}
@container (max-width: 430px) { @container (max-width: 430px) {
.files { .files {
grid-template-columns: 1fr; grid-template-columns: 1fr;
+170 -1
View File
@@ -59,6 +59,26 @@ const paneOpen = ref(typeof window === 'undefined' ? true : !window.matchMedia('
const inviteOpen = ref(false) const inviteOpen = ref(false)
const settingsOpen = ref(false) const settingsOpen = ref(false)
const PANE_WIDTH_KEY = 'together.pane-width'
const DEFAULT_PANE_PERCENT = 44
const PANE_MIN_WIDTH = 380
const CHAT_MIN_WIDTH = 420
const DIVIDER_WIDTH = 8
const roomBody = ref<HTMLElement | null>(null)
const paneWidth = ref<number | null>(null)
const paneBodyWidth = ref(0)
let paneBodyObserver: ResizeObserver | null = null
type PaneDrag = {
pointerId: number
startX: number
startWidth: number
moved: boolean
}
let paneDrag: PaneDrag | null = null
const seenMessages = new Set<number>() const seenMessages = new Set<number>()
const seenNotices = new Set<number>() const seenNotices = new Set<number>()
let lastDurable = 0 let lastDurable = 0
@@ -93,6 +113,44 @@ const memberById = computed(() => {
return map return map
}) })
const paneMaxWidth = computed(() => {
const total = paneBodyWidth.value
if (!total) return PANE_MIN_WIDTH
return Math.max(PANE_MIN_WIDTH, total - CHAT_MIN_WIDTH - DIVIDER_WIDTH)
})
function clampPaneWidth(width: number): number {
const rounded = Math.round(width)
if (!paneBodyWidth.value) return Math.max(rounded, PANE_MIN_WIDTH)
return Math.min(Math.max(rounded, PANE_MIN_WIDTH), paneMaxWidth.value)
}
const effectivePaneWidth = computed(() => {
if (paneWidth.value === null) return null
return clampPaneWidth(paneWidth.value)
})
const paneStyle = computed<Record<string, string> | undefined>(() => {
const width = effectivePaneWidth.value
return width === null ? undefined : { '--pane-width': `${width}px` }
})
function panePercentFor(width: number): number {
const total = paneBodyWidth.value
if (!total) return DEFAULT_PANE_PERCENT
return Math.round((width / total) * 100)
}
const paneValue = computed(() => {
const total = paneBodyWidth.value
if (!total) return DEFAULT_PANE_PERCENT
const width = effectivePaneWidth.value ?? (total * DEFAULT_PANE_PERCENT) / 100
return panePercentFor(width)
})
const paneMinPercent = computed(() => (paneBodyWidth.value ? panePercentFor(PANE_MIN_WIDTH) : 25))
const paneMaxPercent = computed(() => (paneBodyWidth.value ? panePercentFor(paneMaxWidth.value) : 75))
const timeline = computed<TimelineEntry[]>(() => { const timeline = computed<TimelineEntry[]>(() => {
const entries: TimelineEntry[] = [] const entries: TimelineEntry[] = []
for (const message of messages.value) { for (const message of messages.value) {
@@ -446,6 +504,86 @@ function onTyping(active: boolean) {
sendPresenceState(active) sendPresenceState(active)
} }
function readPaneWidth(): number | null {
try {
const stored = window.localStorage.getItem(PANE_WIDTH_KEY)
if (!stored) return null
const value = Number.parseInt(stored, 10)
return Number.isFinite(value) && value > 0 ? value : null
} catch {
return null
}
}
function savePaneWidth(width: number) {
try {
window.localStorage.setItem(PANE_WIDTH_KEY, String(Math.round(width)))
} catch {
// A browser that refuses storage keeps the width for this visit.
}
}
function currentPaneElement(): HTMLElement | null {
return roomBody.value?.querySelector<HTMLElement>('.right-pane') ?? null
}
function onPaneResizeStart(event: PointerEvent) {
if (event.button !== 0) return
const pane = currentPaneElement()
if (!pane) return
event.preventDefault()
paneDrag = {
pointerId: event.pointerId,
startX: event.clientX,
startWidth: pane.getBoundingClientRect().width,
moved: false,
}
;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)
document.body.classList.add('pane-resizing')
}
function onPaneResizeMove(event: PointerEvent) {
if (!paneDrag || event.pointerId !== paneDrag.pointerId) return
const next = paneDrag.startWidth + paneDrag.startX - event.clientX
if (Math.abs(event.clientX - paneDrag.startX) >= 1) paneDrag.moved = true
paneWidth.value = clampPaneWidth(next)
}
function endPaneResize() {
if (!paneDrag) return
const moved = paneDrag.moved
paneDrag = null
document.body.classList.remove('pane-resizing')
if (moved && paneWidth.value !== null) savePaneWidth(paneWidth.value)
}
function onPaneResizeKey(event: KeyboardEvent) {
const pane = currentPaneElement()
const current = pane?.getBoundingClientRect().width ?? effectivePaneWidth.value ?? 0
const step = event.shiftKey ? 64 : 16
let next: number
switch (event.key) {
case 'ArrowLeft':
next = current + step
break
case 'ArrowRight':
next = current - step
break
case 'Home':
next = PANE_MIN_WIDTH
break
case 'End':
next = paneMaxWidth.value
break
default:
return
}
event.preventDefault()
const clamped = clampPaneWidth(next)
paneWidth.value = clamped
savePaneWidth(clamped)
}
function colorFor(message: Message): string | null { function colorFor(message: Message): string | null {
if (!message.author_id) return null if (!message.author_id) return null
return memberById.value.get(message.author_id)?.color ?? null return memberById.value.get(message.author_id)?.color ?? null
@@ -573,11 +711,19 @@ async function onArchived() {
} }
onMounted(async () => { onMounted(async () => {
paneWidth.value = readPaneWidth()
await loadDetail() await loadDetail()
await loadMessages() await loadMessages()
if (!detailError.value) { if (!detailError.value) {
await nextTick() await nextTick()
if (roomBody.value) {
paneBodyWidth.value = roomBody.value.clientWidth
paneBodyObserver = new ResizeObserver(() => {
paneBodyWidth.value = roomBody.value?.clientWidth ?? 0
})
paneBodyObserver.observe(roomBody.value)
}
scrollToBottom() scrollToBottom()
window.requestAnimationFrame(() => { window.requestAnimationFrame(() => {
if (stick.value) scrollToBottom() if (stick.value) scrollToBottom()
@@ -598,6 +744,9 @@ onMounted(async () => {
onBeforeUnmount(() => { onBeforeUnmount(() => {
disposed = true disposed = true
eventGeneration += 1 eventGeneration += 1
paneBodyObserver?.disconnect()
paneBodyObserver = null
document.body.classList.remove('pane-resizing')
chatObserver?.disconnect() chatObserver?.disconnect()
chatObserver = null chatObserver = null
eventController?.abort() eventController?.abort()
@@ -632,7 +781,7 @@ onBeforeUnmount(() => {
@toggle-pane="paneOpen = !paneOpen" @toggle-pane="paneOpen = !paneOpen"
/> />
<div class="room-body"> <div ref="roomBody" class="room-body" :style="paneStyle">
<div class="chat-column"> <div class="chat-column">
<div class="chat-area"> <div class="chat-area">
<div ref="chatScroll" class="chat-scroll" @scroll="onScroll"> <div ref="chatScroll" class="chat-scroll" @scroll="onScroll">
@@ -690,6 +839,26 @@ onBeforeUnmount(() => {
<ChatComposer :room-id="roomId" @sent="onSent" @typing="onTyping" /> <ChatComposer :room-id="roomId" @sent="onSent" @typing="onTyping" />
</div> </div>
<div
v-if="paneOpen"
class="pane-resizer"
role="separator"
aria-orientation="vertical"
aria-label="Resize conversation and workspace panes"
:aria-valuemin="paneMinPercent"
:aria-valuemax="paneMaxPercent"
:aria-valuenow="paneValue"
:aria-valuetext="`${paneValue} percent`"
title="Drag to resize. Arrow keys also work."
tabindex="0"
@pointerdown="onPaneResizeStart"
@pointermove="onPaneResizeMove"
@pointerup="endPaneResize"
@pointercancel="endPaneResize"
@lostpointercapture="endPaneResize"
@keydown="onPaneResizeKey"
></div>
<RightPane <RightPane
v-if="paneOpen" v-if="paneOpen"
:room-id="detail.room.id" :room-id="detail.room.id"