Improve mobile thread navigation and diff selection
- Keep sidebar threads swipeable with archive/delete actions - Hide archived threads from navigation groups - Stabilize review diff visibility and optimistic file selection Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
cf0f731bc8
commit
a896942bc7
11 files changed
+336
-188
No files matched your search
@@ -550,6 +550,8 @@ public final class T3ReviewDiffView: ExpoView, UIScrollViewDelegate {
|
||||
}
|
||||
|
||||
self.contentResetKey = contentResetKey
|
||||
tokensDecodeGeneration += 1
|
||||
contentView.tokensByRowId = [:]
|
||||
hasAppliedInitialRowIndex = false
|
||||
lastVisibleFileId = nil
|
||||
pendingScrollFileId = nil
|
||||
@@ -684,8 +686,23 @@ public final class T3ReviewDiffView: ExpoView, UIScrollViewDelegate {
|
||||
// Keep the explicit destination selected while UIKit animates through the files
|
||||
// between the old and new offsets. Emitting every intermediate header forces a
|
||||
// React render per crossing and makes the navigator visibly flash.
|
||||
guard !isProgrammaticScrollActive,
|
||||
let fileId = contentView.visibleFileId(atVerticalOffset: scrollView.contentOffset.y),
|
||||
guard !isProgrammaticScrollActive else {
|
||||
return
|
||||
}
|
||||
|
||||
// The top of the combined diff is the explicit "All files" destination.
|
||||
// Treat it as a first-class selection instead of immediately resolving the
|
||||
// first file header and undoing the navigator's optimistic selection.
|
||||
if scrollView.contentOffset.y <= 0.5 {
|
||||
guard lastVisibleFileId != nil else {
|
||||
return
|
||||
}
|
||||
lastVisibleFileId = nil
|
||||
onVisibleFileChange(["fileId": NSNull()])
|
||||
return
|
||||
}
|
||||
|
||||
guard let fileId = contentView.visibleFileId(atVerticalOffset: scrollView.contentOffset.y),
|
||||
fileId != lastVisibleFileId else {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -81,3 +81,20 @@ describe("resolveNativeReviewDiffView", () => {
|
||||
expect(consoleError).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isPendingNativeViewRegistration", () => {
|
||||
it("recognizes registration races for the installed native view name", async () => {
|
||||
const { isPendingNativeViewRegistration } = await import("./nativeReviewDiffSurface");
|
||||
|
||||
expect(
|
||||
isPendingNativeViewRegistration(
|
||||
new Error("Unable to find the 'T3ReviewDiffSurface' view for this native tag"),
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
isPendingNativeViewRegistration(
|
||||
new Error("Unable to find the 'T3ReviewDiffView' view for this native tag"),
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -124,7 +124,7 @@ export interface NativeReviewDiffViewProps extends ViewProps {
|
||||
readonly nativeViewRef?: Ref<NativeReviewDiffViewHandle>;
|
||||
readonly onDebug?: (event: NativeSyntheticEvent<Record<string, unknown>>) => void;
|
||||
readonly onVisibleFileChange?: (
|
||||
event: NativeSyntheticEvent<{ readonly fileId?: string }>,
|
||||
event: NativeSyntheticEvent<{ readonly fileId?: string | null }>,
|
||||
) => void;
|
||||
readonly onToggleFile?: (event: NativeSyntheticEvent<{ readonly fileId?: string }>) => void;
|
||||
readonly onToggleViewedFile?: (event: NativeSyntheticEvent<{ readonly fileId?: string }>) => void;
|
||||
@@ -166,9 +166,10 @@ let nativeReviewDiffViewResolutionFailed = false;
|
||||
|
||||
type NativeReviewDiffPayloadMethod = "setRowsJson" | "setTokensJson" | "setTokensPatchJson";
|
||||
|
||||
function isPendingNativeViewRegistration(error: unknown): boolean {
|
||||
export function isPendingNativeViewRegistration(error: unknown): boolean {
|
||||
return (
|
||||
error instanceof Error && error.message.includes("Unable to find the 'T3ReviewDiffView' view")
|
||||
error instanceof Error &&
|
||||
error.message.includes(`Unable to find the '${NATIVE_REVIEW_DIFF_MODULE_NAME}' view`)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
const fileTreeCache = new WeakMap<ReadonlyArray<ProjectEntry>, ReadonlyArray<FileTreeNode>>();
|
||||
const FILE_TREE_INITIAL_RENDER_COUNT = 20;
|
||||
const FILE_TREE_RENDER_BATCH_SIZE = 12;
|
||||
const OPTIMISTIC_SELECTION_TIMEOUT_MS = 1_000;
|
||||
|
||||
function cachedFileTree(entries: ReadonlyArray<ProjectEntry>): ReadonlyArray<FileTreeNode> {
|
||||
const cached = fileTreeCache.get(entries);
|
||||
@@ -120,6 +121,7 @@ export function FileTreeBrowser(props: {
|
||||
const iconColor = String(useThemeColor("--color-icon-muted"));
|
||||
const { onPreviewFile, onSelectFile, selectedPath: controlledSelectedPath } = props;
|
||||
const controlledSelectedPathRef = useRef(controlledSelectedPath);
|
||||
const pendingSelectionTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
controlledSelectedPathRef.current = controlledSelectedPath;
|
||||
|
||||
const selectedPath =
|
||||
@@ -164,6 +166,15 @@ export function FileTreeBrowser(props: {
|
||||
});
|
||||
}, [controlledSelectedPath]);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (pendingSelectionTimeoutRef.current !== null) {
|
||||
clearTimeout(pendingSelectionTimeoutRef.current);
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const toggleDirectory = useCallback((path: string) => {
|
||||
setExpandedPaths((current) => {
|
||||
const next = new Set(current);
|
||||
@@ -177,10 +188,17 @@ export function FileTreeBrowser(props: {
|
||||
}, []);
|
||||
const handleSelectFile = useCallback(
|
||||
(path: string) => {
|
||||
if (pendingSelectionTimeoutRef.current !== null) {
|
||||
clearTimeout(pendingSelectionTimeoutRef.current);
|
||||
}
|
||||
setPendingSelection({
|
||||
path,
|
||||
selectedPathAtPress: controlledSelectedPathRef.current,
|
||||
});
|
||||
pendingSelectionTimeoutRef.current = setTimeout(() => {
|
||||
pendingSelectionTimeoutRef.current = null;
|
||||
setPendingSelection((current) => (current?.path === path ? null : current));
|
||||
}, OPTIMISTIC_SELECTION_TIMEOUT_MS);
|
||||
onSelectFile(path);
|
||||
},
|
||||
[onSelectFile],
|
||||
|
||||
@@ -7,13 +7,10 @@ import type {
|
||||
SidebarProjectGroupingMode,
|
||||
SidebarThreadSortOrder,
|
||||
} from "@t3tools/contracts";
|
||||
import * as Haptics from "expo-haptics";
|
||||
import { SymbolView } from "expo-symbols";
|
||||
import { useCallback, useMemo, useRef, useState } from "react";
|
||||
import { ActivityIndicator, Pressable, ScrollView, useWindowDimensions, View } from "react-native";
|
||||
import ReanimatedSwipeable, {
|
||||
type SwipeableMethods,
|
||||
} from "react-native-gesture-handler/ReanimatedSwipeable";
|
||||
import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
|
||||
import Animated, {
|
||||
Easing,
|
||||
LinearTransition,
|
||||
@@ -32,11 +29,7 @@ import type { SavedRemoteConnection } from "../../lib/connection";
|
||||
import { relativeTime } from "../../lib/time";
|
||||
import { threadStatusTone } from "../threads/threadPresentation";
|
||||
import { buildHomeThreadGroups, type HomeProjectSortOrder } from "./homeThreadList";
|
||||
import {
|
||||
THREAD_SWIPE_ACTIONS_WIDTH,
|
||||
THREAD_SWIPE_SPRING,
|
||||
ThreadSwipeActions,
|
||||
} from "./thread-swipe-actions";
|
||||
import { ThreadSwipeable } from "./thread-swipe-actions";
|
||||
|
||||
/* ─── Types ──────────────────────────────────────────────────────────── */
|
||||
|
||||
@@ -219,13 +212,10 @@ function ThreadRow(props: {
|
||||
readonly onSwipeableClose: (methods: SwipeableMethods) => void;
|
||||
readonly isLast: boolean;
|
||||
}) {
|
||||
const swipeableRef = useRef<SwipeableMethods | null>(null);
|
||||
const fullSwipeArmedRef = useRef(false);
|
||||
const { width: windowWidth } = useWindowDimensions();
|
||||
const separatorColor = useThemeColor("--color-separator");
|
||||
const iconSubtleColor = useThemeColor("--color-icon-subtle");
|
||||
const cardColor = useThemeColor("--color-card");
|
||||
const fullSwipeThreshold = Math.max(THREAD_SWIPE_ACTIONS_WIDTH + 44, (windowWidth - 32) * 0.58);
|
||||
const { bg, fg } = statusColors(props.thread);
|
||||
const tone = threadStatusTone(props.thread);
|
||||
const timestamp = relativeTime(
|
||||
@@ -235,150 +225,107 @@ function ThreadRow(props: {
|
||||
const subtitleParts = [props.environmentLabel, branch].filter((part): part is string =>
|
||||
Boolean(part),
|
||||
);
|
||||
const handleFullSwipeArmedChange = useCallback((armed: boolean) => {
|
||||
if (armed && !fullSwipeArmedRef.current && process.env.EXPO_OS === "ios") {
|
||||
void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
|
||||
}
|
||||
fullSwipeArmedRef.current = armed;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ReanimatedSwipeable
|
||||
ref={swipeableRef}
|
||||
animationOptions={THREAD_SWIPE_SPRING}
|
||||
childrenContainerStyle={{ backgroundColor: cardColor }}
|
||||
containerStyle={{ backgroundColor: cardColor }}
|
||||
dragOffsetFromRightEdge={8}
|
||||
enableTrackpadTwoFingerGesture
|
||||
friction={1}
|
||||
onSwipeableClose={() => {
|
||||
fullSwipeArmedRef.current = false;
|
||||
if (swipeableRef.current) {
|
||||
props.onSwipeableClose(swipeableRef.current);
|
||||
}
|
||||
<ThreadSwipeable
|
||||
backgroundColor={cardColor}
|
||||
fullSwipeWidth={windowWidth - 32}
|
||||
onDelete={props.onDelete}
|
||||
onSwipeableClose={props.onSwipeableClose}
|
||||
onSwipeableWillOpen={props.onSwipeableWillOpen}
|
||||
primaryAction={{
|
||||
accessibilityLabel: `Archive ${props.thread.title}`,
|
||||
icon: "archivebox",
|
||||
label: "Archive",
|
||||
onPress: props.onArchive,
|
||||
}}
|
||||
onSwipeableOpenStartDrag={() => {
|
||||
if (swipeableRef.current) {
|
||||
props.onSwipeableWillOpen(swipeableRef.current);
|
||||
}
|
||||
}}
|
||||
onSwipeableWillOpen={() => {
|
||||
const methods = swipeableRef.current;
|
||||
if (!methods) {
|
||||
return;
|
||||
}
|
||||
|
||||
props.onSwipeableWillOpen(methods);
|
||||
if (fullSwipeArmedRef.current) {
|
||||
fullSwipeArmedRef.current = false;
|
||||
methods.close();
|
||||
props.onDelete();
|
||||
}
|
||||
}}
|
||||
overshootFriction={1}
|
||||
overshootRight
|
||||
renderRightActions={(_progress, translation, methods) => (
|
||||
<ThreadSwipeActions
|
||||
backgroundColor={cardColor}
|
||||
fullSwipeThreshold={fullSwipeThreshold}
|
||||
onDelete={props.onDelete}
|
||||
onFullSwipeArmedChange={handleFullSwipeArmedChange}
|
||||
primaryAction={{
|
||||
accessibilityLabel: `Archive ${props.thread.title}`,
|
||||
icon: "archivebox",
|
||||
label: "Archive",
|
||||
onPress: props.onArchive,
|
||||
}}
|
||||
swipeableMethods={methods}
|
||||
threadTitle={props.thread.title}
|
||||
translation={translation}
|
||||
/>
|
||||
)}
|
||||
rightThreshold={THREAD_SWIPE_ACTIONS_WIDTH * 0.42}
|
||||
threadTitle={props.thread.title}
|
||||
>
|
||||
<Pressable
|
||||
accessibilityHint="Swipe left for archive and delete actions"
|
||||
accessibilityLabel={props.thread.title}
|
||||
accessibilityRole="button"
|
||||
className="bg-card"
|
||||
onPress={() => {
|
||||
swipeableRef.current?.close();
|
||||
props.onPress();
|
||||
}}
|
||||
style={({ pressed }) => ({ opacity: pressed ? 0.7 : 1 })}
|
||||
>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
paddingLeft: 16,
|
||||
paddingRight: 16,
|
||||
paddingVertical: 10,
|
||||
gap: 12,
|
||||
borderBottomWidth: props.isLast ? 0 : 1,
|
||||
borderBottomColor: separatorColor,
|
||||
{(close) => (
|
||||
<Pressable
|
||||
accessibilityHint="Swipe left for archive and delete actions"
|
||||
accessibilityLabel={props.thread.title}
|
||||
accessibilityRole="button"
|
||||
className="bg-card"
|
||||
onPress={() => {
|
||||
close();
|
||||
props.onPress();
|
||||
}}
|
||||
style={({ pressed }) => ({ opacity: pressed ? 0.7 : 1 })}
|
||||
>
|
||||
<View
|
||||
style={{
|
||||
width: 30,
|
||||
height: 30,
|
||||
borderRadius: 9,
|
||||
backgroundColor: bg,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
marginTop: 2,
|
||||
flexDirection: "row",
|
||||
paddingLeft: 16,
|
||||
paddingRight: 16,
|
||||
paddingVertical: 10,
|
||||
gap: 12,
|
||||
borderBottomWidth: props.isLast ? 0 : 1,
|
||||
borderBottomColor: separatorColor,
|
||||
}}
|
||||
>
|
||||
<SymbolView name="arrow.triangle.branch" size={13} tintColor={fg} type="monochrome" />
|
||||
</View>
|
||||
|
||||
<View style={{ flex: 1, gap: 3 }}>
|
||||
<View className="flex-row items-center justify-between gap-2">
|
||||
<Text
|
||||
className="flex-1 text-base font-t3-bold leading-[20px] text-foreground"
|
||||
numberOfLines={1}
|
||||
>
|
||||
{props.thread.title}
|
||||
</Text>
|
||||
<View className="flex-row items-center gap-2">
|
||||
<View
|
||||
className={tone.pillClassName}
|
||||
style={{ borderRadius: 99, paddingHorizontal: 6, paddingVertical: 2 }}
|
||||
>
|
||||
<Text className={`text-3xs font-t3-bold ${tone.textClassName}`}>
|
||||
{tone.label}
|
||||
</Text>
|
||||
</View>
|
||||
<Text
|
||||
className="text-xs text-foreground-tertiary"
|
||||
style={{ fontVariant: ["tabular-nums"] }}
|
||||
>
|
||||
{timestamp}
|
||||
</Text>
|
||||
</View>
|
||||
<View
|
||||
style={{
|
||||
width: 30,
|
||||
height: 30,
|
||||
borderRadius: 9,
|
||||
backgroundColor: bg,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
marginTop: 2,
|
||||
}}
|
||||
>
|
||||
<SymbolView name="arrow.triangle.branch" size={13} tintColor={fg} type="monochrome" />
|
||||
</View>
|
||||
|
||||
{subtitleParts.length > 0 ? (
|
||||
<View className="flex-row items-center gap-1.5" style={{ marginTop: 1 }}>
|
||||
<SymbolView
|
||||
name="arrow.triangle.branch"
|
||||
size={10}
|
||||
tintColor={iconSubtleColor}
|
||||
type="monochrome"
|
||||
/>
|
||||
<View style={{ flex: 1, gap: 3 }}>
|
||||
<View className="flex-row items-center justify-between gap-2">
|
||||
<Text
|
||||
className="text-2xs text-foreground-tertiary"
|
||||
className="flex-1 text-base font-t3-bold leading-[20px] text-foreground"
|
||||
numberOfLines={1}
|
||||
style={{ fontFamily: "monospace" }}
|
||||
>
|
||||
{subtitleParts.join(" · ")}
|
||||
{props.thread.title}
|
||||
</Text>
|
||||
<View className="flex-row items-center gap-2">
|
||||
<View
|
||||
className={tone.pillClassName}
|
||||
style={{ borderRadius: 99, paddingHorizontal: 6, paddingVertical: 2 }}
|
||||
>
|
||||
<Text className={`text-3xs font-t3-bold ${tone.textClassName}`}>
|
||||
{tone.label}
|
||||
</Text>
|
||||
</View>
|
||||
<Text
|
||||
className="text-xs text-foreground-tertiary"
|
||||
style={{ fontVariant: ["tabular-nums"] }}
|
||||
>
|
||||
{timestamp}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{subtitleParts.length > 0 ? (
|
||||
<View className="flex-row items-center gap-1.5" style={{ marginTop: 1 }}>
|
||||
<SymbolView
|
||||
name="arrow.triangle.branch"
|
||||
size={10}
|
||||
tintColor={iconSubtleColor}
|
||||
type="monochrome"
|
||||
/>
|
||||
<Text
|
||||
className="text-2xs text-foreground-tertiary"
|
||||
numberOfLines={1}
|
||||
style={{ fontFamily: "monospace" }}
|
||||
>
|
||||
{subtitleParts.join(" · ")}
|
||||
</Text>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</Pressable>
|
||||
</ReanimatedSwipeable>
|
||||
</Pressable>
|
||||
)}
|
||||
</ThreadSwipeable>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { SymbolView } from "expo-symbols";
|
||||
import type { ComponentProps } from "react";
|
||||
import type { ColorValue } from "react-native";
|
||||
import * as Haptics from "expo-haptics";
|
||||
import { useCallback, useRef, type ComponentProps, type ReactNode } from "react";
|
||||
import type { ColorValue, StyleProp, ViewStyle } from "react-native";
|
||||
import { Pressable, View } from "react-native";
|
||||
import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
|
||||
import ReanimatedSwipeable, {
|
||||
type SwipeableMethods,
|
||||
} from "react-native-gesture-handler/ReanimatedSwipeable";
|
||||
import Animated, {
|
||||
Extrapolation,
|
||||
interpolate,
|
||||
@@ -26,6 +29,95 @@ export const THREAD_SWIPE_SPRING = {
|
||||
stiffness: 330,
|
||||
};
|
||||
|
||||
interface ThreadSwipePrimaryAction {
|
||||
readonly accessibilityLabel: string;
|
||||
readonly icon: ComponentProps<typeof SymbolView>["name"];
|
||||
readonly label: string;
|
||||
readonly onPress: () => void;
|
||||
}
|
||||
|
||||
export function ThreadSwipeable(props: {
|
||||
readonly backgroundColor: ColorValue;
|
||||
readonly children: (close: () => void) => ReactNode;
|
||||
readonly containerStyle?: StyleProp<ViewStyle>;
|
||||
readonly fullSwipeWidth: number;
|
||||
readonly onDelete: () => void;
|
||||
readonly onSwipeableClose?: (methods: SwipeableMethods) => void;
|
||||
readonly onSwipeableWillOpen?: (methods: SwipeableMethods) => void;
|
||||
readonly primaryAction: ThreadSwipePrimaryAction;
|
||||
readonly threadTitle: string;
|
||||
}) {
|
||||
const swipeableRef = useRef<SwipeableMethods | null>(null);
|
||||
const fullSwipeArmedRef = useRef(false);
|
||||
const fullSwipeThreshold = Math.max(THREAD_SWIPE_ACTIONS_WIDTH + 44, props.fullSwipeWidth * 0.58);
|
||||
const close = useCallback(() => swipeableRef.current?.close(), []);
|
||||
const handleFullSwipeArmedChange = useCallback((armed: boolean) => {
|
||||
if (armed && !fullSwipeArmedRef.current && process.env.EXPO_OS === "ios") {
|
||||
void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
|
||||
}
|
||||
fullSwipeArmedRef.current = armed;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ReanimatedSwipeable
|
||||
ref={swipeableRef}
|
||||
animationOptions={THREAD_SWIPE_SPRING}
|
||||
childrenContainerStyle={{ backgroundColor: props.backgroundColor }}
|
||||
containerStyle={[{ backgroundColor: props.backgroundColor }, props.containerStyle]}
|
||||
dragOffsetFromRightEdge={8}
|
||||
enableTrackpadTwoFingerGesture
|
||||
friction={1}
|
||||
onSwipeableClose={() => {
|
||||
fullSwipeArmedRef.current = false;
|
||||
if (swipeableRef.current) {
|
||||
props.onSwipeableClose?.(swipeableRef.current);
|
||||
}
|
||||
}}
|
||||
onSwipeableOpenStartDrag={() => {
|
||||
if (swipeableRef.current) {
|
||||
props.onSwipeableWillOpen?.(swipeableRef.current);
|
||||
}
|
||||
}}
|
||||
onSwipeableWillOpen={() => {
|
||||
const methods = swipeableRef.current;
|
||||
if (!methods) {
|
||||
return;
|
||||
}
|
||||
|
||||
props.onSwipeableWillOpen?.(methods);
|
||||
if (fullSwipeArmedRef.current) {
|
||||
fullSwipeArmedRef.current = false;
|
||||
methods.close();
|
||||
props.onDelete();
|
||||
}
|
||||
}}
|
||||
overshootFriction={1}
|
||||
overshootRight
|
||||
renderRightActions={(_progress, translation, methods) => (
|
||||
<ThreadSwipeActions
|
||||
backgroundColor={props.backgroundColor}
|
||||
fullSwipeThreshold={fullSwipeThreshold}
|
||||
onDelete={props.onDelete}
|
||||
onFullSwipeArmedChange={handleFullSwipeArmedChange}
|
||||
primaryAction={{
|
||||
...props.primaryAction,
|
||||
onPress: () => {
|
||||
methods.close();
|
||||
props.primaryAction.onPress();
|
||||
},
|
||||
}}
|
||||
swipeableMethods={methods}
|
||||
threadTitle={props.threadTitle}
|
||||
translation={translation}
|
||||
/>
|
||||
)}
|
||||
rightThreshold={THREAD_SWIPE_ACTIONS_WIDTH * 0.42}
|
||||
>
|
||||
{props.children(close)}
|
||||
</ReanimatedSwipeable>
|
||||
);
|
||||
}
|
||||
|
||||
function SwipeActionButton(props: {
|
||||
readonly accessibilityLabel: string;
|
||||
readonly backgroundColor: string;
|
||||
@@ -179,12 +271,7 @@ export function ThreadSwipeActions(props: {
|
||||
readonly fullSwipeThreshold: number;
|
||||
readonly onDelete: () => void;
|
||||
readonly onFullSwipeArmedChange: (armed: boolean) => void;
|
||||
readonly primaryAction: {
|
||||
readonly accessibilityLabel: string;
|
||||
readonly icon: ComponentProps<typeof SymbolView>["name"];
|
||||
readonly label: string;
|
||||
readonly onPress: () => void;
|
||||
};
|
||||
readonly primaryAction: ThreadSwipePrimaryAction;
|
||||
readonly swipeableMethods: SwipeableMethods;
|
||||
readonly threadTitle: string;
|
||||
readonly translation: SharedValue<number>;
|
||||
|
||||
@@ -179,7 +179,7 @@ const ReviewFileNavigatorRow = memo(function ReviewFileNavigatorRow(props: {
|
||||
});
|
||||
|
||||
interface ReviewFileNavigatorHandle {
|
||||
readonly setVisibleFile: (fileId: string) => void;
|
||||
readonly setVisibleFile: (fileId: string | null) => void;
|
||||
}
|
||||
|
||||
interface ReviewFileNavigatorProps {
|
||||
@@ -212,7 +212,7 @@ function ReviewFileNavigator({
|
||||
ref,
|
||||
() => ({
|
||||
setVisibleFile: (fileId) => {
|
||||
if (!availableFileIds.includes(fileId)) {
|
||||
if (fileId !== null && !availableFileIds.includes(fileId)) {
|
||||
return;
|
||||
}
|
||||
setFileSelection((current) => {
|
||||
@@ -482,12 +482,8 @@ export function ReviewSheet() {
|
||||
[collapsedFileIds, commentSelection, toggleExpandedFile],
|
||||
);
|
||||
const handleVisibleFileChange = useCallback(
|
||||
(event: NativeSyntheticEvent<{ readonly fileId?: string }>) => {
|
||||
const { fileId } = event.nativeEvent;
|
||||
if (!fileId) {
|
||||
return;
|
||||
}
|
||||
reviewFileNavigatorRef.current?.setVisibleFile(fileId);
|
||||
(event: NativeSyntheticEvent<{ readonly fileId?: string | null }>) => {
|
||||
reviewFileNavigatorRef.current?.setVisibleFile(event.nativeEvent.fileId ?? null);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
@@ -1124,7 +1124,9 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
|
||||
const disclosureAnchorKeyRef = useRef<string | null>(null);
|
||||
const previousLatestTurnRef = useRef(props.latestTurn);
|
||||
const { width: windowWidth } = useWindowDimensions();
|
||||
const [viewportWidth, setViewportWidth] = useState(windowWidth);
|
||||
const [viewportWidth, setViewportWidth] = useState(() =>
|
||||
props.layoutVariant === "split" ? 0 : windowWidth,
|
||||
);
|
||||
const [disclosureToggleSettling, setDisclosureToggleSettling] = useState(false);
|
||||
const [interactionState, setInteractionState] = useState<{
|
||||
readonly copiedRowId: string | null;
|
||||
@@ -1201,6 +1203,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
|
||||
markdownStyles,
|
||||
reviewCommentColors,
|
||||
userBubbleColor,
|
||||
viewportWidth,
|
||||
}),
|
||||
[
|
||||
copiedRowId,
|
||||
@@ -1209,6 +1212,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
|
||||
markdownStyles,
|
||||
reviewCommentColors,
|
||||
userBubbleColor,
|
||||
viewportWidth,
|
||||
],
|
||||
);
|
||||
const expandedWorkGroupIds = useMemo(() => {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
|
||||
import { SymbolView } from "expo-symbols";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useCallback, useMemo, useRef, useState } from "react";
|
||||
import { Pressable, ScrollView, StyleSheet, TextInput, View } from "react-native";
|
||||
import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
|
||||
import { AppText as Text } from "../../components/AppText";
|
||||
@@ -10,6 +11,8 @@ import { scopedThreadKey } from "../../lib/scopedEntities";
|
||||
import { relativeTime } from "../../lib/time";
|
||||
import { useThemeColor } from "../../lib/useThemeColor";
|
||||
import { useProjects, useThreadShells } from "../../state/entities";
|
||||
import { ThreadSwipeable } from "../home/thread-swipe-actions";
|
||||
import { useThreadListActions } from "../home/useThreadListActions";
|
||||
import { buildThreadNavigationGroups } from "./thread-navigation-groups";
|
||||
import { SidebarHeaderActions } from "./sidebar-header-actions";
|
||||
import { threadStatusTone } from "./threadPresentation";
|
||||
@@ -25,6 +28,8 @@ export function ThreadNavigationSidebar(props: {
|
||||
const projects = useProjects();
|
||||
const threads = useThreadShells();
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const openSwipeableRef = useRef<SwipeableMethods | null>(null);
|
||||
const { archiveThread, confirmDeleteThread } = useThreadListActions();
|
||||
const groups = useMemo(
|
||||
() => buildThreadNavigationGroups({ projects, threads, searchQuery }),
|
||||
[projects, searchQuery, threads],
|
||||
@@ -38,6 +43,17 @@ export function ThreadNavigationSidebar(props: {
|
||||
const searchBackgroundColor = useThemeColor("--color-subtle-strong");
|
||||
const selectedBackgroundColor = useThemeColor("--color-subtle-strong");
|
||||
const pressedBackgroundColor = useThemeColor("--color-subtle");
|
||||
const handleSwipeableWillOpen = useCallback((methods: SwipeableMethods) => {
|
||||
if (openSwipeableRef.current !== methods) {
|
||||
openSwipeableRef.current?.close();
|
||||
openSwipeableRef.current = methods;
|
||||
}
|
||||
}, []);
|
||||
const handleSwipeableClose = useCallback((methods: SwipeableMethods) => {
|
||||
if (openSwipeableRef.current === methods) {
|
||||
openSwipeableRef.current = null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<View
|
||||
@@ -84,6 +100,7 @@ export function ThreadNavigationSidebar(props: {
|
||||
contentContainerStyle={styles.threadListContent}
|
||||
keyboardDismissMode="on-drag"
|
||||
keyboardShouldPersistTaps="handled"
|
||||
onScrollBeginDrag={() => openSwipeableRef.current?.close()}
|
||||
showsVerticalScrollIndicator={false}
|
||||
style={styles.threadList}
|
||||
>
|
||||
@@ -106,33 +123,55 @@ export function ThreadNavigationSidebar(props: {
|
||||
const selected = threadKey === props.selectedThreadKey;
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
<ThreadSwipeable
|
||||
key={threadKey}
|
||||
accessibilityLabel={thread.title}
|
||||
accessibilityRole="button"
|
||||
accessibilityState={{ selected }}
|
||||
onPress={() => props.onSelectThread(thread)}
|
||||
style={({ pressed }) => [
|
||||
styles.threadRow,
|
||||
{
|
||||
backgroundColor: selected
|
||||
? selectedBackgroundColor
|
||||
: pressed
|
||||
? pressedBackgroundColor
|
||||
: "transparent",
|
||||
},
|
||||
]}
|
||||
backgroundColor={backgroundColor}
|
||||
containerStyle={styles.threadRowContainer}
|
||||
fullSwipeWidth={props.width - 20}
|
||||
onDelete={() => confirmDeleteThread(thread)}
|
||||
onSwipeableClose={handleSwipeableClose}
|
||||
onSwipeableWillOpen={handleSwipeableWillOpen}
|
||||
primaryAction={{
|
||||
accessibilityLabel: `Archive ${thread.title}`,
|
||||
icon: "archivebox",
|
||||
label: "Archive",
|
||||
onPress: () => archiveThread(thread),
|
||||
}}
|
||||
threadTitle={thread.title}
|
||||
>
|
||||
<View style={styles.threadText}>
|
||||
<Text className="text-base font-t3-medium" numberOfLines={1}>
|
||||
{thread.title}
|
||||
</Text>
|
||||
<Text className="text-xs text-foreground-muted" numberOfLines={1}>
|
||||
{relativeTime(thread.updatedAt ?? thread.createdAt)}
|
||||
</Text>
|
||||
</View>
|
||||
<StatusPill {...threadStatusTone(thread)} size="compact" />
|
||||
</Pressable>
|
||||
{(close) => (
|
||||
<Pressable
|
||||
accessibilityHint="Swipe left for archive and delete actions"
|
||||
accessibilityLabel={thread.title}
|
||||
accessibilityRole="button"
|
||||
accessibilityState={{ selected }}
|
||||
onPress={() => {
|
||||
close();
|
||||
props.onSelectThread(thread);
|
||||
}}
|
||||
style={({ pressed }) => [
|
||||
styles.threadRow,
|
||||
{
|
||||
backgroundColor: selected
|
||||
? selectedBackgroundColor
|
||||
: pressed
|
||||
? pressedBackgroundColor
|
||||
: backgroundColor,
|
||||
},
|
||||
]}
|
||||
>
|
||||
<View style={styles.threadText}>
|
||||
<Text className="text-base font-t3-medium" numberOfLines={1}>
|
||||
{thread.title}
|
||||
</Text>
|
||||
<Text className="text-xs text-foreground-muted" numberOfLines={1}>
|
||||
{relativeTime(thread.updatedAt ?? thread.createdAt)}
|
||||
</Text>
|
||||
</View>
|
||||
<StatusPill {...threadStatusTone(thread)} size="compact" />
|
||||
</Pressable>
|
||||
)}
|
||||
</ThreadSwipeable>
|
||||
);
|
||||
})
|
||||
)}
|
||||
@@ -197,6 +236,10 @@ const styles = StyleSheet.create({
|
||||
alignItems: "center",
|
||||
gap: 8,
|
||||
},
|
||||
threadRowContainer: {
|
||||
borderRadius: 10,
|
||||
overflow: "hidden",
|
||||
},
|
||||
threadText: {
|
||||
minWidth: 0,
|
||||
flex: 1,
|
||||
|
||||
@@ -91,4 +91,21 @@ describe("buildThreadNavigationGroups", () => {
|
||||
})[0]?.threads.map((thread) => thread.id),
|
||||
).toEqual(["newer", "older"]);
|
||||
});
|
||||
|
||||
it("excludes archived threads from the navigation sidebar", () => {
|
||||
const archived = makeThread({
|
||||
id: ThreadId.make("archived"),
|
||||
projectId: project.id,
|
||||
title: "Archived work",
|
||||
archivedAt: "2026-06-04T00:00:00.000Z",
|
||||
updatedAt: "2026-06-04T00:00:00.000Z",
|
||||
});
|
||||
|
||||
expect(
|
||||
buildThreadNavigationGroups({
|
||||
projects: [project],
|
||||
threads: [...threads, archived],
|
||||
})[0]?.threads.map((thread) => thread.id),
|
||||
).toEqual(["newer", "older"]);
|
||||
});
|
||||
});
|
||||
@@ -30,8 +30,9 @@ export function buildThreadNavigationGroups(input: {
|
||||
readonly searchQuery?: string;
|
||||
}): ReadonlyArray<ThreadNavigationGroup> {
|
||||
const query = input.searchQuery?.trim().toLocaleLowerCase() ?? "";
|
||||
const activeThreads = input.threads.filter((thread) => thread.archivedAt === null);
|
||||
|
||||
return groupProjectsByRepository(input).flatMap((group) => {
|
||||
return groupProjectsByRepository({ ...input, threads: activeThreads }).flatMap((group) => {
|
||||
const threads = Arr.sort(
|
||||
group.projects.flatMap((projectGroup) => projectGroup.threads),
|
||||
threadActivityOrder,
|
||||
|
||||
Reference in new issue
Block a user