Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71bf16596d | ||
|
|
cf2b02f8e9 | ||
|
|
fb1a59e963 | ||
|
|
a74bb10a11 | ||
|
|
120d684da9 | ||
|
|
3e77096713 | ||
|
|
a0b75c6b58 |
No files matched your search
@@ -22,6 +22,7 @@ import {
|
||||
IconChevronUp,
|
||||
IconCircleCheck,
|
||||
IconCircleXFilled,
|
||||
IconClock,
|
||||
IconCopy,
|
||||
IconDeviceDesktop,
|
||||
IconDots,
|
||||
@@ -96,6 +97,7 @@ const ANDROID_ICON_BY_SF_SYMBOL: Partial<Record<SFSymbol, Icon>> = {
|
||||
camera: IconCamera,
|
||||
checkmark: IconCheck,
|
||||
"checkmark.circle": IconCircleCheck,
|
||||
clock: IconClock,
|
||||
"chevron.down": IconChevronDown,
|
||||
"chevron.left": IconChevronLeft,
|
||||
"chevron.left.forwardslash.chevron.right": IconCode,
|
||||
|
||||
@@ -29,8 +29,14 @@ export function HomeRouteScreen() {
|
||||
const { savedConnectionsById } = useSavedRemoteConnections();
|
||||
const navigation = useNavigation();
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const { archiveThread, confirmDeleteThread, settleThread, unsettleThread } =
|
||||
useThreadListActions();
|
||||
const {
|
||||
archiveThread,
|
||||
confirmDeleteThread,
|
||||
settleThread,
|
||||
snoozeThread,
|
||||
unsnoozeThread,
|
||||
unsettleThread,
|
||||
} = useThreadListActions();
|
||||
const pendingTasks = usePendingNewTasks();
|
||||
const { openPendingTask, confirmDeletePendingTask } = usePendingTaskListActions();
|
||||
const environments = useMemo(
|
||||
@@ -135,6 +141,8 @@ export function HomeRouteScreen() {
|
||||
onArchiveThread={archiveThread}
|
||||
onDeleteThread={confirmDeleteThread}
|
||||
onSettleThread={settleThread}
|
||||
onSnoozeThread={snoozeThread}
|
||||
onUnsnoozeThread={unsnoozeThread}
|
||||
onUnsettleThread={unsettleThread}
|
||||
onEnvironmentChange={setSelectedEnvironmentId}
|
||||
onProjectChange={setSelectedProjectKey}
|
||||
|
||||
@@ -35,13 +35,15 @@ import {
|
||||
ThreadListRow,
|
||||
ThreadListShowMoreRow,
|
||||
} from "../threads/thread-list-items";
|
||||
import { ThreadListV2Row } from "../threads/thread-list-v2-items";
|
||||
import { ThreadListV2Row, ThreadListV2SnoozedShelfHeader } from "../threads/thread-list-v2-items";
|
||||
import {
|
||||
buildThreadListV2Items,
|
||||
snoozeWakeLabel,
|
||||
THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
|
||||
THREAD_LIST_V2_SETTLED_PAGE_COUNT,
|
||||
type ThreadListV2Item,
|
||||
} from "../threads/threadListV2";
|
||||
|
||||
import type { HomeListFilterMenuEnvironment } from "./home-list-filter-menu";
|
||||
import {
|
||||
buildHomeListLayout,
|
||||
@@ -64,6 +66,11 @@ import { shouldShowWorkspaceConnectionStatus } from "./workspace-connection-stat
|
||||
|
||||
/* ─── Types ──────────────────────────────────────────────────────────── */
|
||||
|
||||
/** v2 list rows: thread rows plus the standalone snoozed-shelf header. */
|
||||
type ThreadListV2DisplayItem =
|
||||
| { readonly type: "thread"; readonly item: ThreadListV2Item }
|
||||
| { readonly type: "snoozed-shelf-header"; readonly count: number };
|
||||
|
||||
interface HomeScreenProps {
|
||||
readonly projects: ReadonlyArray<EnvironmentProject>;
|
||||
readonly threads: ReadonlyArray<EnvironmentThreadShell>;
|
||||
@@ -91,6 +98,10 @@ interface HomeScreenProps {
|
||||
readonly onDeleteThread: (thread: EnvironmentThreadShell) => void;
|
||||
/** Resolves true iff the settle was dispatched and succeeded. */
|
||||
readonly onSettleThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
|
||||
/** Snoozes for the swipe action's one-hour default. */
|
||||
readonly onSnoozeThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
|
||||
/** Wakes a snoozed thread from the snoozed shelf. */
|
||||
readonly onUnsnoozeThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
|
||||
readonly onUnsettleThread: (thread: EnvironmentThreadShell) => void;
|
||||
readonly onSelectPendingTask: (pendingTask: PendingNewTask) => void;
|
||||
readonly onDeletePendingTask: (pendingTask: PendingNewTask) => void;
|
||||
@@ -451,6 +462,18 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
},
|
||||
[props.onSettleThread],
|
||||
);
|
||||
const handleSnoozeThread = useCallback(
|
||||
(thread: EnvironmentThreadShell) => {
|
||||
void props.onSnoozeThread(thread);
|
||||
},
|
||||
[props.onSnoozeThread],
|
||||
);
|
||||
const handleUnsnoozeThread = useCallback(
|
||||
(thread: EnvironmentThreadShell) => {
|
||||
void props.onUnsnoozeThread(thread);
|
||||
},
|
||||
[props.onUnsnoozeThread],
|
||||
);
|
||||
const handleDeleteThread = props.onDeleteThread;
|
||||
const handleUnsettleThread = props.onUnsettleThread;
|
||||
// The settled tail renders in pages; expansion resets when the filter
|
||||
@@ -468,6 +491,9 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
() => setSettledVisibleCount((count) => count + THREAD_LIST_V2_SETTLED_PAGE_COUNT),
|
||||
[],
|
||||
);
|
||||
// Collapsed by default, like web: the shelf is a shelf, not a second inbox.
|
||||
const [snoozedShelfExpanded, setSnoozedShelfExpanded] = useState(false);
|
||||
const toggleSnoozedShelf = useCallback(() => setSnoozedShelfExpanded((value) => !value), []);
|
||||
// now is quantized to the minute and ticks so the inactivity auto-settle
|
||||
// boundary is actually crossed while the app stays open (mirrors web);
|
||||
// without a clock dependency the partition memoizes a frozen "now".
|
||||
@@ -508,7 +534,13 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
}, [serverConfigs]);
|
||||
const threadListV2Layout = useMemo(() => {
|
||||
if (!threadListV2Enabled)
|
||||
return { items: [], hiddenSettledCount: 0, snoozedCount: 0, nextSnoozeWakeAt: null };
|
||||
return {
|
||||
items: [],
|
||||
hiddenSettledCount: 0,
|
||||
snoozedCount: 0,
|
||||
snoozedShelfHeaderIndex: null,
|
||||
nextSnoozeWakeAt: null,
|
||||
};
|
||||
// Settled threads are live shells; archived threads keep their original
|
||||
// "hidden from lists" meaning.
|
||||
return buildThreadListV2Items({
|
||||
@@ -522,11 +554,16 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
settledLimit: settledVisibleCount,
|
||||
now: `${nowMinute}:00.000Z`,
|
||||
snoozeNow: new Date().toISOString(),
|
||||
snoozedShelfExpanded,
|
||||
// Phones navigate away on select, so no row is ever "open" here — the
|
||||
// collapsed-shelf exception is an iPad split-view concern.
|
||||
selectedThreadKey: null,
|
||||
});
|
||||
}, [
|
||||
changeRequestStateByKey,
|
||||
nowMinute,
|
||||
snoozeWakeTick,
|
||||
snoozedShelfExpanded,
|
||||
settledVisibleCount,
|
||||
settlementEnvironmentIds,
|
||||
snoozeEnvironmentIds,
|
||||
@@ -550,54 +587,98 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
// unchanged: after a clamped fire (wake beyond the 32-bit setTimeout
|
||||
// range) the boundary string is identical and the chain would die.
|
||||
}, [nextSnoozeWakeAt, snoozeWakeTick]);
|
||||
const threadListV2Items = threadListV2Layout.items;
|
||||
// The shelf header is a list row of its own: it must render even when the
|
||||
// shelf is collapsed and has no rows to hang it on.
|
||||
const threadListV2Items = useMemo((): ThreadListV2DisplayItem[] => {
|
||||
const rows: ThreadListV2DisplayItem[] = threadListV2Layout.items.map((item) => ({
|
||||
type: "thread" as const,
|
||||
item,
|
||||
}));
|
||||
const headerIndex = threadListV2Layout.snoozedShelfHeaderIndex;
|
||||
if (headerIndex !== null) {
|
||||
rows.splice(headerIndex, 0, {
|
||||
type: "snoozed-shelf-header",
|
||||
count: threadListV2Layout.snoozedCount,
|
||||
});
|
||||
}
|
||||
return rows;
|
||||
}, [
|
||||
threadListV2Layout.items,
|
||||
threadListV2Layout.snoozedCount,
|
||||
threadListV2Layout.snoozedShelfHeaderIndex,
|
||||
]);
|
||||
|
||||
const renderV2Item = useCallback(
|
||||
({ item }: { readonly item: ThreadListV2Item }) => (
|
||||
<ThreadListV2Row
|
||||
thread={item.thread}
|
||||
variant={item.variant}
|
||||
showSettledDivider={item.showSettledDivider}
|
||||
project={
|
||||
projectByKey.get(scopedProjectKey(item.thread.environmentId, item.thread.projectId)) ??
|
||||
null
|
||||
}
|
||||
projectTitle={v2ProjectTitleByProjectKey.get(
|
||||
scopedProjectKey(item.thread.environmentId, item.thread.projectId),
|
||||
)}
|
||||
providerDriver={
|
||||
serverConfigs
|
||||
.get(item.thread.environmentId)
|
||||
?.providers.find(
|
||||
(provider) =>
|
||||
provider.instanceId ===
|
||||
(item.thread.session?.providerInstanceId ?? item.thread.modelSelection.instanceId),
|
||||
)?.driver ?? null
|
||||
}
|
||||
environmentLabel={
|
||||
Object.keys(props.savedConnectionsById).length > 1
|
||||
? (props.savedConnectionsById[item.thread.environmentId]?.environmentLabel ?? null)
|
||||
: null
|
||||
}
|
||||
onSelectThread={props.onSelectThread}
|
||||
onDeleteThread={handleDeleteThread}
|
||||
onArchiveThread={props.onArchiveThread}
|
||||
settlementSupported={settlementEnvironmentIds.has(item.thread.environmentId)}
|
||||
onSettleThread={handleSettleThread}
|
||||
onUnsettleThread={handleUnsettleThread}
|
||||
onChangeRequestState={handleChangeRequestState}
|
||||
projectCwd={
|
||||
projectCwdByKey.get(scopedProjectKey(item.thread.environmentId, item.thread.projectId)) ??
|
||||
null
|
||||
}
|
||||
onSwipeableClose={handleSwipeableClose}
|
||||
onSwipeableWillOpen={handleSwipeableWillOpen}
|
||||
/>
|
||||
),
|
||||
({ item: displayItem }: { readonly item: ThreadListV2DisplayItem }) => {
|
||||
if (displayItem.type === "snoozed-shelf-header") {
|
||||
return (
|
||||
<ThreadListV2SnoozedShelfHeader
|
||||
count={displayItem.count}
|
||||
expanded={snoozedShelfExpanded}
|
||||
onToggle={toggleSnoozedShelf}
|
||||
/>
|
||||
);
|
||||
}
|
||||
const item = displayItem.item;
|
||||
return (
|
||||
<ThreadListV2Row
|
||||
thread={item.thread}
|
||||
variant={item.variant}
|
||||
showSettledDivider={item.showSettledDivider}
|
||||
snoozed={item.snoozed}
|
||||
snoozeWakeLabelText={
|
||||
item.snoozed && item.thread.snoozedUntil != null
|
||||
? snoozeWakeLabel(item.thread.snoozedUntil, { now: `${nowMinute}:00.000Z` })
|
||||
: undefined
|
||||
}
|
||||
project={
|
||||
projectByKey.get(scopedProjectKey(item.thread.environmentId, item.thread.projectId)) ??
|
||||
null
|
||||
}
|
||||
projectTitle={v2ProjectTitleByProjectKey.get(
|
||||
scopedProjectKey(item.thread.environmentId, item.thread.projectId),
|
||||
)}
|
||||
providerDriver={
|
||||
serverConfigs
|
||||
.get(item.thread.environmentId)
|
||||
?.providers.find(
|
||||
(provider) =>
|
||||
provider.instanceId ===
|
||||
(item.thread.session?.providerInstanceId ??
|
||||
item.thread.modelSelection.instanceId),
|
||||
)?.driver ?? null
|
||||
}
|
||||
environmentLabel={
|
||||
Object.keys(props.savedConnectionsById).length > 1
|
||||
? (props.savedConnectionsById[item.thread.environmentId]?.environmentLabel ?? null)
|
||||
: null
|
||||
}
|
||||
onSelectThread={props.onSelectThread}
|
||||
onDeleteThread={handleDeleteThread}
|
||||
onArchiveThread={props.onArchiveThread}
|
||||
settlementSupported={settlementEnvironmentIds.has(item.thread.environmentId)}
|
||||
onSettleThread={handleSettleThread}
|
||||
snoozeSupported={snoozeEnvironmentIds.has(item.thread.environmentId)}
|
||||
onSnoozeThread={handleSnoozeThread}
|
||||
onUnsnoozeThread={handleUnsnoozeThread}
|
||||
onUnsettleThread={handleUnsettleThread}
|
||||
onChangeRequestState={handleChangeRequestState}
|
||||
projectCwd={
|
||||
projectCwdByKey.get(
|
||||
scopedProjectKey(item.thread.environmentId, item.thread.projectId),
|
||||
) ?? null
|
||||
}
|
||||
onSwipeableClose={handleSwipeableClose}
|
||||
onSwipeableWillOpen={handleSwipeableWillOpen}
|
||||
/>
|
||||
);
|
||||
},
|
||||
[
|
||||
handleChangeRequestState,
|
||||
handleDeleteThread,
|
||||
handleSettleThread,
|
||||
handleSnoozeThread,
|
||||
handleUnsnoozeThread,
|
||||
handleSwipeableClose,
|
||||
handleSwipeableWillOpen,
|
||||
handleUnsettleThread,
|
||||
@@ -608,11 +689,18 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
props.savedConnectionsById,
|
||||
serverConfigs,
|
||||
settlementEnvironmentIds,
|
||||
nowMinute,
|
||||
snoozeEnvironmentIds,
|
||||
snoozedShelfExpanded,
|
||||
toggleSnoozedShelf,
|
||||
v2ProjectTitleByProjectKey,
|
||||
],
|
||||
);
|
||||
const v2KeyExtractor = useCallback(
|
||||
(item: ThreadListV2Item) => `${item.thread.environmentId}:${item.thread.id}`,
|
||||
(item: ThreadListV2DisplayItem) =>
|
||||
item.type === "snoozed-shelf-header"
|
||||
? "snoozed-shelf-header"
|
||||
: `${item.item.thread.environmentId}:${item.item.thread.id}`,
|
||||
[],
|
||||
);
|
||||
|
||||
@@ -845,31 +933,13 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
// Self-contained: v1's listEmpty keys off projectGroups, which ignores the
|
||||
// v2 project scope, so it can be null (results elsewhere) while this list
|
||||
// is empty. Search outranks the scope — "No results" names the actionable
|
||||
// fact when a query is active. Snoozed threads outrank the rest: "No
|
||||
// threads yet" over an inbox that is merely all-snoozed reads as data
|
||||
// loss. Pending tasks render in the header, so the list showing them
|
||||
// isn't empty in the user's eyes.
|
||||
const v2SnoozedCount = threadListV2Layout.snoozedCount;
|
||||
// fact when a query is active. Pending tasks render in the header, so the
|
||||
// list showing them isn't empty in the user's eyes. Snoozed threads need
|
||||
// no empty-state case: the shelf header renders as a list row whenever
|
||||
// anything is snoozed, so an all-snoozed list is never actually empty.
|
||||
const v2ListEmpty =
|
||||
v2PendingTasks.length > 0 ? null : hasSearchQuery ? (
|
||||
v2SnoozedCount > 0 ? (
|
||||
// The snoozed threads already passed this search filter: "No
|
||||
// results" would claim nothing matched when matches are merely
|
||||
// parked.
|
||||
<EmptyState
|
||||
title={
|
||||
v2SnoozedCount === 1 ? "1 matching thread snoozed" : `All matching threads snoozed`
|
||||
}
|
||||
detail={`Threads matching "${props.searchQuery}" are snoozed and return when their wake time passes.`}
|
||||
/>
|
||||
) : (
|
||||
<EmptyState title="No results" detail={`No threads matching "${props.searchQuery}".`} />
|
||||
)
|
||||
) : v2SnoozedCount > 0 ? (
|
||||
<EmptyState
|
||||
title={v2SnoozedCount === 1 ? "1 thread snoozed" : `${v2SnoozedCount} threads snoozed`}
|
||||
detail="Snoozed threads return when their wake time passes."
|
||||
/>
|
||||
<EmptyState title="No results" detail={`No threads matching "${props.searchQuery}".`} />
|
||||
) : v2ScopedProjectGroup !== null ? (
|
||||
<EmptyState
|
||||
title={`No threads in ${v2ScopedProjectGroup.title}`}
|
||||
|
||||
@@ -47,13 +47,57 @@ export const THREAD_SWIPE_SPRING = {
|
||||
stiffness: 330,
|
||||
};
|
||||
|
||||
interface ThreadSwipePrimaryAction {
|
||||
interface ThreadSwipeAction {
|
||||
readonly accessibilityLabel: string;
|
||||
readonly icon: ComponentProps<typeof SymbolView>["name"];
|
||||
readonly label: string;
|
||||
readonly onPress: () => void;
|
||||
}
|
||||
|
||||
interface ThreadSwipeSecondaryAction extends ThreadSwipeAction {
|
||||
readonly backgroundColor: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rows that opt out of a secondary action reveal a single-action tray, so the
|
||||
* open width (and every animation range derived from it) shrinks to one item
|
||||
* instead of leaving an empty slot where Delete used to sit.
|
||||
*/
|
||||
function swipeActionsWidth(hasSecondaryAction: boolean) {
|
||||
return hasSecondaryAction ? THREAD_SWIPE_ACTIONS_WIDTH : ACTION_ITEM_WIDTH;
|
||||
}
|
||||
|
||||
/** `undefined` = v1 default (Delete), `null` = no secondary action at all. */
|
||||
function resolveSecondaryAction(input: {
|
||||
readonly close: () => void;
|
||||
readonly onDelete: () => void;
|
||||
readonly secondaryAction: ThreadSwipeAction | null | undefined;
|
||||
readonly threadTitle: string;
|
||||
}): ThreadSwipeSecondaryAction | null {
|
||||
if (input.secondaryAction === null) return null;
|
||||
if (input.secondaryAction === undefined) {
|
||||
return {
|
||||
accessibilityLabel: `Delete ${input.threadTitle}`,
|
||||
backgroundColor: "#ff2d55",
|
||||
icon: "trash",
|
||||
label: "Delete",
|
||||
onPress: () => {
|
||||
input.close();
|
||||
input.onDelete();
|
||||
},
|
||||
};
|
||||
}
|
||||
const action = input.secondaryAction;
|
||||
return {
|
||||
...action,
|
||||
backgroundColor: "#5856d6",
|
||||
onPress: () => {
|
||||
input.close();
|
||||
action.onPress();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Delivers the scroll gate to swipeables via context so that flipping it does
|
||||
* NOT re-render whole rows: putting the flag in list extraData/renderItem deps
|
||||
@@ -183,7 +227,15 @@ export function ThreadSwipeable(props: {
|
||||
readonly onDelete: () => void;
|
||||
readonly onSwipeableClose?: (methods: SwipeableMethods) => void;
|
||||
readonly onSwipeableWillOpen?: (methods: SwipeableMethods) => void;
|
||||
readonly primaryAction: ThreadSwipePrimaryAction;
|
||||
readonly primaryAction: ThreadSwipeAction;
|
||||
/**
|
||||
* Second action revealed nearest the row edge. Omitted (`undefined`) keeps
|
||||
* the v1 default of a destructive Delete; explicit `null` opts out of a
|
||||
* secondary action entirely and reveals a single-action tray — the two must
|
||||
* stay distinguishable so gating an optional action can never fall back to
|
||||
* an unadvertised Delete.
|
||||
*/
|
||||
readonly secondaryAction?: ThreadSwipeAction | null;
|
||||
/**
|
||||
* Identity of the content being wrapped. When a recycled list reuses this
|
||||
* component for a different item, the swipeable snaps back to closed so an
|
||||
@@ -197,7 +249,12 @@ export function ThreadSwipeable(props: {
|
||||
}) {
|
||||
const swipeableRef = useRef<SwipeableMethods | null>(null);
|
||||
const fullSwipeArmedRef = useRef(false);
|
||||
const fullSwipeThreshold = Math.max(THREAD_SWIPE_ACTIONS_WIDTH + 44, props.fullSwipeWidth * 0.58);
|
||||
const hasSecondaryAction = props.secondaryAction !== null;
|
||||
const actionsWidth = swipeActionsWidth(hasSecondaryAction);
|
||||
const fullSwipeThreshold = Math.max(actionsWidth + 44, props.fullSwipeWidth * 0.58);
|
||||
// With no secondary action there is no Delete button to stretch or commit,
|
||||
// so a full swipe can only mean the primary action.
|
||||
const fullSwipeAction = hasSecondaryAction ? (props.fullSwipeAction ?? "delete") : "primary";
|
||||
const close = useCallback(() => swipeableRef.current?.close(), []);
|
||||
const gateEnabled = use(SwipeableScrollGateContext);
|
||||
const resetKey = props.resetKey;
|
||||
@@ -251,7 +308,7 @@ export function ThreadSwipeable(props: {
|
||||
if (fullSwipeArmedRef.current) {
|
||||
fullSwipeArmedRef.current = false;
|
||||
methods.close();
|
||||
if (props.fullSwipeAction === "primary") {
|
||||
if (fullSwipeAction === "primary") {
|
||||
props.primaryAction.onPress();
|
||||
} else {
|
||||
props.onDelete();
|
||||
@@ -264,9 +321,8 @@ export function ThreadSwipeable(props: {
|
||||
<ThreadSwipeActions
|
||||
backgroundColor={props.backgroundColor}
|
||||
compact={props.compactActions === true}
|
||||
fullSwipeAction={props.fullSwipeAction ?? "delete"}
|
||||
fullSwipeAction={fullSwipeAction}
|
||||
fullSwipeThreshold={fullSwipeThreshold}
|
||||
onDelete={props.onDelete}
|
||||
onFullSwipeArmedChange={handleFullSwipeArmedChange}
|
||||
primaryAction={{
|
||||
...props.primaryAction,
|
||||
@@ -275,12 +331,16 @@ export function ThreadSwipeable(props: {
|
||||
props.primaryAction.onPress();
|
||||
},
|
||||
}}
|
||||
swipeableMethods={methods}
|
||||
threadTitle={props.threadTitle}
|
||||
secondaryAction={resolveSecondaryAction({
|
||||
close: () => methods.close(),
|
||||
onDelete: props.onDelete,
|
||||
secondaryAction: props.secondaryAction,
|
||||
threadTitle: props.threadTitle,
|
||||
})}
|
||||
translation={translation}
|
||||
/>
|
||||
)}
|
||||
rightThreshold={THREAD_SWIPE_ACTIONS_WIDTH * 0.42}
|
||||
rightThreshold={actionsWidth * 0.42}
|
||||
simultaneousWithExternalGesture={props.simultaneousWithExternalGesture}
|
||||
>
|
||||
{props.children(close)}
|
||||
@@ -290,6 +350,9 @@ export function ThreadSwipeable(props: {
|
||||
|
||||
function SwipeActionButton(props: {
|
||||
readonly accessibilityLabel: string;
|
||||
/** Width of the whole action tray — the point past which a swipe stretches
|
||||
* the committing button instead of revealing more of it. */
|
||||
readonly actionsWidth: number;
|
||||
readonly backgroundColor: string;
|
||||
readonly compact: boolean;
|
||||
readonly entryRange: readonly [number, number];
|
||||
@@ -305,10 +368,10 @@ function SwipeActionButton(props: {
|
||||
const actionStyle = useAnimatedStyle(() => {
|
||||
const reveal = Math.max(-props.translation.value, 0);
|
||||
const entryProgress = interpolate(reveal, props.entryRange, [0, 1], Extrapolation.CLAMP);
|
||||
const stretch = Math.max(reveal - THREAD_SWIPE_ACTIONS_WIDTH, 0);
|
||||
const stretch = Math.max(reveal - props.actionsWidth, 0);
|
||||
const fullSwipeProgress = interpolate(
|
||||
reveal,
|
||||
[THREAD_SWIPE_ACTIONS_WIDTH, props.fullSwipeThreshold + 20],
|
||||
[props.actionsWidth, props.fullSwipeThreshold + 20],
|
||||
[0, 1],
|
||||
Extrapolation.CLAMP,
|
||||
);
|
||||
@@ -327,9 +390,7 @@ function SwipeActionButton(props: {
|
||||
});
|
||||
const circleStyle = useAnimatedStyle(() => {
|
||||
const reveal = Math.max(-props.translation.value, 0);
|
||||
const stretch = props.stretchesOnFullSwipe
|
||||
? Math.max(reveal - THREAD_SWIPE_ACTIONS_WIDTH, 0)
|
||||
: 0;
|
||||
const stretch = props.stretchesOnFullSwipe ? Math.max(reveal - props.actionsWidth, 0) : 0;
|
||||
|
||||
return {
|
||||
transform: [{ translateX: -stretch }],
|
||||
@@ -338,9 +399,7 @@ function SwipeActionButton(props: {
|
||||
});
|
||||
const iconStyle = useAnimatedStyle(() => {
|
||||
const reveal = Math.max(-props.translation.value, 0);
|
||||
const stretch = props.stretchesOnFullSwipe
|
||||
? Math.max(reveal - THREAD_SWIPE_ACTIONS_WIDTH, 0)
|
||||
: 0;
|
||||
const stretch = props.stretchesOnFullSwipe ? Math.max(reveal - props.actionsWidth, 0) : 0;
|
||||
const armedProgress = interpolate(
|
||||
reveal,
|
||||
[props.fullSwipeThreshold, props.fullSwipeThreshold + 20],
|
||||
@@ -358,7 +417,7 @@ function SwipeActionButton(props: {
|
||||
}
|
||||
|
||||
const reveal = Math.max(-props.translation.value, 0);
|
||||
const stretch = Math.max(reveal - THREAD_SWIPE_ACTIONS_WIDTH, 0);
|
||||
const stretch = Math.max(reveal - props.actionsWidth, 0);
|
||||
return {
|
||||
opacity: interpolate(
|
||||
reveal,
|
||||
@@ -446,14 +505,17 @@ export function ThreadSwipeActions(props: {
|
||||
readonly compact: boolean;
|
||||
readonly fullSwipeAction?: "delete" | "primary";
|
||||
readonly fullSwipeThreshold: number;
|
||||
readonly onDelete: () => void;
|
||||
readonly onFullSwipeArmedChange: (armed: boolean) => void;
|
||||
readonly primaryAction: ThreadSwipePrimaryAction;
|
||||
readonly swipeableMethods: SwipeableMethods;
|
||||
readonly threadTitle: string;
|
||||
readonly primaryAction: ThreadSwipeAction;
|
||||
/** Null renders a single-action tray — no second button, no Delete. */
|
||||
readonly secondaryAction: ThreadSwipeSecondaryAction | null;
|
||||
readonly translation: SharedValue<number>;
|
||||
}) {
|
||||
const fullSwipeIsPrimary = props.fullSwipeAction === "primary";
|
||||
const secondaryAction = props.secondaryAction;
|
||||
// Without a secondary action the primary is the only thing that can stretch
|
||||
// and commit on full swipe, whatever the caller asked for.
|
||||
const fullSwipeIsPrimary = props.fullSwipeAction === "primary" || secondaryAction === null;
|
||||
const actionsWidth = swipeActionsWidth(secondaryAction !== null);
|
||||
useAnimatedReaction(
|
||||
() => -props.translation.value >= props.fullSwipeThreshold,
|
||||
(armed, previous) => {
|
||||
@@ -470,14 +532,21 @@ export function ThreadSwipeActions(props: {
|
||||
backgroundColor: props.backgroundColor,
|
||||
flexDirection: "row",
|
||||
height: "100%",
|
||||
width: THREAD_SWIPE_ACTIONS_WIDTH,
|
||||
width: actionsWidth,
|
||||
}}
|
||||
>
|
||||
<SwipeActionButton
|
||||
accessibilityLabel={props.primaryAction.accessibilityLabel}
|
||||
actionsWidth={actionsWidth}
|
||||
backgroundColor="#007aff"
|
||||
compact={props.compact}
|
||||
entryRange={[ACTION_ITEM_WIDTH * 0.55, THREAD_SWIPE_ACTIONS_WIDTH * 0.85]}
|
||||
// The lone button sits at the row edge, so it enters on the same
|
||||
// ramp the secondary would have used.
|
||||
entryRange={
|
||||
secondaryAction === null
|
||||
? [8, ACTION_ITEM_WIDTH * 0.72]
|
||||
: [ACTION_ITEM_WIDTH * 0.55, THREAD_SWIPE_ACTIONS_WIDTH * 0.85]
|
||||
}
|
||||
fullSwipeThreshold={props.fullSwipeThreshold}
|
||||
icon={props.primaryAction.icon}
|
||||
label={props.primaryAction.label}
|
||||
@@ -485,21 +554,21 @@ export function ThreadSwipeActions(props: {
|
||||
stretchesOnFullSwipe={fullSwipeIsPrimary}
|
||||
translation={props.translation}
|
||||
/>
|
||||
<SwipeActionButton
|
||||
accessibilityLabel={`Delete ${props.threadTitle}`}
|
||||
backgroundColor="#ff2d55"
|
||||
compact={props.compact}
|
||||
entryRange={[8, ACTION_ITEM_WIDTH * 0.72]}
|
||||
fullSwipeThreshold={props.fullSwipeThreshold}
|
||||
icon="trash"
|
||||
label="Delete"
|
||||
onPress={() => {
|
||||
props.swipeableMethods.close();
|
||||
props.onDelete();
|
||||
}}
|
||||
stretchesOnFullSwipe={!fullSwipeIsPrimary}
|
||||
translation={props.translation}
|
||||
/>
|
||||
{secondaryAction === null ? null : (
|
||||
<SwipeActionButton
|
||||
accessibilityLabel={secondaryAction.accessibilityLabel}
|
||||
actionsWidth={actionsWidth}
|
||||
backgroundColor={secondaryAction.backgroundColor}
|
||||
compact={props.compact}
|
||||
entryRange={[8, ACTION_ITEM_WIDTH * 0.72]}
|
||||
fullSwipeThreshold={props.fullSwipeThreshold}
|
||||
icon={secondaryAction.icon}
|
||||
label={secondaryAction.label}
|
||||
onPress={secondaryAction.onPress}
|
||||
stretchesOnFullSwipe={!fullSwipeIsPrimary}
|
||||
translation={props.translation}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
|
||||
import { canSettle } from "@t3tools/client-runtime/state/thread-settled";
|
||||
import { canSettle, canSnooze } from "@t3tools/client-runtime/state/thread-settled";
|
||||
import * as Cause from "effect/Cause";
|
||||
import * as Haptics from "expo-haptics";
|
||||
import { useCallback, useRef } from "react";
|
||||
@@ -13,6 +13,8 @@ import { environmentServerConfigsAtom } from "../../state/server";
|
||||
import { threadEnvironment } from "../../state/threads";
|
||||
import { useAtomCommand } from "../../state/use-atom-command";
|
||||
|
||||
const SWIPE_SNOOZE_DURATION_MS = 60 * 60 * 1_000;
|
||||
|
||||
/** Version skew: never send settle/unsettle to a server that predates them
|
||||
(capability defaults false on decode for older servers). */
|
||||
function environmentSupportsSettlement(environmentId: EnvironmentThreadShell["environmentId"]) {
|
||||
@@ -22,6 +24,13 @@ function environmentSupportsSettlement(environmentId: EnvironmentThreadShell["en
|
||||
);
|
||||
}
|
||||
|
||||
function environmentSupportsSnooze(environmentId: EnvironmentThreadShell["environmentId"]) {
|
||||
return (
|
||||
appAtomRegistry.get(environmentServerConfigsAtom).get(environmentId)?.environment.capabilities
|
||||
.threadSnooze === true
|
||||
);
|
||||
}
|
||||
|
||||
type ThreadListAction = "archive" | "unarchive" | "delete" | "settle" | "unsettle";
|
||||
|
||||
const ACTION_VERBS: Record<ThreadListAction, string> = {
|
||||
@@ -192,9 +201,17 @@ export function useThreadListActions(): {
|
||||
readonly archiveThread: (thread: EnvironmentThreadShell) => void;
|
||||
readonly confirmDeleteThread: (thread: EnvironmentThreadShell) => void;
|
||||
readonly settleThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
|
||||
readonly snoozeThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
|
||||
readonly unsnoozeThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
|
||||
readonly unsettleThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
|
||||
} {
|
||||
const executeAction = useThreadActionExecutor();
|
||||
const snoozeMutation = useAtomCommand(threadEnvironment.snooze, { reportFailure: false });
|
||||
const unsnoozeMutation = useAtomCommand(threadEnvironment.unsnooze, { reportFailure: false });
|
||||
// Same double-tap guard executeAction gives the other lifecycle actions:
|
||||
// without it a rapid second Wake/Snooze tap queues a duplicate command and,
|
||||
// on failure, stacks one alert per tap.
|
||||
const snoozeInFlightKeys = useRef(new Set<string>());
|
||||
|
||||
const archiveThread = useCallback(
|
||||
(thread: EnvironmentThreadShell) => {
|
||||
@@ -206,6 +223,94 @@ export function useThreadListActions(): {
|
||||
async (thread: EnvironmentThreadShell) => (await executeAction("settle", thread)) === true,
|
||||
[executeAction],
|
||||
);
|
||||
const snoozeThread = useCallback(
|
||||
async (thread: EnvironmentThreadShell) => {
|
||||
const key = scopedThreadKey(thread.environmentId, thread.id);
|
||||
if (snoozeInFlightKeys.current.has(key)) return false;
|
||||
if (!environmentSupportsSnooze(thread.environmentId)) {
|
||||
Alert.alert(
|
||||
"Could not snooze thread",
|
||||
"This environment's server does not support snoozing yet. Update the server to use Snooze.",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (!canSnooze(thread, { now: new Date().toISOString() })) {
|
||||
// canSnooze refuses for two unrelated reasons; naming the wrong one
|
||||
// sends the user looking for a request that isn't there.
|
||||
Alert.alert(
|
||||
"Could not snooze thread",
|
||||
thread.hasPendingApprovals || thread.hasPendingUserInput
|
||||
? "This thread is waiting on you. Respond to the pending request before snoozing it."
|
||||
: "This thread is still starting a turn. Try again once it's running.",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
snoozeInFlightKeys.current.add(key);
|
||||
selectionHaptic();
|
||||
try {
|
||||
const result = await snoozeMutation({
|
||||
environmentId: thread.environmentId,
|
||||
input: {
|
||||
threadId: thread.id,
|
||||
snoozedUntil: new Date(Date.now() + SWIPE_SNOOZE_DURATION_MS).toISOString(),
|
||||
},
|
||||
});
|
||||
if (result._tag === "Failure") {
|
||||
const error = Cause.squash(result.cause);
|
||||
Alert.alert(
|
||||
"Could not snooze thread",
|
||||
error instanceof Error && error.message.trim().length > 0
|
||||
? error.message
|
||||
: "The thread could not be snoozed.",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} finally {
|
||||
snoozeInFlightKeys.current.delete(key);
|
||||
}
|
||||
},
|
||||
[snoozeMutation],
|
||||
);
|
||||
// Waking has no client-side precondition (canSnooze guards the way IN, not
|
||||
// the way OUT) — a thread the user can see on the shelf can always wake.
|
||||
const unsnoozeThread = useCallback(
|
||||
async (thread: EnvironmentThreadShell) => {
|
||||
const key = scopedThreadKey(thread.environmentId, thread.id);
|
||||
if (snoozeInFlightKeys.current.has(key)) return false;
|
||||
if (!environmentSupportsSnooze(thread.environmentId)) {
|
||||
Alert.alert(
|
||||
"Could not wake thread",
|
||||
"This environment's server does not support snoozing yet. Update the server to wake this thread.",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
snoozeInFlightKeys.current.add(key);
|
||||
selectionHaptic();
|
||||
try {
|
||||
const result = await unsnoozeMutation({
|
||||
environmentId: thread.environmentId,
|
||||
input: { threadId: thread.id, reason: "user" },
|
||||
});
|
||||
if (result._tag === "Failure") {
|
||||
const error = Cause.squash(result.cause);
|
||||
Alert.alert(
|
||||
"Could not wake thread",
|
||||
error instanceof Error && error.message.trim().length > 0
|
||||
? error.message
|
||||
: "The thread could not be woken.",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} finally {
|
||||
snoozeInFlightKeys.current.delete(key);
|
||||
}
|
||||
},
|
||||
[unsnoozeMutation],
|
||||
);
|
||||
const unsettleThread = useCallback(
|
||||
async (thread: EnvironmentThreadShell) => (await executeAction("unsettle", thread)) === true,
|
||||
[executeAction],
|
||||
@@ -213,7 +318,14 @@ export function useThreadListActions(): {
|
||||
|
||||
const confirmDeleteThread = useConfirmDeleteThread(executeAction);
|
||||
|
||||
return { archiveThread, confirmDeleteThread, settleThread, unsettleThread };
|
||||
return {
|
||||
archiveThread,
|
||||
confirmDeleteThread,
|
||||
settleThread,
|
||||
snoozeThread,
|
||||
unsnoozeThread,
|
||||
unsettleThread,
|
||||
};
|
||||
}
|
||||
|
||||
export function useArchivedThreadListActions(
|
||||
|
||||
@@ -63,9 +63,10 @@ import {
|
||||
ThreadListRow,
|
||||
ThreadListShowMoreRow,
|
||||
} from "./thread-list-items";
|
||||
import { ThreadListV2Row } from "./thread-list-v2-items";
|
||||
import { ThreadListV2Row, ThreadListV2SnoozedShelfHeader } from "./thread-list-v2-items";
|
||||
import {
|
||||
buildThreadListV2Items,
|
||||
snoozeWakeLabel,
|
||||
THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
|
||||
THREAD_LIST_V2_SETTLED_PAGE_COUNT,
|
||||
type ThreadListV2Item,
|
||||
@@ -82,7 +83,20 @@ type SidebarListItem =
|
||||
readonly pendingTask: PendingNewTask;
|
||||
readonly isLast: boolean;
|
||||
}
|
||||
| { readonly type: "v2-thread"; readonly key: string; readonly item: ThreadListV2Item }
|
||||
| {
|
||||
readonly type: "v2-thread";
|
||||
readonly key: string;
|
||||
readonly item: ThreadListV2Item;
|
||||
/** Precomputed against the minute tick so the row comparator can see
|
||||
the countdown change; undefined for non-snoozed rows. */
|
||||
readonly snoozeWakeLabelText: string | undefined;
|
||||
}
|
||||
| {
|
||||
readonly type: "v2-snoozed-shelf-header";
|
||||
readonly key: string;
|
||||
readonly count: number;
|
||||
readonly expanded: boolean;
|
||||
}
|
||||
| { readonly type: "v2-show-more"; readonly key: string; readonly hiddenCount: number };
|
||||
|
||||
/**
|
||||
@@ -194,8 +208,14 @@ function ThreadNavigationSidebarPane(
|
||||
const openSwipeableRef = useRef<SwipeableMethods | null>(null);
|
||||
const headerIsOverContentRef = useRef(false);
|
||||
const sidebarScrollGesture = useMemo(() => Gesture.Native(), []);
|
||||
const { archiveThread, confirmDeleteThread, settleThread, unsettleThread } =
|
||||
useThreadListActions();
|
||||
const {
|
||||
archiveThread,
|
||||
confirmDeleteThread,
|
||||
settleThread,
|
||||
snoozeThread,
|
||||
unsnoozeThread,
|
||||
unsettleThread,
|
||||
} = useThreadListActions();
|
||||
const preferencesResult = useAtomValue(mobilePreferencesAtom);
|
||||
const threadListV2Enabled =
|
||||
AsyncResult.isSuccess(preferencesResult) &&
|
||||
@@ -395,6 +415,9 @@ function ThreadNavigationSidebarPane(
|
||||
() => setSettledVisibleCount((count) => count + THREAD_LIST_V2_SETTLED_PAGE_COUNT),
|
||||
[],
|
||||
);
|
||||
// Collapsed by default, like web: the shelf is a shelf, not a second inbox.
|
||||
const [snoozedShelfExpanded, setSnoozedShelfExpanded] = useState(false);
|
||||
const toggleSnoozedShelf = useCallback(() => setSnoozedShelfExpanded((value) => !value), []);
|
||||
// now ticks per minute so the inactivity auto-settle boundary is actually
|
||||
// crossed while the pane stays open; without a clock dependency the
|
||||
// partition memoizes a frozen "now".
|
||||
@@ -435,7 +458,13 @@ function ThreadNavigationSidebarPane(
|
||||
}, [serverConfigs]);
|
||||
const threadListV2Layout = useMemo(() => {
|
||||
if (!threadListV2Enabled)
|
||||
return { items: [], hiddenSettledCount: 0, snoozedCount: 0, nextSnoozeWakeAt: null };
|
||||
return {
|
||||
items: [],
|
||||
hiddenSettledCount: 0,
|
||||
snoozedCount: 0,
|
||||
snoozedShelfHeaderIndex: null,
|
||||
nextSnoozeWakeAt: null,
|
||||
};
|
||||
return buildThreadListV2Items({
|
||||
threads: threads.filter((thread) => thread.archivedAt === null),
|
||||
environmentId: options.selectedEnvironmentId,
|
||||
@@ -447,11 +476,17 @@ function ThreadNavigationSidebarPane(
|
||||
settledLimit: settledVisibleCount,
|
||||
now: `${nowMinute}:00.000Z`,
|
||||
snoozeNow: new Date().toISOString(),
|
||||
snoozedShelfExpanded,
|
||||
// Split view keeps a thread open beside the list: a snoozed one must
|
||||
// keep its row (and its Wake action) even while the shelf is closed.
|
||||
selectedThreadKey: props.selectedThreadKey ?? null,
|
||||
});
|
||||
}, [
|
||||
changeRequestStateByKey,
|
||||
nowMinute,
|
||||
snoozeWakeTick,
|
||||
snoozedShelfExpanded,
|
||||
props.selectedThreadKey,
|
||||
options.selectedEnvironmentId,
|
||||
props.searchQuery,
|
||||
settledVisibleCount,
|
||||
@@ -500,13 +535,28 @@ function ThreadNavigationSidebarPane(
|
||||
pendingTask,
|
||||
isLast: index === v2PendingTasks.length - 1,
|
||||
}));
|
||||
for (const item of threadListV2Layout.items) {
|
||||
items.push({
|
||||
type: "v2-thread" as const,
|
||||
key: scopedThreadKey(item.thread.environmentId, item.thread.id),
|
||||
item,
|
||||
const snoozeLabelNow = `${nowMinute}:00.000Z`;
|
||||
const threadRows: SidebarListItem[] = threadListV2Layout.items.map((item) => ({
|
||||
type: "v2-thread" as const,
|
||||
key: scopedThreadKey(item.thread.environmentId, item.thread.id),
|
||||
item,
|
||||
snoozeWakeLabelText:
|
||||
item.snoozed && item.thread.snoozedUntil != null
|
||||
? snoozeWakeLabel(item.thread.snoozedUntil, { now: snoozeLabelNow })
|
||||
: undefined,
|
||||
}));
|
||||
// The shelf header is a row of its own: collapsed, it IS the shelf, so
|
||||
// it has no thread row to hang off. splice() handles the all-snoozed
|
||||
// case (index lands at the end) without a separate branch.
|
||||
if (threadListV2Layout.snoozedShelfHeaderIndex !== null) {
|
||||
threadRows.splice(threadListV2Layout.snoozedShelfHeaderIndex, 0, {
|
||||
type: "v2-snoozed-shelf-header",
|
||||
key: "v2-snoozed-shelf-header",
|
||||
count: threadListV2Layout.snoozedCount,
|
||||
expanded: snoozedShelfExpanded,
|
||||
});
|
||||
}
|
||||
items.push(...threadRows);
|
||||
if (threadListV2Layout.hiddenSettledCount > 0) {
|
||||
items.push({
|
||||
type: "v2-show-more",
|
||||
@@ -517,10 +567,12 @@ function ThreadNavigationSidebarPane(
|
||||
return items;
|
||||
}, [
|
||||
listLayout.items,
|
||||
nowMinute,
|
||||
options.selectedEnvironmentId,
|
||||
pendingTasks,
|
||||
props.searchQuery,
|
||||
selectedProjectRefs,
|
||||
snoozedShelfExpanded,
|
||||
threadListV2Enabled,
|
||||
threadListV2Layout,
|
||||
]);
|
||||
@@ -709,12 +761,23 @@ function ThreadNavigationSidebarPane(
|
||||
previous.key === item.key &&
|
||||
previous.item.thread === item.item.thread &&
|
||||
previous.item.variant === item.item.variant &&
|
||||
previous.item.showSettledDivider === item.item.showSettledDivider
|
||||
previous.item.showSettledDivider === item.item.showSettledDivider &&
|
||||
// A timer wake is derived from the clock, not from new data: the
|
||||
// shell reference and variant can both be unchanged while the row
|
||||
// stops being snoozed. Without this the woken row keeps its blue
|
||||
// countdown and Wake action.
|
||||
previous.item.snoozed === item.item.snoozed &&
|
||||
// Same reason for the countdown text: it changes on the minute
|
||||
// tick while every other field holds still.
|
||||
previous.snoozeWakeLabelText === item.snoozeWakeLabelText
|
||||
);
|
||||
}
|
||||
if (previous.type === "v2-show-more" && item.type === "v2-show-more") {
|
||||
return previous.hiddenCount === item.hiddenCount;
|
||||
}
|
||||
if (previous.type === "v2-snoozed-shelf-header" && item.type === "v2-snoozed-shelf-header") {
|
||||
return previous.count === item.count && previous.expanded === item.expanded;
|
||||
}
|
||||
if (previous.type === "v2-pending-task" && item.type === "v2-pending-task") {
|
||||
return previous.pendingTask === item.pendingTask && previous.isLast === item.isLast;
|
||||
}
|
||||
@@ -722,9 +785,11 @@ function ThreadNavigationSidebarPane(
|
||||
previous.type === "v2-thread" ||
|
||||
previous.type === "v2-show-more" ||
|
||||
previous.type === "v2-pending-task" ||
|
||||
previous.type === "v2-snoozed-shelf-header" ||
|
||||
item.type === "v2-thread" ||
|
||||
item.type === "v2-show-more" ||
|
||||
item.type === "v2-pending-task"
|
||||
item.type === "v2-pending-task" ||
|
||||
item.type === "v2-snoozed-shelf-header"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
@@ -774,6 +839,8 @@ function ThreadNavigationSidebarPane(
|
||||
thread={thread}
|
||||
variant={item.item.variant}
|
||||
showSettledDivider={item.item.showSettledDivider}
|
||||
snoozed={item.item.snoozed}
|
||||
snoozeWakeLabelText={item.snoozeWakeLabelText}
|
||||
project={projectByKey.get(scopeKey) ?? null}
|
||||
projectTitle={projectTitleByProjectKey.get(scopeKey)}
|
||||
providerDriver={
|
||||
@@ -800,6 +867,9 @@ function ThreadNavigationSidebarPane(
|
||||
onArchiveThread={archiveThread}
|
||||
settlementSupported={settlementEnvironmentIds.has(thread.environmentId)}
|
||||
onSettleThread={settleThread}
|
||||
snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)}
|
||||
onSnoozeThread={snoozeThread}
|
||||
onUnsnoozeThread={unsnoozeThread}
|
||||
onUnsettleThread={unsettleThread}
|
||||
onChangeRequestState={handleChangeRequestState}
|
||||
projectCwd={projectCwdByKey.get(scopeKey) ?? null}
|
||||
@@ -809,6 +879,15 @@ function ThreadNavigationSidebarPane(
|
||||
/>
|
||||
);
|
||||
}
|
||||
case "v2-snoozed-shelf-header":
|
||||
return (
|
||||
<ThreadListV2SnoozedShelfHeader
|
||||
count={item.count}
|
||||
expanded={item.expanded}
|
||||
onToggle={toggleSnoozedShelf}
|
||||
pane="sidebar"
|
||||
/>
|
||||
);
|
||||
case "v2-show-more":
|
||||
return (
|
||||
<Pressable
|
||||
@@ -915,7 +994,11 @@ function ThreadNavigationSidebarPane(
|
||||
settlementEnvironmentIds,
|
||||
showMoreSettled,
|
||||
sidebarScrollGesture,
|
||||
snoozeEnvironmentIds,
|
||||
snoozeThread,
|
||||
toggleSnoozedShelf,
|
||||
unsettleThread,
|
||||
unsnoozeThread,
|
||||
updateGroupDisplay,
|
||||
],
|
||||
);
|
||||
@@ -962,28 +1045,17 @@ function ThreadNavigationSidebarPane(
|
||||
}),
|
||||
[filterIcon, filterMenu, props.onOpenSettings],
|
||||
);
|
||||
// "No threads yet" over an inbox that is merely all-snoozed reads as
|
||||
// data loss; name the snoozed threads instead.
|
||||
const snoozedCount = threadListV2Layout.snoozedCount;
|
||||
// Snoozed threads need no case here: the shelf header renders as a list
|
||||
// row whenever anything is snoozed, so an all-snoozed pane is never empty.
|
||||
const listEmpty = (
|
||||
<Text className="px-2 py-4 text-sm text-foreground-muted">
|
||||
{catalogState.isLoadingConnections
|
||||
? "Loading threads…"
|
||||
: props.searchQuery.trim().length > 0
|
||||
? snoozedCount > 0
|
||||
? // Snoozed matches passed this same search filter — "No
|
||||
// matching threads" would misreport them as nonexistent.
|
||||
snoozedCount === 1
|
||||
? "1 matching thread snoozed"
|
||||
: "All matching threads snoozed"
|
||||
: "No matching threads"
|
||||
: snoozedCount > 0
|
||||
? snoozedCount === 1
|
||||
? "1 thread snoozed"
|
||||
: `${snoozedCount} threads snoozed`
|
||||
: selectedProjectScope !== null
|
||||
? `No threads in ${selectedProjectScope.title}`
|
||||
: "No threads yet"}
|
||||
? "No matching threads"
|
||||
: selectedProjectScope !== null
|
||||
? `No threads in ${selectedProjectScope.title}`
|
||||
: "No threads yet"}
|
||||
</Text>
|
||||
);
|
||||
|
||||
|
||||
@@ -2,11 +2,13 @@ import type {
|
||||
EnvironmentProject,
|
||||
EnvironmentThreadShell,
|
||||
} from "@t3tools/client-runtime/state/shell";
|
||||
import { canSnooze } from "@t3tools/client-runtime/state/thread-settled";
|
||||
import type { MenuAction } from "@react-native-menu/menu";
|
||||
import { memo, useCallback, useEffect, useMemo, type ComponentProps } from "react";
|
||||
import { Platform, Pressable, useWindowDimensions, View } from "react-native";
|
||||
import { memo, useCallback, useEffect, useMemo, useState, type ComponentProps } from "react";
|
||||
import { Platform, Pressable, useColorScheme, useWindowDimensions, View } from "react-native";
|
||||
import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
|
||||
|
||||
import { SymbolView } from "../../components/AppSymbol";
|
||||
import { AppText as Text } from "../../components/AppText";
|
||||
import { ControlPillMenu } from "../../components/ControlPill";
|
||||
import { ProjectFavicon } from "../../components/ProjectFavicon";
|
||||
@@ -16,7 +18,12 @@ import { relativeTime } from "../../lib/time";
|
||||
import { useThemeColor } from "../../lib/useThemeColor";
|
||||
import { useThreadPr } from "../../state/use-thread-pr";
|
||||
import { ThreadSwipeable } from "../home/thread-swipe-actions";
|
||||
import { resolveThreadListV2Status, type ThreadListV2Status } from "./threadListV2";
|
||||
import {
|
||||
resolveThreadListV2SnoozeGateExpiryMs,
|
||||
resolveThreadListV2Status,
|
||||
resolveThreadListV2SwipeActions,
|
||||
type ThreadListV2Status,
|
||||
} from "./threadListV2";
|
||||
|
||||
/**
|
||||
* Thread List v2 renders one flat native list: rich edge-to-edge rows for
|
||||
@@ -59,6 +66,12 @@ const SLIM_MENU_ACTIONS: MenuAction[] = [
|
||||
{ id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
|
||||
];
|
||||
|
||||
// Snoozed rows wake instead of settling — the thread is parked, not done.
|
||||
const SNOOZED_MENU_ACTIONS: MenuAction[] = [
|
||||
{ id: "unsnooze", title: "Wake thread", image: "clock" },
|
||||
{ id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
|
||||
];
|
||||
|
||||
// Pre-settlement servers: no lifecycle items, archive fills the gap.
|
||||
const LEGACY_MENU_ACTIONS: MenuAction[] = [
|
||||
{ id: "archive", title: "Archive", image: "archivebox" },
|
||||
@@ -85,10 +98,63 @@ export const ThreadListV2SettledDivider = memo(function ThreadListV2SettledDivid
|
||||
);
|
||||
});
|
||||
|
||||
// SymbolView takes a literal tint, so the shelf chevron can't ride the
|
||||
// blue-600/blue-400 Tailwind pair the label uses. Same values, resolved here.
|
||||
const SNOOZE_ACCENT_LIGHT = "#2563eb";
|
||||
const SNOOZE_ACCENT_DARK = "#60a5fa";
|
||||
|
||||
/**
|
||||
* Snoozed shelf header: tappable, showing the count while collapsed so the
|
||||
* shelf's whole footprint is one line. Mirrors web's snoozed shelf toggle —
|
||||
* parked work stays reachable without competing with the inbox.
|
||||
*/
|
||||
export const ThreadListV2SnoozedShelfHeader = memo(function ThreadListV2SnoozedShelfHeader(props: {
|
||||
readonly count: number;
|
||||
readonly expanded: boolean;
|
||||
readonly onToggle: () => void;
|
||||
readonly pane?: "screen" | "sidebar";
|
||||
}) {
|
||||
const colorScheme = useColorScheme();
|
||||
return (
|
||||
<Pressable
|
||||
accessibilityHint={
|
||||
props.expanded ? "Collapses the snoozed threads." : "Expands the snoozed threads."
|
||||
}
|
||||
accessibilityLabel={props.count === 1 ? "1 snoozed thread" : `${props.count} snoozed threads`}
|
||||
accessibilityRole="button"
|
||||
accessibilityState={{ expanded: props.expanded }}
|
||||
className={cn(
|
||||
"mb-1.5 mt-4 flex-row items-center gap-2.5",
|
||||
props.pane === "sidebar" ? "px-3" : "px-5",
|
||||
)}
|
||||
onPress={props.onToggle}
|
||||
style={({ pressed }) => ({ opacity: pressed ? 0.6 : 1 })}
|
||||
>
|
||||
<Text className="text-xs font-t3-medium text-blue-600 dark:text-blue-400">
|
||||
{props.expanded ? "Snoozed" : `Snoozed (${props.count})`}
|
||||
</Text>
|
||||
<View className="h-px flex-1 bg-blue-500/20 dark:bg-blue-400/15" />
|
||||
<SymbolView
|
||||
name={props.expanded ? "chevron.up" : "chevron.down"}
|
||||
size={10}
|
||||
tintColor={colorScheme === "dark" ? SNOOZE_ACCENT_DARK : SNOOZE_ACCENT_LIGHT}
|
||||
type="monochrome"
|
||||
/>
|
||||
</Pressable>
|
||||
);
|
||||
});
|
||||
|
||||
export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
readonly thread: EnvironmentThreadShell;
|
||||
readonly variant: "card" | "slim";
|
||||
readonly showSettledDivider: boolean;
|
||||
/** Snoozed-shelf row: shows its wake time and offers Wake, not Settle. */
|
||||
readonly snoozed?: boolean;
|
||||
/** Pre-formatted "wakes in" text for snoozed rows. Computed by the parent
|
||||
against its minute tick rather than here: this row is memoized, so a
|
||||
clock read inside it would freeze at first render and the countdown
|
||||
would never move. Mirrors web's snoozeWakeLabelText prop. */
|
||||
readonly snoozeWakeLabelText?: string;
|
||||
readonly project: EnvironmentProject | null;
|
||||
readonly projectTitle?: string;
|
||||
readonly providerDriver: string | null;
|
||||
@@ -111,11 +177,15 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
|
||||
readonly onDeleteThread: (thread: EnvironmentThreadShell) => void;
|
||||
readonly onSettleThread: (thread: EnvironmentThreadShell) => void;
|
||||
readonly onSnoozeThread: (thread: EnvironmentThreadShell) => void;
|
||||
readonly onUnsnoozeThread: (thread: EnvironmentThreadShell) => void;
|
||||
readonly onUnsettleThread: (thread: EnvironmentThreadShell) => void;
|
||||
readonly onArchiveThread: (thread: EnvironmentThreadShell) => void;
|
||||
/** False on environments whose server predates thread.settle/unsettle:
|
||||
swipe + menu fall back to Archive instead of failing on use. */
|
||||
readonly settlementSupported: boolean;
|
||||
/** False on servers that predate thread.snooze/unsnooze. */
|
||||
readonly snoozeSupported: boolean;
|
||||
readonly onSwipeableWillOpen: (methods: SwipeableMethods) => void;
|
||||
readonly onSwipeableClose: (methods: SwipeableMethods) => void;
|
||||
/** Reports this row's live PR state up so the partition can auto-settle
|
||||
@@ -136,10 +206,13 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
onSelectThread,
|
||||
onDeleteThread,
|
||||
onSettleThread,
|
||||
onSnoozeThread,
|
||||
onUnsnoozeThread,
|
||||
onUnsettleThread,
|
||||
onArchiveThread,
|
||||
onChangeRequestState,
|
||||
} = props;
|
||||
const snoozedRow = props.snoozed === true;
|
||||
|
||||
const pr = useThreadPr(thread, props.projectCwd ?? props.project?.workspaceRoot ?? null);
|
||||
const prState = pr?.state ?? null;
|
||||
@@ -161,27 +234,53 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
|
||||
const handleDelete = useCallback(() => onDeleteThread(thread), [onDeleteThread, thread]);
|
||||
const handleSettle = useCallback(() => onSettleThread(thread), [onSettleThread, thread]);
|
||||
const handleSnooze = useCallback(() => onSnoozeThread(thread), [onSnoozeThread, thread]);
|
||||
const handleUnsnooze = useCallback(() => onUnsnoozeThread(thread), [onUnsnoozeThread, thread]);
|
||||
const handleUnsettle = useCallback(() => onUnsettleThread(thread), [onUnsettleThread, thread]);
|
||||
const handleArchive = useCallback(() => onArchiveThread(thread), [onArchiveThread, thread]);
|
||||
const handleMenuAction = useCallback(
|
||||
({ nativeEvent }: { readonly nativeEvent: { readonly event: string } }) => {
|
||||
if (nativeEvent.event === "settle") handleSettle();
|
||||
if (nativeEvent.event === "unsettle") handleUnsettle();
|
||||
if (nativeEvent.event === "unsnooze") handleUnsnooze();
|
||||
if (nativeEvent.event === "archive") handleArchive();
|
||||
if (nativeEvent.event === "delete") handleDelete();
|
||||
},
|
||||
[handleArchive, handleDelete, handleSettle, handleUnsettle],
|
||||
[handleArchive, handleDelete, handleSettle, handleUnsettle, handleUnsnooze],
|
||||
);
|
||||
|
||||
// Swipe: the v2 primary action is the lifecycle transition. Every settled
|
||||
// row can un-settle — explicit settles clear the override, auto-settled
|
||||
// rows get pinned active until real activity clears the pin.
|
||||
const canUnsettle = variant === "slim";
|
||||
// Snooze eligibility is time-gated (a user message no turn has adopted yet
|
||||
// blocks it for the grace window), so the row re-renders itself the moment
|
||||
// that window lapses — otherwise Snooze would stay hidden until unrelated
|
||||
// props changed.
|
||||
const [snoozeGateTick, bumpSnoozeGateTick] = useState(0);
|
||||
const snoozeGateExpiryMs = props.snoozeSupported
|
||||
? resolveThreadListV2SnoozeGateExpiryMs(thread, { now: new Date().toISOString() })
|
||||
: null;
|
||||
useEffect(() => {
|
||||
if (snoozeGateExpiryMs === null) return;
|
||||
const delayMs = Math.min(Math.max(0, snoozeGateExpiryMs - Date.now()) + 50, 2_147_483_647);
|
||||
const id = setTimeout(() => bumpSnoozeGateTick((tick) => tick + 1), delayMs);
|
||||
return () => clearTimeout(id);
|
||||
// snoozeGateTick re-arms after a clamped fire: for a far-future expiry the
|
||||
// boundary is unchanged, so without it the timer chain would stop.
|
||||
}, [snoozeGateExpiryMs, snoozeGateTick]);
|
||||
const swipeActions = resolveThreadListV2SwipeActions({
|
||||
variant,
|
||||
settlementSupported: props.settlementSupported,
|
||||
snoozeSupported: props.snoozeSupported,
|
||||
snoozable: canSnooze(thread, { now: new Date().toISOString() }),
|
||||
snoozed: snoozedRow,
|
||||
});
|
||||
const primaryAction = useMemo(() => {
|
||||
// Pre-settlement server: archive is the swipe action, as in v1. (Slim
|
||||
// rows cannot occur here — unsupported environments never classify as
|
||||
// settled.)
|
||||
if (!props.settlementSupported) {
|
||||
if (swipeActions.primary === "archive") {
|
||||
return {
|
||||
accessibilityLabel: `Archive ${thread.title}`,
|
||||
icon: "archivebox" as const,
|
||||
@@ -189,7 +288,15 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
onPress: handleArchive,
|
||||
};
|
||||
}
|
||||
return canUnsettle
|
||||
if (swipeActions.primary === "unsnooze") {
|
||||
return {
|
||||
accessibilityLabel: `Wake ${thread.title} now`,
|
||||
icon: "clock" as const,
|
||||
label: "Wake",
|
||||
onPress: handleUnsnooze,
|
||||
};
|
||||
}
|
||||
return swipeActions.primary === "unsettle"
|
||||
? {
|
||||
accessibilityLabel: `Un-settle ${thread.title}`,
|
||||
icon: "arrow.uturn.backward" as const,
|
||||
@@ -203,13 +310,29 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
onPress: handleSettle,
|
||||
};
|
||||
}, [
|
||||
canUnsettle,
|
||||
handleArchive,
|
||||
handleSettle,
|
||||
handleUnsettle,
|
||||
props.settlementSupported,
|
||||
handleUnsnooze,
|
||||
swipeActions.primary,
|
||||
thread.title,
|
||||
]);
|
||||
const secondaryAction = useMemo(
|
||||
() =>
|
||||
swipeActions.secondary === "snooze"
|
||||
? {
|
||||
accessibilityLabel: `Snooze ${thread.title} for 1 hour`,
|
||||
icon: "clock" as const,
|
||||
label: "Snooze 1h",
|
||||
onPress: handleSnooze,
|
||||
}
|
||||
: null,
|
||||
[handleSnooze, swipeActions.secondary, thread.title],
|
||||
);
|
||||
const swipeAccessibilityHint =
|
||||
secondaryAction === null
|
||||
? `Opens the thread. Swipe left to ${primaryAction.label.toLowerCase()}.`
|
||||
: `Opens the thread. Swipe left for ${primaryAction.label.toLowerCase()} and snooze actions.`;
|
||||
|
||||
// The sidebar pane fills selected rows with the accent color (matching the
|
||||
// v1 sidebar), so every piece of row text needs a white-on-accent variant.
|
||||
@@ -322,7 +445,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
const rowContent = (close: () => void) =>
|
||||
variant === "card" ? (
|
||||
<Pressable
|
||||
accessibilityHint={`Opens the thread. Swipe left to ${primaryAction.label.toLowerCase()}.`}
|
||||
accessibilityHint={swipeAccessibilityHint}
|
||||
accessibilityLabel={thread.title}
|
||||
accessibilityRole="button"
|
||||
accessibilityState={{ selected }}
|
||||
@@ -360,8 +483,18 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
</Pressable>
|
||||
) : (
|
||||
<Pressable
|
||||
accessibilityHint={`Opens the thread. Swipe left to ${primaryAction.label.toLowerCase()}.`}
|
||||
accessibilityLabel={thread.title}
|
||||
accessibilityHint={swipeAccessibilityHint}
|
||||
// The wake countdown is the row's whole story visually; a screen
|
||||
// reader must hear it too, not just the Wake hint.
|
||||
accessibilityLabel={
|
||||
snoozedRow && props.snoozeWakeLabelText !== undefined
|
||||
? // The label can read "now" for the sliver between the wake
|
||||
// passing and the next re-partition removing the row.
|
||||
props.snoozeWakeLabelText === "now"
|
||||
? `${thread.title}, snoozed, wakes now`
|
||||
: `${thread.title}, snoozed, wakes in ${props.snoozeWakeLabelText}`
|
||||
: thread.title
|
||||
}
|
||||
accessibilityRole="button"
|
||||
accessibilityState={{ selected }}
|
||||
className={sidebarPane ? undefined : "bg-screen"}
|
||||
@@ -408,14 +541,22 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
>
|
||||
{thread.title}
|
||||
</Text>
|
||||
{/* Snoozed rows show when they come BACK, not when they were last
|
||||
touched — the return ticket is the row's whole story. */}
|
||||
<Text
|
||||
className={cn(
|
||||
"text-sm tabular-nums",
|
||||
selected ? "text-user-bubble-foreground-muted" : "text-foreground-tertiary",
|
||||
selected
|
||||
? "text-user-bubble-foreground-muted"
|
||||
: snoozedRow
|
||||
? "text-blue-600 dark:text-blue-400"
|
||||
: "text-foreground-tertiary",
|
||||
)}
|
||||
style={{ fontFamily: MONO_FONT }}
|
||||
>
|
||||
{relativeTime(thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt)}
|
||||
{snoozedRow && props.snoozeWakeLabelText !== undefined
|
||||
? props.snoozeWakeLabelText
|
||||
: relativeTime(thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt)}
|
||||
</Text>
|
||||
</View>
|
||||
</Pressable>
|
||||
@@ -432,13 +573,14 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
}
|
||||
enableTrackpadSwipe
|
||||
// Full swipe commits the advertised lifecycle action (Settle /
|
||||
// Un-settle), never the destructive delete.
|
||||
// Un-settle), never the secondary Snooze action.
|
||||
fullSwipeAction="primary"
|
||||
fullSwipeWidth={props.fullSwipeWidth ?? windowWidth - 32}
|
||||
onDelete={handleDelete}
|
||||
onSwipeableClose={props.onSwipeableClose}
|
||||
onSwipeableWillOpen={props.onSwipeableWillOpen}
|
||||
primaryAction={primaryAction}
|
||||
secondaryAction={secondaryAction}
|
||||
resetKey={`${thread.environmentId}:${thread.id}`}
|
||||
simultaneousWithExternalGesture={props.simultaneousSwipeGesture}
|
||||
threadTitle={thread.title}
|
||||
@@ -446,11 +588,13 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
{(close) => (
|
||||
<ControlPillMenu
|
||||
actions={
|
||||
!props.settlementSupported
|
||||
? LEGACY_MENU_ACTIONS
|
||||
: canUnsettle
|
||||
? SLIM_MENU_ACTIONS
|
||||
: CARD_MENU_ACTIONS
|
||||
snoozedRow
|
||||
? SNOOZED_MENU_ACTIONS
|
||||
: !props.settlementSupported
|
||||
? LEGACY_MENU_ACTIONS
|
||||
: canUnsettle
|
||||
? SLIM_MENU_ACTIONS
|
||||
: CARD_MENU_ACTIONS
|
||||
}
|
||||
onPressAction={handleMenuAction}
|
||||
shouldOpenOnLongPress
|
||||
|
||||
@@ -4,6 +4,8 @@ import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import {
|
||||
buildThreadListV2Items,
|
||||
resolveThreadListV2SnoozeGateExpiryMs,
|
||||
resolveThreadListV2SwipeActions,
|
||||
resolveThreadListV2Status,
|
||||
sortThreadsForListV2,
|
||||
} from "./threadListV2";
|
||||
@@ -65,6 +67,102 @@ describe("resolveThreadListV2Status", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveThreadListV2SwipeActions", () => {
|
||||
it("offers settle and snooze for an active snoozable thread", () => {
|
||||
expect(
|
||||
resolveThreadListV2SwipeActions({
|
||||
variant: "card",
|
||||
settlementSupported: true,
|
||||
snoozeSupported: true,
|
||||
snoozable: true,
|
||||
}),
|
||||
).toEqual({ primary: "settle", secondary: "snooze" });
|
||||
});
|
||||
|
||||
it("offers un-settle and snooze for settled history", () => {
|
||||
expect(
|
||||
resolveThreadListV2SwipeActions({
|
||||
variant: "slim",
|
||||
settlementSupported: true,
|
||||
snoozeSupported: true,
|
||||
snoozable: true,
|
||||
}),
|
||||
).toEqual({ primary: "unsettle", secondary: "snooze" });
|
||||
});
|
||||
|
||||
it("omits snooze when the server or thread does not allow it", () => {
|
||||
expect(
|
||||
resolveThreadListV2SwipeActions({
|
||||
variant: "card",
|
||||
settlementSupported: true,
|
||||
snoozeSupported: false,
|
||||
snoozable: true,
|
||||
}),
|
||||
).toEqual({ primary: "settle", secondary: null });
|
||||
expect(
|
||||
resolveThreadListV2SwipeActions({
|
||||
variant: "card",
|
||||
settlementSupported: true,
|
||||
snoozeSupported: true,
|
||||
snoozable: false,
|
||||
}),
|
||||
).toEqual({ primary: "settle", secondary: null });
|
||||
});
|
||||
|
||||
it("falls back to archive only for a pre-lifecycle server", () => {
|
||||
expect(
|
||||
resolveThreadListV2SwipeActions({
|
||||
variant: "card",
|
||||
settlementSupported: false,
|
||||
snoozeSupported: false,
|
||||
snoozable: true,
|
||||
}),
|
||||
).toEqual({ primary: "archive", secondary: null });
|
||||
});
|
||||
|
||||
it("offers wake and no snooze on a snoozed row", () => {
|
||||
expect(
|
||||
resolveThreadListV2SwipeActions({
|
||||
variant: "slim",
|
||||
settlementSupported: true,
|
||||
snoozeSupported: true,
|
||||
snoozable: true,
|
||||
snoozed: true,
|
||||
}),
|
||||
).toEqual({ primary: "unsnooze", secondary: null });
|
||||
});
|
||||
});
|
||||
|
||||
// snoozeWakeLabel itself is covered in client-runtime, where it lives.
|
||||
|
||||
describe("resolveThreadListV2SnoozeGateExpiryMs", () => {
|
||||
it("reports when an unadopted turn's grace window lapses", () => {
|
||||
const thread = makeThread({
|
||||
id: ThreadId.make("t"),
|
||||
title: "t",
|
||||
latestUserMessageAt: "2026-06-02T00:00:30.000Z",
|
||||
});
|
||||
expect(resolveThreadListV2SnoozeGateExpiryMs(thread, { now: "2026-06-02T00:01:00.000Z" })).toBe(
|
||||
Date.parse("2026-06-02T00:02:30.000Z"),
|
||||
);
|
||||
});
|
||||
|
||||
it("returns null once the thread is already snoozable", () => {
|
||||
const thread = makeThread({ id: ThreadId.make("t"), title: "t" });
|
||||
expect(resolveThreadListV2SnoozeGateExpiryMs(thread, { now: NOW })).toBe(null);
|
||||
});
|
||||
|
||||
it("returns null for threads blocked on the user — only new data clears those", () => {
|
||||
const thread = makeThread({
|
||||
id: ThreadId.make("t"),
|
||||
title: "t",
|
||||
hasPendingApprovals: true,
|
||||
latestUserMessageAt: NOW,
|
||||
});
|
||||
expect(resolveThreadListV2SnoozeGateExpiryMs(thread, { now: NOW })).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe("sortThreadsForListV2", () => {
|
||||
it("orders by creation time, newest first, ignoring activity", () => {
|
||||
const sorted = sortThreadsForListV2([
|
||||
@@ -136,6 +234,95 @@ describe("buildThreadListV2Items", () => {
|
||||
expect(layout.nextSnoozeWakeAt).toBe("2026-06-02T09:00:00.000Z");
|
||||
});
|
||||
|
||||
it("builds snoozed rows between active and settled when the shelf is expanded", () => {
|
||||
const layout = buildThreadListV2Items({
|
||||
threads: [
|
||||
makeThread({ id: ThreadId.make("active"), title: "Active" }),
|
||||
makeThread({
|
||||
id: ThreadId.make("settled"),
|
||||
title: "Settled",
|
||||
settledOverride: "settled",
|
||||
}),
|
||||
makeThread({
|
||||
id: ThreadId.make("later"),
|
||||
title: "Wakes later",
|
||||
snoozedUntil: "2026-06-03T09:00:00.000Z",
|
||||
snoozedAt: "2026-06-01T12:00:00.000Z",
|
||||
}),
|
||||
makeThread({
|
||||
id: ThreadId.make("sooner"),
|
||||
title: "Wakes sooner",
|
||||
snoozedUntil: "2026-06-02T09:00:00.000Z",
|
||||
snoozedAt: "2026-06-01T12:00:00.000Z",
|
||||
}),
|
||||
],
|
||||
environmentId: null,
|
||||
searchQuery: "",
|
||||
now: NOW,
|
||||
snoozedShelfExpanded: true,
|
||||
});
|
||||
|
||||
// Soonest wake first, and the shelf sits between inbox and settled.
|
||||
expect(layout.items.map((item) => item.thread.id)).toEqual([
|
||||
"active",
|
||||
"sooner",
|
||||
"later",
|
||||
"settled",
|
||||
]);
|
||||
expect(layout.items.map((item) => item.snoozed)).toEqual([false, true, true, false]);
|
||||
expect(layout.snoozedShelfHeaderIndex).toBe(1);
|
||||
expect(layout.snoozedCount).toBe(2);
|
||||
});
|
||||
|
||||
it("collapses to a header-only shelf, reporting the index past the last row", () => {
|
||||
const layout = buildThreadListV2Items({
|
||||
threads: [
|
||||
makeThread({
|
||||
id: ThreadId.make("snoozed"),
|
||||
title: "Snoozed",
|
||||
snoozedUntil: "2026-06-03T09:00:00.000Z",
|
||||
snoozedAt: "2026-06-01T12:00:00.000Z",
|
||||
}),
|
||||
],
|
||||
environmentId: null,
|
||||
searchQuery: "",
|
||||
now: NOW,
|
||||
});
|
||||
|
||||
expect(layout.items).toEqual([]);
|
||||
expect(layout.snoozedCount).toBe(1);
|
||||
// Header still renders — the count IS the shelf while collapsed.
|
||||
expect(layout.snoozedShelfHeaderIndex).toBe(0);
|
||||
});
|
||||
|
||||
it("keeps the open thread on a collapsed shelf so it never vanishes", () => {
|
||||
const layout = buildThreadListV2Items({
|
||||
threads: [
|
||||
makeThread({
|
||||
id: ThreadId.make("open"),
|
||||
title: "Open",
|
||||
snoozedUntil: "2026-06-03T09:00:00.000Z",
|
||||
snoozedAt: "2026-06-01T12:00:00.000Z",
|
||||
}),
|
||||
makeThread({
|
||||
id: ThreadId.make("other"),
|
||||
title: "Other",
|
||||
snoozedUntil: "2026-06-03T09:00:00.000Z",
|
||||
snoozedAt: "2026-06-01T12:00:00.000Z",
|
||||
}),
|
||||
],
|
||||
environmentId: null,
|
||||
searchQuery: "",
|
||||
now: NOW,
|
||||
selectedThreadKey: `${environmentId}:open`,
|
||||
});
|
||||
|
||||
expect(layout.items.map((item) => item.thread.id)).toEqual(["open"]);
|
||||
expect(layout.items[0]?.snoozed).toBe(true);
|
||||
// Both still count: the shelf header reports everything parked.
|
||||
expect(layout.snoozedCount).toBe(2);
|
||||
});
|
||||
|
||||
it("keeps snoozed threads visible on environments without the snooze capability", () => {
|
||||
const layout = buildThreadListV2Items({
|
||||
threads: [
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
import { effectiveSettled, effectiveSnoozed } from "@t3tools/client-runtime/state/thread-settled";
|
||||
import {
|
||||
effectiveSettled,
|
||||
effectiveSnoozed,
|
||||
hasQueuedTurnStart,
|
||||
QUEUED_TURN_START_GRACE_MS,
|
||||
} from "@t3tools/client-runtime/state/thread-settled";
|
||||
|
||||
// Wake labels live with the rest of the snooze model so web and mobile can
|
||||
// never drift; re-exported here because this module is the list's one stop.
|
||||
export { snoozeWakeLabel } from "@t3tools/client-runtime/state/thread-settled";
|
||||
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
|
||||
import type { EnvironmentId, ProjectId } from "@t3tools/contracts";
|
||||
|
||||
@@ -11,6 +20,59 @@ import type { EnvironmentId, ProjectId } from "@t3tools/contracts";
|
||||
* unlabeled resting state.
|
||||
*/
|
||||
export type ThreadListV2Status = "approval" | "input" | "working" | "failed" | "ready";
|
||||
export type ThreadListV2SwipeAction = "archive" | "settle" | "unsettle" | "snooze" | "unsnooze";
|
||||
|
||||
export function resolveThreadListV2SwipeActions(input: {
|
||||
readonly variant: "card" | "slim";
|
||||
readonly settlementSupported: boolean;
|
||||
readonly snoozeSupported: boolean;
|
||||
readonly snoozable: boolean;
|
||||
/** Row is on the snoozed shelf. */
|
||||
readonly snoozed?: boolean;
|
||||
}): {
|
||||
readonly primary: Exclude<ThreadListV2SwipeAction, "snooze">;
|
||||
readonly secondary: "snooze" | null;
|
||||
} {
|
||||
// A snoozed row's one lifecycle move is waking: settling parked work is
|
||||
// meaningless, and re-snoozing an already-snoozed thread is a no-op.
|
||||
if (input.snoozed === true) {
|
||||
return { primary: "unsnooze", secondary: null };
|
||||
}
|
||||
const primary = input.settlementSupported
|
||||
? input.variant === "slim"
|
||||
? "unsettle"
|
||||
: "settle"
|
||||
: "archive";
|
||||
return {
|
||||
primary,
|
||||
secondary: input.snoozeSupported && input.snoozable ? "snooze" : null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* When a thread's snooze eligibility can flip on its own, as epoch ms — the
|
||||
* moment the queued-turn-start grace window expires and `canSnooze` starts
|
||||
* returning true. Null when nothing time-based gates it: either the thread is
|
||||
* already snoozable, or it is blocked on the user and only fresh server data
|
||||
* can clear that. Rows arm a one-shot timer on this so an unadopted turn's
|
||||
* Snooze action appears when the grace period lapses instead of waiting for
|
||||
* an unrelated re-render.
|
||||
*/
|
||||
export function resolveThreadListV2SnoozeGateExpiryMs(
|
||||
thread: Pick<
|
||||
EnvironmentThreadShell,
|
||||
"hasPendingApprovals" | "hasPendingUserInput" | "latestUserMessageAt" | "latestTurn" | "session"
|
||||
>,
|
||||
options: { readonly now: string },
|
||||
): number | null {
|
||||
// Blocked-on-user threads are not on a clock — leave them to data updates.
|
||||
if (thread.hasPendingApprovals || thread.hasPendingUserInput) return null;
|
||||
if (!hasQueuedTurnStart(thread, options)) return null;
|
||||
// hasQueuedTurnStart already rejected a null/unparseable message time.
|
||||
const messageAtMs = Date.parse(thread.latestUserMessageAt ?? "");
|
||||
if (Number.isNaN(messageAtMs)) return null;
|
||||
return messageAtMs + QUEUED_TURN_START_GRACE_MS;
|
||||
}
|
||||
|
||||
// Settled-tail paging: recent history is the common lookup; the deep tail
|
||||
// stays behind an explicit Show more. Shared by the compact Home list and
|
||||
@@ -77,6 +139,9 @@ export interface ThreadListV2Item {
|
||||
readonly variant: "card" | "slim";
|
||||
/** First settled row after the card block draws the SETTLED divider. */
|
||||
readonly showSettledDivider: boolean;
|
||||
/** Snoozed-shelf row: renders its wake time instead of its last-activity
|
||||
time, and offers Wake instead of Settle. */
|
||||
readonly snoozed: boolean;
|
||||
readonly isLast: boolean;
|
||||
}
|
||||
|
||||
@@ -84,11 +149,17 @@ export interface ThreadListV2Layout {
|
||||
readonly items: ThreadListV2Item[];
|
||||
/** Settled threads beyond the render limit (behind "Show more"). */
|
||||
readonly hiddenSettledCount: number;
|
||||
/** Snoozed threads hidden from the list (visibility parity with web's
|
||||
collapsed Snoozed shelf; mobile has no shelf UI yet). */
|
||||
/** Snoozed threads matching the current filters. Drives the shelf header,
|
||||
which shows the count while collapsed; rows only build when the shelf
|
||||
is expanded (or for the open thread). */
|
||||
readonly snoozedCount: number;
|
||||
/** Soonest wake time among hidden snoozed threads, or null. Callers arm
|
||||
a timeout at this boundary so the list re-partitions the moment a
|
||||
/** Index in `items` where the snoozed shelf header belongs, or null when
|
||||
nothing is snoozed. Callers splice their own header element in here:
|
||||
the header must render even while the shelf is collapsed (its count is
|
||||
the whole shelf then), so it can't hang off a row flag. */
|
||||
readonly snoozedShelfHeaderIndex: number | null;
|
||||
/** Soonest wake time among snoozed threads, or null. Callers arm a
|
||||
timeout at this boundary so the list re-partitions the moment a
|
||||
snooze expires instead of on the next minute tick. */
|
||||
readonly nextSnoozeWakeAt: string | null;
|
||||
}
|
||||
@@ -126,6 +197,13 @@ export function buildThreadListV2Items(input: {
|
||||
second-precise, so classifying with the floored minute would hold a
|
||||
woken thread hidden for up to a minute. Defaults to `now`. */
|
||||
readonly snoozeNow?: string;
|
||||
/** Expands the snoozed shelf into rows. Collapsed (the default, matching
|
||||
web) the shelf is just its header + count. */
|
||||
readonly snoozedShelfExpanded?: boolean;
|
||||
/** Scoped key ("environmentId:threadId") of the open thread. A snoozed
|
||||
thread reached by route keeps its row even while the shelf is
|
||||
collapsed — the open thread must never vanish behind a shelf. */
|
||||
readonly selectedThreadKey?: string | null;
|
||||
}): ThreadListV2Layout {
|
||||
const now = input.now ?? new Date().toISOString();
|
||||
const snoozeNow = input.snoozeNow ?? now;
|
||||
@@ -137,7 +215,7 @@ export function buildThreadListV2Items(input: {
|
||||
|
||||
const active: EnvironmentThreadShell[] = [];
|
||||
const settled: EnvironmentThreadShell[] = [];
|
||||
let snoozedCount = 0;
|
||||
const snoozed: EnvironmentThreadShell[] = [];
|
||||
let nextSnoozeWakeAt: string | null = null;
|
||||
for (const thread of input.threads) {
|
||||
// Callers pass live (unarchived) shells; settled threads are among them
|
||||
@@ -155,7 +233,7 @@ export function buildThreadListV2Items(input: {
|
||||
// wakes (or raises its hand — effectiveSnoozed refuses blocked/failed
|
||||
// work). Snooze outranks settled classification, same as web.
|
||||
if (supportsSnooze && effectiveSnoozed(thread, { now: snoozeNow })) {
|
||||
snoozedCount += 1;
|
||||
snoozed.push(thread);
|
||||
if (
|
||||
thread.snoozedUntil != null &&
|
||||
(nextSnoozeWakeAt === null ||
|
||||
@@ -176,6 +254,21 @@ export function buildThreadListV2Items(input: {
|
||||
}
|
||||
|
||||
const orderedActive = sortThreadsForListV2(active);
|
||||
// Soonest wake first: the shelf reads as a queue of what comes back next.
|
||||
const orderedSnoozed = [...snoozed].sort(
|
||||
(left, right) =>
|
||||
parseTimestampMs(left.snoozedUntil ?? "") - parseTimestampMs(right.snoozedUntil ?? ""),
|
||||
);
|
||||
const selectedThreadKey = input.selectedThreadKey ?? null;
|
||||
const visibleSnoozed =
|
||||
input.snoozedShelfExpanded === true
|
||||
? orderedSnoozed
|
||||
: // Collapsed: only the open thread survives, so a snoozed thread
|
||||
// opened by deep link (or snoozed from another device while open)
|
||||
// keeps its row and its Wake affordance.
|
||||
orderedSnoozed.filter(
|
||||
(thread) => `${thread.environmentId}:${thread.id}` === selectedThreadKey,
|
||||
);
|
||||
const orderedSettled = [...settled].sort(
|
||||
(left, right) =>
|
||||
firstValidTimestampMs(right.latestUserMessageAt, right.updatedAt) -
|
||||
@@ -187,13 +280,32 @@ export function buildThreadListV2Items(input: {
|
||||
|
||||
const items: ThreadListV2Item[] = [];
|
||||
for (const thread of orderedActive) {
|
||||
items.push({ thread, variant: "card", showSettledDivider: false, isLast: false });
|
||||
items.push({
|
||||
thread,
|
||||
variant: "card",
|
||||
showSettledDivider: false,
|
||||
snoozed: false,
|
||||
isLast: false,
|
||||
});
|
||||
}
|
||||
// Snoozed shelf sits between the inbox and Settled — out of the way,
|
||||
// never gone. Slim like settled rows: parked work, not inbox work.
|
||||
const snoozedShelfHeaderIndex = orderedSnoozed.length > 0 ? items.length : null;
|
||||
for (const thread of visibleSnoozed) {
|
||||
items.push({
|
||||
thread,
|
||||
variant: "slim",
|
||||
showSettledDivider: false,
|
||||
snoozed: true,
|
||||
isLast: false,
|
||||
});
|
||||
}
|
||||
for (const [index, thread] of visibleSettled.entries()) {
|
||||
items.push({
|
||||
thread,
|
||||
variant: "slim",
|
||||
showSettledDivider: index === 0,
|
||||
snoozed: false,
|
||||
isLast: false,
|
||||
});
|
||||
}
|
||||
@@ -204,7 +316,8 @@ export function buildThreadListV2Items(input: {
|
||||
return {
|
||||
items,
|
||||
hiddenSettledCount: orderedSettled.length - visibleSettled.length,
|
||||
snoozedCount,
|
||||
snoozedCount: orderedSnoozed.length,
|
||||
snoozedShelfHeaderIndex,
|
||||
nextSnoozeWakeAt,
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { resolveSnoozePresets, snoozeWakeDescription, snoozeWakeLabel } from "./Sidebar.snooze";
|
||||
import { resolveSnoozePresets, snoozeWakeDescription } from "./Sidebar.snooze";
|
||||
|
||||
// Local-time constructor so preset math is timezone-stable in tests.
|
||||
function localDate(year: number, month: number, day: number, hour: number, minute = 0): Date {
|
||||
@@ -64,20 +64,7 @@ describe("resolveSnoozePresets", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("snoozeWakeLabel", () => {
|
||||
const now = localDate(2026, 4, 8, 10);
|
||||
|
||||
it("formats minutes, hours, and days, rounding up", () => {
|
||||
expect(snoozeWakeLabel(new Date(now.getTime() + 30 * 60_000).toISOString(), now)).toBe("30m");
|
||||
expect(snoozeWakeLabel(new Date(now.getTime() + 90 * 60_000).toISOString(), now)).toBe("2h");
|
||||
expect(snoozeWakeLabel(new Date(now.getTime() + 26 * 3_600_000).toISOString(), now)).toBe("2d");
|
||||
});
|
||||
|
||||
it("reports now for past and malformed wake times", () => {
|
||||
expect(snoozeWakeLabel(new Date(now.getTime() - 1000).toISOString(), now)).toBe("now");
|
||||
expect(snoozeWakeLabel("not-a-date", now)).toBe("now");
|
||||
});
|
||||
});
|
||||
// snoozeWakeLabel now lives in client-runtime and is tested there.
|
||||
|
||||
describe("snoozeWakeDescription", () => {
|
||||
const now = localDate(2026, 4, 8, 10);
|
||||
|
||||
@@ -93,19 +93,8 @@ export function resolveSnoozePresets(now: Date): ReadonlyArray<SnoozePreset> {
|
||||
return presets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compact "wakes in" label for snoozed rows: "2h", "18h", "3d". Minutes
|
||||
* round up so a snooze never reads "0m" while still hidden.
|
||||
*/
|
||||
export function snoozeWakeLabel(snoozedUntil: string, now: Date): string {
|
||||
const wake = parseTimestampDate(snoozedUntil);
|
||||
if (wake === null) return "now";
|
||||
const remainingMs = wake.getTime() - now.getTime();
|
||||
if (remainingMs <= 0) return "now";
|
||||
if (remainingMs < HOUR_MS) return `${Math.max(1, Math.ceil(remainingMs / 60_000))}m`;
|
||||
if (remainingMs < DAY_MS) return `${Math.ceil(remainingMs / HOUR_MS)}h`;
|
||||
return `${Math.ceil(remainingMs / DAY_MS)}d`;
|
||||
}
|
||||
/** Shared with mobile so a wake time never reads differently per platform. */
|
||||
export { snoozeWakeLabel } from "@t3tools/client-runtime/state/thread-settled";
|
||||
|
||||
/**
|
||||
* Human wake time for menus and toasts: "tomorrow 9:00", "Mon 9:00",
|
||||
|
||||
@@ -2417,7 +2417,7 @@ export default function SidebarV2() {
|
||||
}
|
||||
snoozeWakeLabelText={
|
||||
section === "snoozed" && thread.snoozedUntil != null
|
||||
? snoozeWakeLabel(thread.snoozedUntil, new Date())
|
||||
? snoozeWakeLabel(thread.snoozedUntil, { now: new Date().toISOString() })
|
||||
: null
|
||||
}
|
||||
// All sections: a woken thread can classify straight
|
||||
|
||||
@@ -295,3 +295,22 @@ export function effectiveSettled(
|
||||
Date.parse(lastActivityAt) < Date.parse(options.now) - options.autoSettleAfterDays * DAY_MS
|
||||
);
|
||||
}
|
||||
|
||||
const HOUR_MS = 60 * 60 * 1_000;
|
||||
|
||||
/**
|
||||
* Compact "wakes in" label for snoozed rows: "2h", "18h", "3d". Minutes
|
||||
* round up so a snooze never reads "0m" while still hidden. Shared by web's
|
||||
* sidebar and the mobile thread list so a wake time never reads differently
|
||||
* across platforms.
|
||||
*/
|
||||
export function snoozeWakeLabel(snoozedUntil: string, options: { readonly now: string }): string {
|
||||
const wakeMs = Date.parse(snoozedUntil);
|
||||
const nowMs = Date.parse(options.now);
|
||||
if (Number.isNaN(wakeMs) || Number.isNaN(nowMs)) return "now";
|
||||
const remainingMs = wakeMs - nowMs;
|
||||
if (remainingMs <= 0) return "now";
|
||||
if (remainingMs < HOUR_MS) return `${Math.max(1, Math.ceil(remainingMs / 60_000))}m`;
|
||||
if (remainingMs < DAY_MS) return `${Math.ceil(remainingMs / HOUR_MS)}h`;
|
||||
return `${Math.ceil(remainingMs / DAY_MS)}d`;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { describe, expect, it } from "vite-plus/test";
|
||||
import {
|
||||
canSnooze,
|
||||
effectiveSnoozed,
|
||||
snoozeWakeLabel,
|
||||
threadRaisedHandWhileSnoozed,
|
||||
threadWokeAt,
|
||||
type ThreadSnoozeShell,
|
||||
@@ -235,3 +236,20 @@ describe("threadWokeAt", () => {
|
||||
).toBe("2026-04-10T09:30:00.000Z");
|
||||
});
|
||||
});
|
||||
|
||||
describe("snoozeWakeLabel", () => {
|
||||
const now = "2026-06-02T00:00:00.000Z";
|
||||
|
||||
it("formats remaining time coarsely, rounding up", () => {
|
||||
expect(snoozeWakeLabel("2026-06-02T00:30:00.000Z", { now })).toBe("30m");
|
||||
expect(snoozeWakeLabel("2026-06-02T01:30:00.000Z", { now })).toBe("2h");
|
||||
expect(snoozeWakeLabel("2026-06-03T02:00:00.000Z", { now })).toBe("2d");
|
||||
});
|
||||
|
||||
it("never reads zero or negative while still snoozed", () => {
|
||||
expect(snoozeWakeLabel("2026-06-02T00:00:30.000Z", { now })).toBe("1m");
|
||||
expect(snoozeWakeLabel("2026-06-01T23:59:59.000Z", { now })).toBe("now");
|
||||
expect(snoozeWakeLabel("not-a-date", { now })).toBe("now");
|
||||
expect(snoozeWakeLabel("2026-06-02T09:00:00.000Z", { now: "bad" })).toBe("now");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user