|
1 | 1 | import { ChevronLeft, ChevronRight, MessageSquareText, X } from "lucide-react"; |
2 | 2 |
|
3 | 3 | import { |
| 4 | + threadRailColumnClassName, |
4 | 5 | threadRailEntryClassName, |
5 | 6 | threadRailHeaderClassName, |
6 | 7 | threadRailShellClassName, |
@@ -36,111 +37,116 @@ export function ThreadRail({ |
36 | 37 | }) { |
37 | 38 | if (pins.length === 0) return null; |
38 | 39 | return ( |
39 | | - <aside |
40 | | - aria-label="Pinned threads" |
41 | | - className={cn( |
42 | | - threadRailShellClassName(collapsed), |
43 | | - collapsed ? "min-[601px]:w-10" : "min-[601px]:w-56", |
44 | | - )} |
45 | | - data-collapsed={collapsed} |
46 | | - data-testid="thread-rail" |
| 40 | + <div |
| 41 | + className={threadRailColumnClassName()} |
| 42 | + data-testid="thread-rail-column" |
47 | 43 | > |
48 | | - <div |
| 44 | + <aside |
| 45 | + aria-label="Pinned threads" |
49 | 46 | className={cn( |
50 | | - threadRailHeaderClassName(), |
51 | | - collapsed ? "justify-center px-1" : "justify-between", |
| 47 | + threadRailShellClassName(collapsed), |
| 48 | + collapsed ? "min-[601px]:w-10" : "min-[601px]:w-56", |
52 | 49 | )} |
53 | | - data-testid="thread-rail-header" |
| 50 | + data-collapsed={collapsed} |
| 51 | + data-testid="thread-rail" |
54 | 52 | > |
55 | | - {!collapsed ? ( |
56 | | - <span className="truncate text-base font-semibold leading-6 tracking-tight"> |
57 | | - Pinned threads |
58 | | - </span> |
59 | | - ) : null} |
60 | | - <Button |
61 | | - aria-expanded={!collapsed} |
62 | | - aria-label={ |
63 | | - collapsed |
64 | | - ? `Expand ${pins.length} pinned threads` |
65 | | - : "Collapse pinned threads" |
66 | | - } |
67 | | - data-testid="thread-rail-toggle" |
68 | | - onClick={onToggleCollapsed} |
69 | | - size="icon" |
70 | | - type="button" |
71 | | - variant="ghost" |
72 | | - > |
73 | | - {collapsed ? ( |
74 | | - <ChevronLeft aria-hidden /> |
75 | | - ) : ( |
76 | | - <ChevronRight aria-hidden /> |
| 53 | + <div |
| 54 | + className={cn( |
| 55 | + threadRailHeaderClassName(), |
| 56 | + collapsed ? "justify-center px-1" : "justify-between", |
77 | 57 | )} |
78 | | - </Button> |
79 | | - </div> |
80 | | - {!collapsed ? ( |
81 | | - <div className="min-h-0 space-y-1 overflow-y-auto px-2 pb-2 pt-1"> |
82 | | - {pins.map((pin) => { |
83 | | - const active = isThreadRailPinActive( |
84 | | - pin, |
85 | | - selectedChannelId, |
86 | | - openThreadRootId, |
87 | | - ); |
88 | | - const hasUnread = unreadRootIds.has(pin.rootId); |
89 | | - const label = `${pin.channelName ? `#${pin.channelName}: ` : ""}${ |
90 | | - pin.rootExcerpt || "Pinned thread" |
91 | | - }`; |
92 | | - return ( |
93 | | - <div |
94 | | - className={threadRailEntryClassName(active)} |
95 | | - data-testid={`thread-rail-row-${pin.rootId}`} |
96 | | - key={`${pin.channelId}:${pin.rootId}`} |
97 | | - > |
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" |
| 58 | + data-testid="thread-rail-header" |
| 59 | + > |
| 60 | + {!collapsed ? ( |
| 61 | + <span className="truncate text-base font-semibold leading-6 tracking-tight"> |
| 62 | + Pinned threads |
| 63 | + </span> |
| 64 | + ) : null} |
| 65 | + <Button |
| 66 | + aria-expanded={!collapsed} |
| 67 | + aria-label={ |
| 68 | + collapsed |
| 69 | + ? `Expand ${pins.length} pinned threads` |
| 70 | + : "Collapse pinned threads" |
| 71 | + } |
| 72 | + data-testid="thread-rail-toggle" |
| 73 | + onClick={onToggleCollapsed} |
| 74 | + size="icon" |
| 75 | + type="button" |
| 76 | + variant="ghost" |
| 77 | + > |
| 78 | + {collapsed ? ( |
| 79 | + <ChevronLeft aria-hidden /> |
| 80 | + ) : ( |
| 81 | + <ChevronRight aria-hidden /> |
| 82 | + )} |
| 83 | + </Button> |
| 84 | + </div> |
| 85 | + {!collapsed ? ( |
| 86 | + <div className="min-h-0 space-y-1 overflow-y-auto px-2 pb-2 pt-1"> |
| 87 | + {pins.map((pin) => { |
| 88 | + const active = isThreadRailPinActive( |
| 89 | + pin, |
| 90 | + selectedChannelId, |
| 91 | + openThreadRootId, |
| 92 | + ); |
| 93 | + const hasUnread = unreadRootIds.has(pin.rootId); |
| 94 | + const label = `${pin.channelName ? `#${pin.channelName}: ` : ""}${ |
| 95 | + pin.rootExcerpt || "Pinned thread" |
| 96 | + }`; |
| 97 | + return ( |
| 98 | + <div |
| 99 | + className={threadRailEntryClassName(active)} |
| 100 | + data-testid={`thread-rail-row-${pin.rootId}`} |
| 101 | + key={`${pin.channelId}:${pin.rootId}`} |
108 | 102 | > |
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 |
| 103 | + <button |
| 104 | + aria-current={active ? "page" : undefined} |
| 105 | + aria-label={hasUnread ? `${label}, unread reply` : label} |
| 106 | + className="min-w-0 flex-1 px-2.5 py-2 text-left text-sm focus-visible:outline-hidden" |
| 107 | + data-testid={`thread-rail-entry-${pin.rootId}`} |
| 108 | + onClick={() => |
| 109 | + onNavigate(threadRailPinToChannelNavigation(pin)) |
| 110 | + } |
| 111 | + title={label} |
| 112 | + type="button" |
| 113 | + > |
| 114 | + <span className="flex items-center gap-2"> |
| 115 | + <MessageSquareText |
117 | 116 | aria-hidden |
118 | | - className="size-2 shrink-0 rounded-full bg-primary" |
119 | | - data-testid={`thread-rail-unread-${pin.rootId}`} |
| 117 | + className="size-3.5 shrink-0 text-muted-foreground" |
120 | 118 | /> |
121 | | - ) : null} |
122 | | - </span> |
123 | | - </button> |
124 | | - <Button |
125 | | - aria-label={`Unpin ${label}`} |
126 | | - className="mr-1 shrink-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100" |
127 | | - data-testid={`unpin-thread-rail-${pin.rootId}`} |
128 | | - onClick={(event) => { |
129 | | - event.stopPropagation(); |
130 | | - onUnpin(pin); |
131 | | - }} |
132 | | - size="icon-xs" |
133 | | - title="Unpin thread" |
134 | | - type="button" |
135 | | - variant="ghost" |
136 | | - > |
137 | | - <X aria-hidden /> |
138 | | - </Button> |
139 | | - </div> |
140 | | - ); |
141 | | - })} |
142 | | - </div> |
143 | | - ) : null} |
144 | | - </aside> |
| 119 | + <span className="min-w-0 flex-1 truncate">{label}</span> |
| 120 | + {hasUnread ? ( |
| 121 | + <span |
| 122 | + aria-hidden |
| 123 | + className="size-2 shrink-0 rounded-full bg-primary" |
| 124 | + data-testid={`thread-rail-unread-${pin.rootId}`} |
| 125 | + /> |
| 126 | + ) : null} |
| 127 | + </span> |
| 128 | + </button> |
| 129 | + <Button |
| 130 | + aria-label={`Unpin ${label}`} |
| 131 | + className="mr-1 shrink-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100" |
| 132 | + data-testid={`unpin-thread-rail-${pin.rootId}`} |
| 133 | + onClick={(event) => { |
| 134 | + event.stopPropagation(); |
| 135 | + onUnpin(pin); |
| 136 | + }} |
| 137 | + size="icon-xs" |
| 138 | + title="Unpin thread" |
| 139 | + type="button" |
| 140 | + variant="ghost" |
| 141 | + > |
| 142 | + <X aria-hidden /> |
| 143 | + </Button> |
| 144 | + </div> |
| 145 | + ); |
| 146 | + })} |
| 147 | + </div> |
| 148 | + ) : null} |
| 149 | + </aside> |
| 150 | + </div> |
145 | 151 | ); |
146 | 152 | } |
0 commit comments