Skip to content

Commit 0eebb58

Browse files
[verified] feat(desktop): add persistent pinned thread rail
Signed-off-by: Empire Operating <[email protected]>
1 parent f8692fa commit 0eebb58

29 files changed

Lines changed: 2121 additions & 96 deletions

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export default defineConfig({
8686
"**/community-rail.spec.ts",
8787
"**/boot-splash.spec.ts",
8888
"**/thread-reply-anchor-roleplay.spec.ts",
89+
"**/thread-rail.spec.ts",
8990
"**/threadpane-ultrawide.spec.ts",
9091
"**/thread-focus-mode.spec.ts",
9192
"**/animated-avatar.spec.ts",

‎desktop/src/app/AppShell.tsx‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ import {
3030
useHideDmMutation,
3131
useOpenDmMutation,
3232
} from "@/features/channels/hooks";
33+
import { useThreadRail } from "@/features/channels/useThreadRail";
34+
import { threadRailRootIdFromSearch } from "@/features/channels/threadRailNavigation";
35+
import { ThreadRailProvider } from "@/features/channels/ThreadRailContext";
36+
import { ThreadRail } from "@/features/channels/ui/ThreadRail";
3337
import { useUnreadChannels } from "@/features/channels/useUnreadChannels";
3438
import { useMembershipNotifications } from "@/features/channels/useMembershipNotifications";
3539
import { useFeedItemState } from "@/features/home/useFeedItemState";
3640
import { useThreadFollows } from "@/features/messages/lib/useThreadFollows";
41+
import { getThreadReference } from "@/features/messages/lib/threading";
3742
import {
3843
useHomeFeedNotifications,
3944
useHomeFeedNotificationState,
@@ -173,6 +178,11 @@ export function AppShell() {
173178
: DEFAULT_SETTINGS_SECTION;
174179
const startupReady = useDeferredStartup();
175180
const identityQuery = useIdentityQuery();
181+
const threadRail = useThreadRail(
182+
identityQuery.data?.pubkey,
183+
communitiesHook.activeCommunity?.relayUrl,
184+
);
185+
const openThreadRootId = threadRailRootIdFromSearch(location.search);
176186
const { mutedChannelIds, muteChannel, unmuteChannel } = useChannelMutes(
177187
identityQuery.data?.pubkey,
178188
communitiesHook.activeCommunity?.relayUrl,
@@ -406,6 +416,16 @@ export function AppShell() {
406416
threadActivityItems,
407417
mutedRootIds,
408418
});
419+
const unreadThreadRootIds = React.useMemo(
420+
() =>
421+
new Set(
422+
unreadThreadFeedItems.flatMap((item) => {
423+
const rootId = getThreadReference(item.tags).rootId;
424+
return rootId ? [rootId] : [];
425+
}),
426+
) as ReadonlySet<string>,
427+
[unreadThreadFeedItems],
428+
);
409429
const markAllChannelsRead = React.useCallback(() => {
410430
markAllReadSources({
411431
activeChannelId: activeChannel?.id ?? null,
@@ -899,8 +919,24 @@ export function AppShell() {
899919
mainInsetRef={mainInsetRef}
900920
terminal={<TerminalBootstrap {...terminalContext} />}
901921
>
902-
<Outlet />
922+
<ThreadRailProvider rail={threadRail}>
923+
<Outlet />
924+
</ThreadRailProvider>
903925
</AppShellChannelSurface>
926+
{!isHuddleRoom ? (
927+
<ThreadRail
928+
collapsed={threadRail.collapsed}
929+
onNavigate={(destination) =>
930+
void goChannel(destination.channelId, destination)
931+
}
932+
onToggleCollapsed={threadRail.toggleCollapsed}
933+
onUnpin={threadRail.unpin}
934+
openThreadRootId={openThreadRootId}
935+
pins={threadRail.pins}
936+
selectedChannelId={selectedChannelId}
937+
unreadRootIds={unreadThreadRootIds}
938+
/>
939+
) : null}
904940
{!isHuddleRoom ? (
905941
<RelayConnectionOverlay
906942
card={relayConnectionCard}

‎desktop/src/app/routes/ChannelRouteScreen.tsx‎

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ export function ChannelRouteScreen({
118118
const cachedTarget = getCachedSearchHitEvent(targetMessageId);
119119
return cachedTarget ? [cachedTarget] : [];
120120
});
121+
const routeTargetKey = `${targetMessageId ?? ""}\u0000${targetThreadRootId ?? ""}`;
122+
const [routeLoadState, setRouteLoadState] = React.useState(() => ({
123+
key: routeTargetKey,
124+
settled:
125+
(!targetMessageId && !targetThreadRootId) || Boolean(selectedPostId),
126+
}));
127+
const targetMessageLoadSettled =
128+
routeLoadState.key === routeTargetKey && routeLoadState.settled;
121129

122130
// Reset spliced target events when the channel context changes (channel
123131
// switch or entering/leaving a forum post). Tied to channel identity rather
@@ -138,14 +146,17 @@ export function ChannelRouteScreen({
138146

139147
React.useEffect(() => {
140148
let isCancelled = false;
149+
const shouldFetchTarget =
150+
Boolean(targetMessageId || targetThreadRootId) && !selectedPostId;
151+
setRouteLoadState({ key: routeTargetKey, settled: !shouldFetchTarget });
141152

142153
// Don't wipe already-spliced target events just because the route target
143154
// cleared (e.g. `onTargetReached` clears the `messageId` URL param once the
144155
// row is centered). In a channel whose feed doesn't already contain the
145156
// deep-linked message, the spliced event is the only copy — dropping it on
146157
// param-clear blanks the timeline. Resetting on channel / forum-post change
147158
// is handled by the effect below; here we only fetch when there's a target.
148-
if ((!targetMessageId && !targetThreadRootId) || selectedPostId) {
159+
if (!shouldFetchTarget) {
149160
return () => {
150161
isCancelled = true;
151162
};
@@ -167,26 +178,28 @@ export function ChannelRouteScreen({
167178
: null,
168179
].filter((eventId): eventId is string => eventId !== null);
169180

170-
void fetchRouteTargetEvents(
171-
eventIds,
172-
targetMessageId,
173-
targetThreadRootId,
174-
).then((events) => {
175-
if (!isCancelled) {
176-
setTargetMessageEvents((currentEvents) => {
177-
const eventsById = new Map<string, RelayEvent>();
178-
for (const event of [...currentEvents, ...events]) {
179-
eventsById.set(event.id, event);
180-
}
181-
return Array.from(eventsById.values());
182-
});
183-
}
184-
});
181+
void fetchRouteTargetEvents(eventIds, targetMessageId, targetThreadRootId)
182+
.then((events) => {
183+
if (!isCancelled) {
184+
setTargetMessageEvents((currentEvents) => {
185+
const eventsById = new Map<string, RelayEvent>();
186+
for (const event of [...currentEvents, ...events]) {
187+
eventsById.set(event.id, event);
188+
}
189+
return Array.from(eventsById.values());
190+
});
191+
}
192+
})
193+
.finally(() => {
194+
if (!isCancelled) {
195+
setRouteLoadState({ key: routeTargetKey, settled: true });
196+
}
197+
});
185198

186199
return () => {
187200
isCancelled = true;
188201
};
189-
}, [selectedPostId, targetMessageId, targetThreadRootId]);
202+
}, [routeTargetKey, selectedPostId, targetMessageId, targetThreadRootId]);
190203

191204
if (channelsQuery.isPending && !activeChannel) {
192205
if (isHuddleTranscript) {
@@ -216,6 +229,7 @@ export function ChannelRouteScreen({
216229
targetForumReplyId={targetReplyId}
217230
targetMessageEvents={targetMessageEvents}
218231
targetMessageId={targetMessageId}
232+
targetMessageLoadSettled={targetMessageLoadSettled}
219233
/>
220234
);
221235
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as React from "react";
2+
3+
import type { ThreadRailPin } from "./threadRailStorage";
4+
import type { ThreadRail } from "./useThreadRail";
5+
6+
const EMPTY_RAIL: ThreadRail = {
7+
pins: [],
8+
collapsed: false,
9+
isScoped: false,
10+
pin: () => {},
11+
unpin: () => {},
12+
updateAnchor: () => {},
13+
updateExpandedReplyIds: () => {},
14+
toggleCollapsed: () => {},
15+
};
16+
17+
const ThreadRailContext = React.createContext<ThreadRail>(EMPTY_RAIL);
18+
19+
export function ThreadRailProvider({
20+
children,
21+
rail,
22+
}: {
23+
children: React.ReactNode;
24+
rail: ThreadRail;
25+
}) {
26+
return (
27+
<ThreadRailContext.Provider value={rail}>
28+
{children}
29+
</ThreadRailContext.Provider>
30+
);
31+
}
32+
33+
export function useThreadRailContext(): ThreadRail {
34+
return React.useContext(ThreadRailContext);
35+
}
36+
37+
export function makeThreadRailPin({
38+
channelId,
39+
channelName,
40+
expandedReplyIds,
41+
returnAnchorId,
42+
rootExcerpt,
43+
rootId,
44+
}: Omit<ThreadRailPin, "pinnedAt">): ThreadRailPin {
45+
return {
46+
channelId,
47+
channelName,
48+
expandedReplyIds,
49+
returnAnchorId,
50+
rootExcerpt,
51+
rootId,
52+
pinnedAt: Date.now(),
53+
};
54+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import { getThreadRailAnchorUpdate } from "./threadRailAnchor.ts";
5+
6+
const PIN = { channelId: "channel-a", rootId: "root-a", pinnedAt: 100 };
7+
8+
test("returns an anchor update only for a pinned nested reply in the open thread", () => {
9+
assert.deepEqual(
10+
getThreadRailAnchorUpdate([PIN], "channel-a", "root-a", {
11+
id: "nested-a",
12+
rootId: "root-a",
13+
}),
14+
{ pin: PIN, returnAnchorId: "nested-a" },
15+
);
16+
});
17+
18+
test("does not anchor roots, other threads, channels, or unpinned threads", () => {
19+
assert.equal(
20+
getThreadRailAnchorUpdate([PIN], "channel-a", "root-a", {
21+
id: "root-a",
22+
rootId: "root-a",
23+
}),
24+
null,
25+
);
26+
assert.equal(
27+
getThreadRailAnchorUpdate([PIN], "channel-a", "root-a", {
28+
id: "other-thread-reply",
29+
rootId: "root-b",
30+
}),
31+
null,
32+
);
33+
assert.equal(
34+
getThreadRailAnchorUpdate([PIN], "channel-b", "root-a", {
35+
id: "nested-a",
36+
rootId: "root-a",
37+
}),
38+
null,
39+
);
40+
assert.equal(
41+
getThreadRailAnchorUpdate([], "channel-a", "root-a", {
42+
id: "nested-a",
43+
rootId: "root-a",
44+
}),
45+
null,
46+
);
47+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { ThreadRailPin } from "./threadRailStorage";
2+
3+
type ThreadRailAnchorTarget = { id: string; rootId?: string | null };
4+
5+
/** Returns a local nested reply anchor only when it belongs to a pinned open thread. */
6+
export function getThreadRailAnchorUpdate(
7+
pins: ThreadRailPin[],
8+
channelId: string | null,
9+
rootId: string | null,
10+
target: ThreadRailAnchorTarget,
11+
): { pin: ThreadRailPin; returnAnchorId: string } | null {
12+
if (
13+
!channelId ||
14+
!rootId ||
15+
target.id === rootId ||
16+
target.rootId !== rootId
17+
) {
18+
return null;
19+
}
20+
const pin = pins.find(
21+
(candidate) =>
22+
candidate.channelId === channelId && candidate.rootId === rootId,
23+
);
24+
return pin ? { pin, returnAnchorId: target.id } : null;
25+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import {
5+
isThreadRailVisible,
6+
projectThreadRailLayout,
7+
threadRailEntryClassName,
8+
threadRailHeaderClassName,
9+
threadRailShellClassName,
10+
} from "./threadRailLayout.ts";
11+
12+
test("isThreadRailVisible hides the rail at and below the desktop breakpoint", () => {
13+
assert.equal(isThreadRailVisible(600, 1), false);
14+
assert.equal(isThreadRailVisible(599, 1), false);
15+
assert.equal(isThreadRailVisible(601, 1), true);
16+
assert.equal(isThreadRailVisible(601, 0), false);
17+
});
18+
19+
test("Thread Rail uses one native rounded surface at the content bounds", () => {
20+
for (const collapsed of [false, true]) {
21+
const className = threadRailShellClassName(collapsed);
22+
23+
assert.match(className, /mt-px/);
24+
assert.match(className, /mb-2/);
25+
assert.match(className, /h-\[calc\(100%-0\.5625rem\)\]/);
26+
assert.match(className, /self-start/);
27+
assert.match(className, /rounded-2xl/);
28+
assert.match(className, /overflow-hidden/);
29+
assert.match(className, /bg-background(?!\/)/);
30+
assert.match(className, /shadow-content-edge/);
31+
assert.match(className, /ring-border\/30/);
32+
assert.match(className, /ring-inset/);
33+
assert.doesNotMatch(className, /clip-path/);
34+
assert.doesNotMatch(className, /self-stretch/);
35+
assert.doesNotMatch(className, /\bmy-2\b/);
36+
}
37+
});
38+
39+
test("Thread Rail header and rows use native panel density and one full-width selection surface", () => {
40+
const headerClassName = threadRailHeaderClassName();
41+
assert.match(headerClassName, /min-h-13/);
42+
assert.doesNotMatch(headerClassName, /border-b/);
43+
44+
const idleEntryClassName = threadRailEntryClassName(false);
45+
const activeEntryClassName = threadRailEntryClassName(true);
46+
assert.match(idleEntryClassName, /rounded-lg/);
47+
assert.match(idleEntryClassName, /hover:bg-muted/);
48+
assert.match(activeEntryClassName, /bg-muted/);
49+
});
50+
51+
test("projectThreadRailLayout keeps pin count and exposes collapse state", () => {
52+
const pins = [
53+
{ channelId: "channel-a", rootId: "root-a", pinnedAt: 100 },
54+
{ channelId: "channel-b", rootId: "root-b", pinnedAt: 200 },
55+
];
56+
57+
assert.deepEqual(projectThreadRailLayout({ collapsed: false, pins }, 800), {
58+
visible: true,
59+
pinCount: 2,
60+
collapsed: false,
61+
collapseControl: { expanded: true, label: "Collapse pinned threads" },
62+
});
63+
assert.deepEqual(projectThreadRailLayout({ collapsed: true, pins }, 800), {
64+
visible: true,
65+
pinCount: 2,
66+
collapsed: true,
67+
collapseControl: { expanded: false, label: "Expand 2 pinned threads" },
68+
});
69+
});

0 commit comments

Comments
 (0)