1- import { ChevronLeft , ChevronRight , MessageSquareText , X } from "lucide-react" ;
1+ import * as React from "react" ;
2+ import {
3+ ChevronLeft ,
4+ ChevronRight ,
5+ MessageSquareText ,
6+ Pencil ,
7+ X ,
8+ } from "lucide-react" ;
29
310import {
411 threadRailEntryClassName ,
@@ -16,6 +23,7 @@ import { cn } from "@/shared/lib/cn";
1623export function ThreadRail ( {
1724 collapsed,
1825 onNavigate,
26+ onRename,
1927 onToggleCollapsed,
2028 onUnpin,
2129 openThreadRootId,
@@ -27,13 +35,19 @@ export function ThreadRail({
2735 onNavigate : (
2836 destination : ReturnType < typeof threadRailPinToChannelNavigation > ,
2937 ) => void ;
38+ onRename : (
39+ pin : Pick < ThreadRailPin , "channelId" | "rootId" > ,
40+ customTitle : string ,
41+ ) => void ;
3042 onToggleCollapsed : ( ) => void ;
3143 onUnpin : ( pin : Pick < ThreadRailPin , "channelId" | "rootId" > ) => void ;
3244 openThreadRootId : string | null ;
3345 pins : ThreadRailPin [ ] ;
3446 selectedChannelId : string | null ;
3547 unreadRootIds : ReadonlySet < string > ;
3648} ) {
49+ const [ editingPinKey , setEditingPinKey ] = React . useState < string | null > ( null ) ;
50+ const [ titleDraft , setTitleDraft ] = React . useState ( "" ) ;
3751 if ( pins . length === 0 ) return null ;
3852 return (
3953 < aside
@@ -86,41 +100,81 @@ export function ThreadRail({
86100 openThreadRootId ,
87101 ) ;
88102 const hasUnread = unreadRootIds . has ( pin . rootId ) ;
89- const label = `${ pin . channelName ? `#${ pin . channelName } : ` : "" } ${
103+ const pinKey = `${ pin . channelId } :${ pin . rootId } ` ;
104+ const fallbackLabel = `${ pin . channelName ? `#${ pin . channelName } : ` : "" } ${
90105 pin . rootExcerpt || "Pinned thread"
91106 } `;
107+ const label = pin . customTitle || fallbackLabel ;
108+ const editing = editingPinKey === pinKey ;
92109 return (
93110 < div
94111 className = { threadRailEntryClassName ( active ) }
95112 data-testid = { `thread-rail-row-${ pin . rootId } ` }
96113 key = { `${ pin . channelId } :${ pin . rootId } ` }
97114 >
98- < button
99- aria-current = { active ? "page" : undefined }
100- aria-label = { hasUnread ? `${ label } , unread reply` : label }
101- className = "min-w-0 flex-1 px-2.5 py-2 text-left text-sm focus-visible:outline-hidden"
102- data-testid = { `thread-rail-entry-${ pin . rootId } ` }
103- onClick = { ( ) =>
104- onNavigate ( threadRailPinToChannelNavigation ( pin ) )
105- }
106- title = { label }
107- type = "button"
108- >
109- < span className = "flex items-center gap-2" >
110- < MessageSquareText
111- aria-hidden
112- className = "size-3.5 shrink-0 text-muted-foreground"
113- />
114- < span className = "min-w-0 flex-1 truncate" > { label } </ span >
115- { hasUnread ? (
116- < span
115+ { editing ? (
116+ < input
117+ aria-label = { `Rename ${ fallbackLabel } ` }
118+ autoFocus
119+ className = "min-w-0 flex-1 bg-transparent px-2.5 py-2 text-sm outline-none"
120+ data-testid = { `thread-rail-title-input-${ pin . rootId } ` }
121+ onBlur = { ( ) => {
122+ onRename ( pin , titleDraft ) ;
123+ setEditingPinKey ( null ) ;
124+ } }
125+ onChange = { ( event ) => setTitleDraft ( event . target . value ) }
126+ onKeyDown = { ( event ) => {
127+ if ( event . key === "Enter" ) {
128+ onRename ( pin , titleDraft ) ;
129+ setEditingPinKey ( null ) ;
130+ }
131+ if ( event . key === "Escape" ) setEditingPinKey ( null ) ;
132+ } }
133+ value = { titleDraft }
134+ />
135+ ) : (
136+ < button
137+ aria-current = { active ? "page" : undefined }
138+ aria-label = { hasUnread ? `${ label } , unread reply` : label }
139+ className = "min-w-0 flex-1 px-2.5 py-2 text-left text-sm focus-visible:outline-hidden"
140+ data-testid = { `thread-rail-entry-${ pin . rootId } ` }
141+ onClick = { ( ) =>
142+ onNavigate ( threadRailPinToChannelNavigation ( pin ) )
143+ }
144+ title = { label }
145+ type = "button"
146+ >
147+ < span className = "flex items-center gap-2" >
148+ < MessageSquareText
117149 aria-hidden
118- className = "size-2 shrink-0 rounded-full bg-primary"
119- data-testid = { `thread-rail-unread-${ pin . rootId } ` }
150+ className = "size-3.5 shrink-0 text-muted-foreground"
120151 />
121- ) : null }
122- </ span >
123- </ button >
152+ < span className = "min-w-0 flex-1 truncate" > { label } </ span >
153+ { hasUnread ? (
154+ < span
155+ aria-hidden
156+ className = "size-2 shrink-0 rounded-full bg-primary"
157+ data-testid = { `thread-rail-unread-${ pin . rootId } ` }
158+ />
159+ ) : null }
160+ </ span >
161+ </ button >
162+ ) }
163+ < Button
164+ aria-label = { `Rename ${ label } ` }
165+ className = "shrink-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100"
166+ data-testid = { `edit-thread-rail-title-${ pin . rootId } ` }
167+ onClick = { ( ) => {
168+ setTitleDraft ( pin . customTitle ?? "" ) ;
169+ setEditingPinKey ( pinKey ) ;
170+ } }
171+ size = "icon-xs"
172+ title = "Rename pinned thread"
173+ type = "button"
174+ variant = "ghost"
175+ >
176+ < Pencil aria-hidden />
177+ </ Button >
124178 < Button
125179 aria-label = { `Unpin ${ label } ` }
126180 className = "mr-1 shrink-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100"
0 commit comments