Skip to content

Commit 65f775e

Browse files
[verified] feat(desktop): rename pinned threads locally
Signed-off-by: Empire Operating <[email protected]>
1 parent 9115588 commit 65f775e

7 files changed

Lines changed: 149 additions & 26 deletions

File tree

‎desktop/src/app/AppShell.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ export function AppShell() {
929929
onNavigate={(destination) =>
930930
void goChannel(destination.channelId, destination)
931931
}
932+
onRename={threadRail.rename}
932933
onToggleCollapsed={threadRail.toggleCollapsed}
933934
onUnpin={threadRail.unpin}
934935
openThreadRootId={openThreadRootId}

‎desktop/src/features/channels/ThreadRailContext.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const EMPTY_RAIL: ThreadRail = {
88
collapsed: false,
99
isScoped: false,
1010
pin: () => {},
11+
rename: () => {},
1112
unpin: () => {},
1213
updateAnchor: () => {},
1314
updateExpandedReplyIds: () => {},

‎desktop/src/features/channels/threadRailStorage.test.mjs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
MAX_THREAD_RAIL_PINS,
88
parseThreadRailStore,
99
readThreadRailStore,
10+
renameThreadRailPin,
1011
removeThreadRailPin,
1112
updateThreadRailExpandedReplyIds,
1213
updateThreadRailPinAnchor,
@@ -228,6 +229,25 @@ test("parse rejects oversized durable identifiers", () => {
228229
assert.deepEqual(parsed?.pins, [PIN_A]);
229230
});
230231

232+
test("renames a pin locally, bounds its title, and clears it without changing identity", () => {
233+
const store = { collapsed: false, pins: [PIN_A, PIN_B], version: 1 };
234+
const renamed = renameThreadRailPin(store, PIN_A, ` ${"T".repeat(140)} `);
235+
236+
assert.equal(renamed.pins[0].customTitle, "T".repeat(128));
237+
assert.deepEqual(renamed.pins[1], PIN_B);
238+
assert.equal(renamed.pins[0].channelId, PIN_A.channelId);
239+
assert.equal(renamed.pins[0].rootId, PIN_A.rootId);
240+
assert.deepEqual(renameThreadRailPin(renamed, PIN_A, " "), {
241+
collapsed: false,
242+
pins: [PIN_A, PIN_B],
243+
version: 1,
244+
});
245+
assert.equal(
246+
renameThreadRailPin(store, { ...PIN_A, rootId: "missing" }, "Name"),
247+
store,
248+
);
249+
});
250+
231251
test("write failure leaves the caller-owned in-memory store usable", () => {
232252
const original = window.localStorage.setItem;
233253
window.localStorage.setItem = () => {

‎desktop/src/features/channels/threadRailStorage.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { setLocalStorageItemWithRecovery } from "@/shared/lib/localStorageQuota"
44
const STORAGE_PREFIX = "buzz-thread-rail.v1";
55
export const MAX_THREAD_RAIL_PINS = 50;
66
const MAX_EXPANDED_REPLY_IDS_PER_PIN = 100;
7+
const MAX_THREAD_RAIL_CUSTOM_TITLE_LENGTH = 128;
78
const MAX_THREAD_RAIL_ID_LENGTH = 256;
89
const MAX_THREAD_RAIL_CHANNEL_NAME_LENGTH = 128;
910
const MAX_THREAD_RAIL_EXCERPT_LENGTH = 512;
@@ -20,6 +21,7 @@ export type ThreadRailPin = {
2021
returnAnchorId?: string;
2122
/** Local branch expansion state for this pinned canonical thread. */
2223
expandedReplyIds?: string[];
24+
customTitle?: string;
2325
channelName?: string;
2426
rootExcerpt?: string;
2527
pinnedAt: number;
@@ -232,6 +234,27 @@ export function updateThreadRailExpandedReplyIds(
232234
return { ...store, pins };
233235
}
234236

237+
export function renameThreadRailPin(
238+
store: ThreadRailStore,
239+
pin: Pick<ThreadRailPin, "channelId" | "rootId">,
240+
customTitle: string,
241+
): ThreadRailStore {
242+
const index = store.pins.findIndex((existing) => samePin(existing, pin));
243+
if (index < 0) return store;
244+
const normalizedTitle = customTitle
245+
.trim()
246+
.slice(0, MAX_THREAD_RAIL_CUSTOM_TITLE_LENGTH);
247+
if ((store.pins[index].customTitle ?? "") === normalizedTitle) return store;
248+
const pins = [...store.pins];
249+
if (normalizedTitle) {
250+
pins[index] = { ...pins[index], customTitle: normalizedTitle };
251+
} else {
252+
const { customTitle: _customTitle, ...pinWithoutCustomTitle } = pins[index];
253+
pins[index] = pinWithoutCustomTitle;
254+
}
255+
return { ...store, pins };
256+
}
257+
235258
export function removeThreadRailPin(
236259
store: ThreadRailStore,
237260
pin: Pick<ThreadRailPin, "channelId" | "rootId">,

‎desktop/src/features/channels/ui/ThreadRail.tsx‎

Lines changed: 80 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
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

310
import {
411
threadRailEntryClassName,
@@ -16,6 +23,7 @@ import { cn } from "@/shared/lib/cn";
1623
export 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"

‎desktop/src/features/channels/useThreadRail.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
DEFAULT_THREAD_RAIL_STORE,
55
addThreadRailPin,
66
readThreadRailStore,
7+
renameThreadRailPin,
78
removeThreadRailPin,
89
toggleThreadRailCollapsed,
910
updateThreadRailExpandedReplyIds,
@@ -34,6 +35,10 @@ export type ThreadRail = {
3435
collapsed: boolean;
3536
isScoped: boolean;
3637
pin: (pin: ThreadRailPin) => void;
38+
rename: (
39+
pin: Pick<ThreadRailPin, "channelId" | "rootId">,
40+
customTitle: string,
41+
) => void;
3742
unpin: (pin: Pick<ThreadRailPin, "channelId" | "rootId">) => void;
3843
updateAnchor: (
3944
pin: Pick<ThreadRailPin, "channelId" | "rootId">,
@@ -93,6 +98,16 @@ export function useThreadRail(
9398
updateStore((store) => addThreadRailPin(store, pinToAdd)),
9499
[updateStore],
95100
);
101+
const rename = React.useCallback(
102+
(
103+
pinToRename: Pick<ThreadRailPin, "channelId" | "rootId">,
104+
customTitle: string,
105+
) =>
106+
updateStore((store) =>
107+
renameThreadRailPin(store, pinToRename, customTitle),
108+
),
109+
[updateStore],
110+
);
96111
const unpin = React.useCallback(
97112
(pinToRemove: Pick<ThreadRailPin, "channelId" | "rootId">) =>
98113
updateStore((store) => removeThreadRailPin(store, pinToRemove)),
@@ -133,13 +148,15 @@ export function useThreadRail(
133148
collapsed: store.collapsed,
134149
isScoped: scope !== null,
135150
pin,
151+
rename,
136152
unpin,
137153
updateAnchor,
138154
updateExpandedReplyIds,
139155
toggleCollapsed,
140156
}),
141157
[
142158
pin,
159+
rename,
143160
scope,
144161
store,
145162
toggleCollapsed,

‎desktop/tests/e2e/thread-rail.spec.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ test("pins a canonical thread, switches it from the collapsible rail, and unpins
160160
expect(visualContract.rowBackground).not.toBe("rgba(0, 0, 0, 0)");
161161
expect(visualContract.entryBackground).toBe("rgba(0, 0, 0, 0)");
162162

163+
await rail.getByTestId(`edit-thread-rail-title-${root.id}`).click();
164+
const titleInput = rail.getByTestId(`thread-rail-title-input-${root.id}`);
165+
await titleInput.fill("Roadmap");
166+
await titleInput.press("Enter");
167+
await expect(entry).toHaveAttribute("aria-label", "Roadmap");
168+
163169
const expandedWidth = await rail.evaluate((element) =>
164170
Math.round(element.getBoundingClientRect().width),
165171
);
@@ -179,6 +185,7 @@ test("pins a canonical thread, switches it from the collapsible rail, and unpins
179185

180186
await page.getByTestId("channel-random").click();
181187
await entry.click();
188+
await expect(entry).toHaveAttribute("aria-label", "Roadmap");
182189
await expect(page.getByTestId("chat-title")).toHaveText("general");
183190
await expect(panel).toBeVisible();
184191
await expect(panel.getByTestId("message-thread-head")).toContainText(

0 commit comments

Comments
 (0)