Skip to content
Open
2 changes: 1 addition & 1 deletion apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"generate:highlights": "node scripts/generate-highlights.mts",
"generate:nitro": "cd modules/t3-highlights && nitrogen",
"eas-build-on-success": "node scripts/upload-sourcemaps.mts build",
"test": "vp test run --project unit --project react",
"test": "vp test run --project unit --project react && T3_MOBILE_TEST_PLATFORM=android vp test run --project react src/features/threads/git/GitCommitSheet.test.tsx",
"typecheck": "effect-tsgo tsrs --noEmit"
},
"dependencies": {
Expand Down
5 changes: 4 additions & 1 deletion apps/mobile/src/Stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,10 @@ const RootStackConfig = createWorkspaceStackNavigator({
GitCommit: createNativeStackScreen({
screen: GitCommitSheet,
linking: `${THREAD_LINKING_PREFIX}/git/commit`,
options: sheetRoute({ detent: 0.8, androidFit: true }),
options: {
...sheetRoute({ detent: 0.8 }),
...(Platform.OS === "android" ? { sheetAllowedDetents: [0.92] } : undefined),
},
}),
GitBranches: createNativeStackScreen({
screen: GitBranchesSheet,
Expand Down
129 changes: 129 additions & 0 deletions apps/mobile/src/features/threads/git/GitCommitSheet.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { act, type ReactNode } from "react";
import { createRoot } from "react-dom/client";
import { expect, it, vi } from "vite-plus/test";

const state = vi.hoisted(() => ({
paths: ["a.txt", "b.txt"],
cwd: "/repo",
commit: vi.fn(),
renderFooter: (_footer: ReactNode) => {},
}));

// Navigation materializes native footers only when screen options change.
vi.mock("@react-navigation/native", async () => {
const { createContext } = await vi.importActual<typeof import("react")>("react");
const navigation = {
goBack() {},
setOptions(options: { unstable_sheetFooter?: () => ReactNode }) {
state.renderFooter(options.unstable_sheetFooter?.());
},
};
return {
useNavigation: () => navigation,
NavigationContext: createContext(navigation),
NavigationRouteContext: createContext(undefined),
};
});
vi.mock("react-native", () => ({
Platform: { OS: "android" },
View: ({ children }: { children: ReactNode }) => children,
ScrollView: ({ children }: { children: ReactNode }) => children,
Pressable: (props: { accessibilityLabel: string; onPress: () => void }) => (
<button aria-label={props.accessibilityLabel} onClick={props.onPress} />
),
}));
vi.mock("react-native-safe-area-context", () => ({
useSafeAreaInsets: () => ({ bottom: 0 }),
}));
vi.mock("../../../components/ui/SheetHeader", () => ({ SheetHeader: () => null }));
vi.mock("../../../components/ui/FitSheet", () => ({
FitSheet: ({ children }: { children: ReactNode }) => children,
}));
vi.mock("../../../components/ui/ScreenContent", () => ({
ScreenContent: ({ children }: { children: ReactNode }) => children,
}));
vi.mock("../../../components/ui/AppSymbol", () => ({ SymbolView: () => null }));
vi.mock("../../../components/ui/AppText", () => ({
AppText: ({ children }: { children: ReactNode }) => children,
AppTextInput: () => null,
}));
vi.mock("../../../components/ui/Button", () => ({
Button: (props: { label: string; disabled?: boolean; onPress: () => void }) => (
<button disabled={props.disabled} onClick={props.onPress}>
{props.label}
</button>
),
}));
vi.mock("../../../state/query", () => ({
useEnvironmentQuery: () => ({
data: {
workingTree: { files: state.paths.map((path) => ({ path, insertions: 1, deletions: 0 })) },
},
}),
}));
vi.mock("../../../state/use-thread-selection", () => ({
useThreadSelection: () => ({ selectedThread: { environmentId: "environment" } }),
}));
vi.mock("../../../state/use-selected-thread-worktree", () => ({
useSelectedThreadWorktree: () => ({ selectedThreadCwd: state.cwd }),
}));
vi.mock("../../../state/use-selected-thread-git-state", () => ({
useSelectedThreadGitState: () => ({ gitOperationLabel: null }),
}));
vi.mock("../../../state/use-selected-thread-git-actions", () => ({
useSelectedThreadGitActions: () => {
const cwd = state.cwd;
return {
canWriteSourceControl: true,
canChangeThreadBranch: true,
onRunSelectedThreadGitAction: (input: unknown) => state.commit(cwd, input),
};
},
}));
vi.mock("../../../state/vcs", () => ({ vcsEnvironment: { status: () => null } }));

import { GitCommitSheet } from "./GitCommitSheet";

it("commits all files in the current worktree after Select all and a worktree switch", async () => {
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
const body = document.createElement("div");
const footer = document.createElement("div");
const root = createRoot(body);
const footerRoot = createRoot(footer);
state.renderFooter = (children) => footerRoot.render(children);
state.paths = ["a.txt", "b.txt"];
state.cwd = "/repo";
state.commit.mockClear();
const render = () =>
act(() =>
root.render(
<GitCommitSheet route={{ params: { environmentId: "environment", threadId: "thread" } }} />,
),
);
try {
render();
act(() => body.querySelector<HTMLButtonElement>('[aria-label="b.txt"]')!.click());
state.paths = ["a.txt"];
render();
act(() =>
Array.from(body.querySelectorAll("button"))
.find((button) => button.textContent === "Select all")!
.click(),
);
state.cwd = "/other";
render();
await act(async () => {
Array.from([...footer.querySelectorAll("button"), ...body.querySelectorAll("button")])
.find((button) => button.textContent === "Commit changes")!
.click();
});
expect(state.commit).toHaveBeenCalledExactlyOnceWith("/other", {
action: "commit",
featureBranch: false,
});
} finally {
act(() => root.unmount());
act(() => footerRoot.unmount());
vi.unstubAllGlobals();
}
});
139 changes: 105 additions & 34 deletions apps/mobile/src/features/threads/git/GitCommitSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { FitSheet } from "../../../components/ui/FitSheet";
import { ScreenContent } from "../../../components/ui/ScreenContent";
import { SheetHeader } from "../../../components/ui/SheetHeader";
import { Button } from "../../../components/ui/Button";
import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
import { useState } from "react";
import { Pressable, View } from "react-native";
import { Platform, Pressable, ScrollView, View } from "react-native";
import { NativeStackScreenOptions } from "../../../native/StackHeader";
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
import { useSafeAreaInsets } from "react-native-safe-area-context";

import { SymbolView } from "../../../components/ui/AppSymbol";
import { AppText as Text, AppTextInput as TextInput } from "../../../components/ui/AppText";
Expand All @@ -23,7 +26,10 @@ type GitCommitSheetProps = StaticScreenProps<{

export function GitCommitSheet(_props: GitCommitSheetProps) {
const navigation = useNavigation();
const { selectedThread } = useThreadSelection();
const insets = useSafeAreaInsets();
const android = Platform.OS === "android";
const [footerHeight, setFooterHeight] = useState(0);
const { selectedThread, selectedThreadProject } = useThreadSelection();
const { selectedThreadCwd } = useSelectedThreadWorktree();
const gitState = useSelectedThreadGitState();
const gitActions = useSelectedThreadGitActions();
Expand Down Expand Up @@ -63,21 +69,46 @@ export function GitCommitSheet(_props: GitCommitSheetProps) {
});
};

return (
<FitSheet
header={
<SheetHeader
title="Commit changes"
subtitle={gitStatus.data?.refName ?? "(detached HEAD)"}
onCancel={() => navigation.goBack()}
accessibilityLabel="Cancel commit"
/>
}
keyboardShouldPersistTaps="handled"
keyboardDismissMode="on-drag"
automaticallyAdjustKeyboardInsets
contentContainerClassName="px-5 pt-4 gap-5"
const actions = (
<View className="gap-2">
<Button
label="Commit changes"
icon="checkmark"
tone="primary"
fullWidth
disabled={!canWriteSourceControl || noneSelected || busy}
onPress={() => void runCommitAction(false)}
/>
<Button
label="Commit on a new branch"
icon="arrow.branch"
tone="text"
fullWidth
disabled={!canWriteSourceControl || !canChangeThreadBranch || noneSelected || busy}
onPress={() => void runCommitAction(true)}
/>
</View>
);
const footer = (
<View
className="shrink-0 gap-2 border-t border-border-subtle bg-sheet-solid px-5 pt-3"
onLayout={android ? (event) => setFooterHeight(event.nativeEvent.layout.height) : undefined}
style={{ paddingBottom: Math.max(insets.bottom, 18) }}
>
{actions}
</View>
);
const header = (
<SheetHeader
title="Commit changes"
subtitle={gitStatus.data?.refName ?? "(detached HEAD)"}
onCancel={() => navigation.goBack()}
accessibilityLabel="Cancel commit"
/>
);

const content = (
<>
{isDefaultRef ? (
<Text className="text-sm text-warning-foreground">
You’re on the default branch. You can create a new branch when committing.
Expand Down Expand Up @@ -188,24 +219,64 @@ export function GitCommitSheet(_props: GitCommitSheetProps) {
})
)}
</View>
<View className="gap-2">
<Button
label="Commit changes"
icon="checkmark"
tone="primary"
fullWidth
disabled={!canWriteSourceControl || noneSelected || busy}
onPress={() => void runCommitAction(false)}
/>
<Button
label="Commit on a new branch"
icon="arrow.branch"
tone="text"
fullWidth
disabled={!canWriteSourceControl || !canChangeThreadBranch || noneSelected || busy}
onPress={() => void runCommitAction(true)}
</>
);

if (!android) {
return (
<FitSheet
header={header}
keyboardShouldPersistTaps="handled"
keyboardDismissMode="on-drag"
automaticallyAdjustKeyboardInsets
contentContainerClassName="px-5 pt-4 gap-5"
>
{content}
{actions}
</FitSheet>
);
}

return (
// Material sheet drags follow the first nested-scrolling native view, and the inline
// header's Compose button is one, so Android renders content first and reverses the column.
<View
collapsable={false}
className="bg-sheet ios:flex-1 android:absolute android:inset-0 android:flex-col-reverse"
>
{android ? (
<NativeStackScreenOptions
options={{ unstable_sheetFooter: () => footer }}
optionsVersion={{
threadId: selectedThread?.id,
cwd: selectedThreadCwd,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
hasProject: selectedThreadProject !== null,
commitMessage: dialogCommitMessage,
filePaths: selectedFiles.map((file) => file.path),
allSelected,
busy,
canWriteSourceControl,
canChangeThreadBranch,
bottomInset: insets.bottom,
}}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
/>
</View>
</FitSheet>
) : null}
<ScreenContent>
<ScrollView
nestedScrollEnabled
contentInsetAdjustmentBehavior="automatic"
className="flex-1"
keyboardShouldPersistTaps="handled"
keyboardDismissMode="on-drag"
automaticallyAdjustKeyboardInsets
contentContainerClassName="px-5 pt-4 pb-6 gap-5"
contentContainerStyle={android ? { paddingBottom: footerHeight + 24 } : undefined}
>
{content}
</ScrollView>
{android ? null : footer}
</ScreenContent>
{header}
</View>
);
}
1 change: 1 addition & 0 deletions apps/mobile/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "vite-plus/test/config";

const reactTests = [
"src/features/threads/git/GitBranchesSheet.test.tsx",
"src/features/threads/git/GitCommitSheet.test.tsx",
"src/features/threads/new-task-flow-provider.test.tsx",
"src/features/layout/workspace/workspace-tabs-state.test.ts",
"src/state/use-thread-pr.demand.test.tsx",
Expand Down
Loading