Live portal: rename streams (tab double-click, persisted per browser) and name tab groups (header slot, session)
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
22
live/src/GroupLabel.jsx
Normal file
22
live/src/GroupLabel.jsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import { names } from './names.js'
|
||||
|
||||
// Left end of every tab bar: an editable group name (double-click). Session-only.
|
||||
export default function GroupLabel({ group }) {
|
||||
const id = group.id
|
||||
const name = names.use(s => s.groups[id])
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [draft, setDraft] = useState('')
|
||||
const ref = useRef(null)
|
||||
useEffect(() => { if (editing) { ref.current?.focus(); ref.current?.select() } }, [editing])
|
||||
const start = e => { e.stopPropagation(); setDraft(name || ''); setEditing(true) }
|
||||
const commit = () => { if (!editing) return; names.renameGroup(id, draft.trim()); setEditing(false) }
|
||||
return (
|
||||
<div className="grouplabel" title="double-click to name this group" onDoubleClick={start} onPointerDown={e => e.stopPropagation()}>
|
||||
{editing
|
||||
? <input ref={ref} value={draft} placeholder="group name" onChange={e => setDraft(e.target.value)} onBlur={commit}
|
||||
onKeyDown={e => { e.stopPropagation(); if (e.key === 'Enter') commit(); if (e.key === 'Escape') setEditing(false) }} />
|
||||
: <span className={name ? 'gname' : 'hint'}>{name || '+ name'}</span>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user