Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions apps/mobile/src/features/browser/ThreadBrowserFloat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useAppForeground } from "../../lib/appState";
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
import { browserTabTitle } from "./browserTabs";
import { PreviewStreamWebView } from "./PreviewStreamWebView";
import { useThreadServerBrowserTabs } from "../../state/preview";
import { usePreparedConnection } from "../../state/session";

const PLAYER_LONG_SIDE = 184;
Expand All @@ -21,28 +22,30 @@ const PLAYER_EXITING = FadeOut.duration(120).reduceMotion(ReduceMotion.System);
export function ThreadBrowserFloat(props: {
readonly environmentId: EnvironmentId;
readonly threadId: ThreadId;
readonly tabs: ReadonlyArray<PreviewSessionSnapshot>;
readonly loaded: boolean;
/** Whether the environment serves browser tabs. */
readonly enabled: boolean;
readonly top: number;
readonly onOpen: (tabId: string) => void;
}) {
// Read here rather than by the thread screen, so a list read re-renders only the float.
const { tabs, loaded } = useThreadServerBrowserTabs(props);
const [tabId, setTabId] = useState<string | null>(null);
// The reveal requests already seen, so only a tab revealed after the first
// list pops the player.
const [seen, setSeen] = useState<{
readonly tabs: ReadonlyArray<PreviewSessionSnapshot>;
readonly reveals: ReadonlyMap<string, string | undefined>;
} | null>(null);
if (props.loaded && seen?.tabs !== props.tabs) {
if (loaded && seen?.tabs !== tabs) {
setSeen({
tabs: props.tabs,
reveals: new Map(props.tabs.map((tab) => [tab.tabId, tab.revealRequest?.id])),
tabs,
reveals: new Map(tabs.map((tab) => [tab.tabId, tab.revealRequest?.id])),
});
const previous = seen?.reveals;
const opened =
previous === undefined
? undefined
: props.tabs.findLast(
: tabs.findLast(
(tab) =>
tab.reveal === true &&
(tab.revealRequest
Expand All @@ -53,7 +56,7 @@ export function ThreadBrowserFloat(props: {
}
const focused = useIsFocused();
const foreground = useAppForeground();
const tab = props.tabs.find((entry) => entry.tabId === tabId) ?? null;
const tab = tabs.find((entry) => entry.tabId === tabId) ?? null;
const onOpen = props.onOpen;
const open = () => {
if (tabId === null) return;
Expand Down
3 changes: 3 additions & 0 deletions apps/mobile/src/features/home/useThreadListActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ vi.mock("react", () => ({
useCallback: (callback: unknown) => callback,
useRef: (current: unknown) => ({ current }),
}));
vi.mock("../../lib/useStableCallback", () => ({
useStableCallback: (callback: unknown) => callback,
}));
vi.mock("react-native", () => ({
Alert: {
alert: (title: string, _message: string, buttons?: { text: string; onPress?: () => void }[]) =>
Expand Down
46 changes: 34 additions & 12 deletions apps/mobile/src/features/home/useThreadListActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
import { getThreadListV2OrderedSection } from "../threads/threadListV2";
import { threadCanArchive } from "./threadArchive";
import { resolveThreadTitleRename } from "../threads/thread-title-rename";
import { useStableCallback } from "../../lib/useStableCallback";

function environmentConfigLoaded(environmentId: EnvironmentThreadShell["environmentId"]) {
return appAtomRegistry.get(environmentServerConfigsAtom).has(environmentId);
Expand Down Expand Up @@ -833,20 +834,41 @@ export function useThreadListActions(): {
const confirmDeleteThread = (thread: EnvironmentThreadShell) =>
confirmThreadDeletion(executeAction, thread);

// Stable, so a list that re-renders does not re-render every row these reach.
// `moveThread` looks up its own row, and refuses while a list holds older rows.
return {
archiveThread: (thread) => archiveThread(liveThread(thread)),
confirmDeleteThread: (thread) => confirmDeleteThread(liveThread(thread)),
settleThread: (thread) => settleThread(liveThread(thread)),
snoozeThread: (thread, snoozedUntil) => snoozeThread(liveThread(thread), snoozedUntil),
unsnoozeThread: (thread) => unsnoozeThread(liveThread(thread)),
unsettleThread: (thread) => unsettleThread(liveThread(thread)),
pinThread: (thread) => pinThread(liveThread(thread)),
unpinThread: (thread) => unpinThread(liveThread(thread)),
setThreadAutoSettle: (thread, enabled) => setThreadAutoSettle(liveThread(thread), enabled),
moveThread,
renameThread: (thread) => renameThread(liveThread(thread)),
regenerateThreadTitle: (thread) => regenerateThreadTitle(liveThread(thread)),
archiveThread: useStableCallback((thread: EnvironmentThreadShell) =>
archiveThread(liveThread(thread)),
),
confirmDeleteThread: useStableCallback((thread: EnvironmentThreadShell) =>
confirmDeleteThread(liveThread(thread)),
),
settleThread: useStableCallback((thread: EnvironmentThreadShell) =>
settleThread(liveThread(thread)),
),
snoozeThread: useStableCallback((thread: EnvironmentThreadShell, snoozedUntil: string) =>
snoozeThread(liveThread(thread), snoozedUntil),
),
unsnoozeThread: useStableCallback((thread: EnvironmentThreadShell) =>
unsnoozeThread(liveThread(thread)),
),
unsettleThread: useStableCallback((thread: EnvironmentThreadShell) =>
unsettleThread(liveThread(thread)),
),
pinThread: useStableCallback((thread: EnvironmentThreadShell) => pinThread(liveThread(thread))),
unpinThread: useStableCallback((thread: EnvironmentThreadShell) =>
unpinThread(liveThread(thread)),
),
setThreadAutoSettle: useStableCallback((thread: EnvironmentThreadShell, enabled: boolean) =>
setThreadAutoSettle(liveThread(thread), enabled),
),
moveThread: useStableCallback(moveThread),
renameThread: useStableCallback((thread: EnvironmentThreadShell) =>
renameThread(liveThread(thread)),
),
regenerateThreadTitle: useStableCallback((thread: EnvironmentThreadShell) =>
regenerateThreadTitle(liveThread(thread)),
),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ function RetainedWorkspaceTab(props: {
);
return () => cancelAnimationFrame(frame);
}, [headerOnly, optionsByRoute, slot, setPrewarmRequests]);
// Built apart from the providers: a header option write re-renders their readers, not the tab.
const body = content ? content.children(content.workspace, content.headerOnly) : null;
return content ? (
<NativeWorkspaceTabActivityContext value={activity}>
<WorkspaceSlotOptionsContext value={slotOptions}>
<WorkspaceTabsContext value={content.workspace}>
{content.children(content.workspace, content.headerOnly)}
</WorkspaceTabsContext>
<WorkspaceTabsContext value={content.workspace}>{body}</WorkspaceTabsContext>
</WorkspaceSlotOptionsContext>
</NativeWorkspaceTabActivityContext>
) : null;
Expand Down
24 changes: 11 additions & 13 deletions apps/mobile/src/features/pull-requests/PullRequestFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AnimatedLegendList } from "@legendapp/list/reanimated";
import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
import type { PullRequestChangeBreakdown } from "@t3tools/contracts";
import { msg, T, useGT, useMessages, Var } from "gt-react-native";
import { useState } from "react";
import { memo, useState } from "react";
import { View } from "react-native";
import Animated from "react-native-reanimated";
import { PierreEntryIcon } from "../../components/PierreEntryIcon";
Expand Down Expand Up @@ -108,12 +108,13 @@ function describeFiles(
.join(" · ");
}

function FileRow(props: {
// Memoized: a pull request's rows rebuild as its detail, diff and viewed reads land.
const FileRow = memo(function FileRow(props: {
readonly file: ReviewRenderableFile;
readonly viewed: boolean;
/** Shown under the file name where files aren't grouped by directory. */
readonly directory?: string;
readonly onPress: () => void;
readonly onPress: (path: string) => void;
}) {
const { file } = props;
const gt = useGT();
Expand All @@ -126,7 +127,7 @@ function FileRow(props: {
? gt("View diff for {path}, {additions} additions, {deletions} deletions, viewed", values)
: gt("View diff for {path}, {additions} additions, {deletions} deletions", values)
}
onPress={props.onPress}
onPress={() => props.onPress(file.path)}
className="min-h-14 flex-row items-center gap-3 border-b border-border-subtle py-3 active:opacity-70"
>
<PierreEntryIcon kind="file" path={file.path} size={20} />
Expand Down Expand Up @@ -158,7 +159,7 @@ function FileRow(props: {
<SymbolView name="chevron.right" size={12} tintColorClassName="accent-icon-muted" />
</RowPressable>
);
}
});

function FileRowSkeleton(props: { readonly index: number }) {
return (
Expand Down Expand Up @@ -289,6 +290,7 @@ export function usePullRequestFilesSection(params: PullRequestParams) {
composerPullRequests.changeBreakdown(pullRequestTarget(params)),
).data;
const expected = pr ?? params.initialSummary;
const openFile = (path: string) => navigation.navigate("PullRequestFile", { ...params, path });
return {
refresh: diff.refresh,
header: (
Expand Down Expand Up @@ -363,7 +365,7 @@ export function usePullRequestFilesSection(params: PullRequestParams) {
file={file}
directory={fileDirectory(file.path)}
viewed={viewed.isViewed(file.path)}
onPress={() => navigation.navigate("PullRequestFile", { ...params, path: file.path })}
onPress={openFile}
/>
),
})),
Expand Down Expand Up @@ -461,14 +463,10 @@ export function PullRequestFilesSheet({ route }: StaticScreenProps<PullRequestDi
<FileRow
file={item.file}
viewed={viewed.isViewed(item.file.path)}
onPress={() => {
requestPullRequestFileJump(navigation.getState()?.routes ?? [], item.file.path);
onPress={(path) => {
requestPullRequestFileJump(navigation.getState()?.routes ?? [], path);
navigation.dispatch(
StackActions.popTo("PullRequestFile", {
...params,
path: item.file.path,
focus: undefined,
}),
StackActions.popTo("PullRequestFile", { ...params, path, focus: undefined }),
);
}}
/>
Expand Down
Loading
Loading