Skip to content

Commit da6e1a9

Browse files
t3dotggclaude
andauthored
feat(sidebar-v2): thread pinning for sidebar v2 (pingdotgg#5312)
Co-authored-by: Claude Fable 5 <[email protected]>
1 parent 8eca200 commit da6e1a9

32 files changed

Lines changed: 1180 additions & 80 deletions

‎apps/mobile/src/components/AppSymbol.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ import {
5050
IconMinus,
5151
IconNetwork,
5252
IconPalette,
53+
IconPin,
54+
IconPinnedOff,
5355
IconPlayerPlay,
5456
IconPlayerStopFilled,
5557
IconPlus,
@@ -121,6 +123,8 @@ const ANDROID_ICON_BY_SF_SYMBOL: Partial<Record<SFSymbol, Icon>> = {
121123
magnifyingglass: IconSearch,
122124
paintbrush: IconPalette,
123125
"person.crop.circle": IconUserCircle,
126+
pin: IconPin,
127+
"pin.slash": IconPinnedOff,
124128
play: IconPlayerPlay,
125129
plus: IconPlus,
126130
"qrcode.viewfinder": IconQrcode,

‎apps/mobile/src/features/home/HomeRouteScreen.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export function HomeRouteScreen() {
4242
settleThread,
4343
snoozeThread,
4444
unsnoozeThread,
45+
pinThread,
46+
unpinThread,
4547
unsettleThread,
4648
} = useThreadListActions();
4749
const pendingTasks = usePendingNewTasks();
@@ -155,6 +157,8 @@ export function HomeRouteScreen() {
155157
onSnoozeThread={snoozeThread}
156158
onUnsnoozeThread={unsnoozeThread}
157159
onUnsettleThread={unsettleThread}
160+
onPinThread={pinThread}
161+
onUnpinThread={unpinThread}
158162
onEnvironmentChange={setSelectedEnvironmentId}
159163
onProjectChange={setSelectedProjectKey}
160164
onOpenEnvironments={() =>

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ interface HomeScreenProps {
111111
) => Promise<boolean>;
112112
readonly onUnsnoozeThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
113113
readonly onUnsettleThread: (thread: EnvironmentThreadShell) => void;
114+
readonly onPinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
115+
readonly onUnpinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
114116
readonly onSelectPendingTask: (pendingTask: PendingNewTask) => void;
115117
readonly onDeletePendingTask: (pendingTask: PendingNewTask) => void;
116118
readonly onNewThreadInProject: (project: EnvironmentProject) => void;
@@ -516,6 +518,18 @@ export function HomeScreen(props: HomeScreenProps) {
516518
},
517519
[props.onUnsnoozeThread],
518520
);
521+
const handlePinThread = useCallback(
522+
(thread: EnvironmentThreadShell) => {
523+
void props.onPinThread(thread);
524+
},
525+
[props.onPinThread],
526+
);
527+
const handleUnpinThread = useCallback(
528+
(thread: EnvironmentThreadShell) => {
529+
void props.onUnpinThread(thread);
530+
},
531+
[props.onUnpinThread],
532+
);
519533
const handleDeleteThread = props.onDeleteThread;
520534
const handleUnsettleThread = props.onUnsettleThread;
521535
// The settled tail renders in pages; expansion resets when the filter
@@ -575,6 +589,15 @@ export function HomeScreen(props: HomeScreenProps) {
575589
}
576590
return supported;
577591
}, [serverConfigs]);
592+
const pinningEnvironmentIds = useMemo(() => {
593+
const supported = new Set<EnvironmentId>();
594+
for (const [environmentId, config] of serverConfigs) {
595+
if (config.environment.capabilities.threadPinning === true) {
596+
supported.add(environmentId);
597+
}
598+
}
599+
return supported;
600+
}, [serverConfigs]);
578601
const threadListV2Layout = useMemo(() => {
579602
if (!threadListV2Enabled)
580603
return {
@@ -718,6 +741,7 @@ export function HomeScreen(props: HomeScreenProps) {
718741
thread={thread}
719742
variant={item.item.variant}
720743
snoozed={item.item.snoozed}
744+
pinned={item.item.pinned}
721745
snoozePresetMinute={nowMinute}
722746
snoozeWakeLabelText={item.snoozeWakeLabelText}
723747
project={
@@ -753,9 +777,12 @@ export function HomeScreen(props: HomeScreenProps) {
753777
settlementSupported={settlementEnvironmentIds.has(thread.environmentId)}
754778
onSettleThread={handleSettleThread}
755779
snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)}
780+
pinningSupported={pinningEnvironmentIds.has(thread.environmentId)}
756781
onSnoozeThread={handleSnoozeThread}
757782
onUnsnoozeThread={handleUnsnoozeThread}
758783
onUnsettleThread={handleUnsettleThread}
784+
onPinThread={handlePinThread}
785+
onUnpinThread={handleUnpinThread}
759786
onChangeRequestState={handleChangeRequestState}
760787
projectCwd={
761788
projectCwdByKey.get(scopedProjectKey(thread.environmentId, thread.projectId)) ?? null
@@ -768,12 +795,15 @@ export function HomeScreen(props: HomeScreenProps) {
768795
[
769796
handleChangeRequestState,
770797
handleDeleteThread,
798+
handlePinThread,
771799
handleSettleThread,
772800
handleSnoozeThread,
801+
handleUnpinThread,
773802
handleUnsnoozeThread,
774803
handleSwipeableClose,
775804
handleSwipeableWillOpen,
776805
handleUnsettleThread,
806+
pinningEnvironmentIds,
777807
projectByKey,
778808
projectCwdByKey,
779809
props.onArchiveThread,

‎apps/mobile/src/features/home/useThreadListActions.ts‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ function environmentSupportsSnooze(environmentId: EnvironmentThreadShell["enviro
2929
);
3030
}
3131

32+
function environmentSupportsPinning(environmentId: EnvironmentThreadShell["environmentId"]) {
33+
return (
34+
appAtomRegistry.get(environmentServerConfigsAtom).get(environmentId)?.environment.capabilities
35+
.threadPinning === true
36+
);
37+
}
38+
3239
type ThreadListAction = "archive" | "unarchive" | "delete" | "settle" | "unsettle";
3340

3441
const ACTION_VERBS: Record<ThreadListAction, string> = {
@@ -202,10 +209,14 @@ export function useThreadListActions(): {
202209
readonly snoozeThread: (thread: EnvironmentThreadShell, snoozedUntil: string) => Promise<boolean>;
203210
readonly unsnoozeThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
204211
readonly unsettleThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
212+
readonly pinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
213+
readonly unpinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
205214
} {
206215
const executeAction = useThreadActionExecutor();
207216
const snoozeMutation = useAtomCommand(threadEnvironment.snooze, { reportFailure: false });
208217
const unsnoozeMutation = useAtomCommand(threadEnvironment.unsnooze, { reportFailure: false });
218+
const pinMutation = useAtomCommand(threadEnvironment.pin, { reportFailure: false });
219+
const unpinMutation = useAtomCommand(threadEnvironment.unpin, { reportFailure: false });
209220
const snoozeInFlightThreadKeys = useRef(new Set<string>());
210221

211222
const archiveThread = useCallback(
@@ -310,6 +321,62 @@ export function useThreadListActions(): {
310321
async (thread: EnvironmentThreadShell) => (await executeAction("unsettle", thread)) === true,
311322
[executeAction],
312323
);
324+
const pinThread = useCallback(
325+
async (thread: EnvironmentThreadShell) => {
326+
if (!environmentSupportsPinning(thread.environmentId)) {
327+
Alert.alert(
328+
"Could not pin thread",
329+
"This environment's server does not support pinning yet. Update the server to use Pin.",
330+
);
331+
return false;
332+
}
333+
selectionHaptic();
334+
const result = await pinMutation({
335+
environmentId: thread.environmentId,
336+
input: { threadId: thread.id },
337+
});
338+
if (result._tag === "Failure") {
339+
const error = Cause.squash(result.cause);
340+
Alert.alert(
341+
"Could not pin thread",
342+
error instanceof Error && error.message.trim().length > 0
343+
? error.message
344+
: "The thread could not be pinned.",
345+
);
346+
return false;
347+
}
348+
return true;
349+
},
350+
[pinMutation],
351+
);
352+
const unpinThread = useCallback(
353+
async (thread: EnvironmentThreadShell) => {
354+
if (!environmentSupportsPinning(thread.environmentId)) {
355+
Alert.alert(
356+
"Could not unpin thread",
357+
"This environment's server does not support pinning yet. Update the server to use Pin.",
358+
);
359+
return false;
360+
}
361+
selectionHaptic();
362+
const result = await unpinMutation({
363+
environmentId: thread.environmentId,
364+
input: { threadId: thread.id },
365+
});
366+
if (result._tag === "Failure") {
367+
const error = Cause.squash(result.cause);
368+
Alert.alert(
369+
"Could not unpin thread",
370+
error instanceof Error && error.message.trim().length > 0
371+
? error.message
372+
: "The thread could not be unpinned.",
373+
);
374+
return false;
375+
}
376+
return true;
377+
},
378+
[unpinMutation],
379+
);
313380

314381
const confirmDeleteThread = useConfirmDeleteThread(executeAction);
315382

@@ -320,6 +387,8 @@ export function useThreadListActions(): {
320387
snoozeThread,
321388
unsnoozeThread,
322389
unsettleThread,
390+
pinThread,
391+
unpinThread,
323392
};
324393
}
325394

‎apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ function ThreadNavigationSidebarPane(
205205
snoozeThread,
206206
unsnoozeThread,
207207
unsettleThread,
208+
pinThread,
209+
unpinThread,
208210
} = useThreadListActions();
209211
const threadListV2Enabled = useThreadListV2Enabled();
210212
const pendingTasks = usePendingNewTasks();
@@ -481,6 +483,15 @@ function ThreadNavigationSidebarPane(
481483
}
482484
return supported;
483485
}, [serverConfigs]);
486+
const pinningEnvironmentIds = useMemo(() => {
487+
const supported = new Set<EnvironmentId>();
488+
for (const [environmentId, config] of serverConfigs) {
489+
if (config.environment.capabilities.threadPinning === true) {
490+
supported.add(environmentId);
491+
}
492+
}
493+
return supported;
494+
}, [serverConfigs]);
484495
const threadListV2Layout = useMemo(() => {
485496
if (!threadListV2Enabled)
486497
return {
@@ -792,6 +803,7 @@ function ThreadNavigationSidebarPane(
792803
previous.item.thread === item.item.thread &&
793804
previous.item.variant === item.item.variant &&
794805
previous.item.snoozed === item.item.snoozed &&
806+
previous.item.pinned === item.item.pinned &&
795807
previous.snoozeWakeLabelText === item.snoozeWakeLabelText
796808
);
797809
}
@@ -879,6 +891,7 @@ function ThreadNavigationSidebarPane(
879891
thread={thread}
880892
variant={item.item.variant}
881893
snoozed={item.item.snoozed}
894+
pinned={item.item.pinned}
882895
snoozePresetMinute={nowMinute}
883896
snoozeWakeLabelText={item.snoozeWakeLabelText}
884897
project={projectByKey.get(scopeKey) ?? null}
@@ -915,9 +928,12 @@ function ThreadNavigationSidebarPane(
915928
settlementSupported={settlementEnvironmentIds.has(thread.environmentId)}
916929
onSettleThread={settleThread}
917930
snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)}
931+
pinningSupported={pinningEnvironmentIds.has(thread.environmentId)}
918932
onSnoozeThread={snoozeThread}
919933
onUnsnoozeThread={unsnoozeThread}
920934
onUnsettleThread={unsettleThread}
935+
onPinThread={pinThread}
936+
onUnpinThread={unpinThread}
921937
onChangeRequestState={handleChangeRequestState}
922938
projectCwd={projectCwdByKey.get(scopeKey) ?? null}
923939
onSwipeableClose={handleSwipeableClose}
@@ -1045,6 +1061,8 @@ function ThreadNavigationSidebarPane(
10451061
handleSwipeableClose,
10461062
handleSwipeableWillOpen,
10471063
openPendingTask,
1064+
pinThread,
1065+
pinningEnvironmentIds,
10481066
projectByKey,
10491067
projectCwdByKey,
10501068
projectTitleByProjectKey,
@@ -1064,6 +1082,7 @@ function ThreadNavigationSidebarPane(
10641082
nowMinute,
10651083
toggleSettledShelf,
10661084
toggleSnoozedShelf,
1085+
unpinThread,
10671086
unsettleThread,
10681087
unsnoozeThread,
10691088
updateGroupDisplay,

0 commit comments

Comments
 (0)