Skip to content

Commit 7b4b0b6

Browse files
refactor(mobile): git action results buzz from where they are reported
GitActionProgressOverlay kept the previous progress phase in a ref and diffed it in an effect to fire success/error haptics when a git action finished. That reconstructs an event that already has one owner: showGitActionResult, which every git action result passes through. The haptic now fires there, picked by result type. The overlay loses its ref and its effect. Behavior: the haptic now fires even when no thread route overlay is mounted, and its type always matches the result shown (the old diff could miss a failure if a render showed idle or a still-visible earlier result between the run ending and the error landing). Keyboard copy feedback never went through "running" and still gets its haptic from tryCopyTextWithHaptic. Effects: GitActionProgressOverlay.tsx 1 -> 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 79f6cd3 commit 7b4b0b6

3 files changed

Lines changed: 44 additions & 15 deletions

File tree

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
2-
import * as Haptics from "expo-haptics";
32
import { HeaderHeightContext } from "@react-navigation/elements";
4-
import { useContext, useEffect, useRef } from "react";
3+
import { useContext } from "react";
54
import { Platform } from "react-native";
65
import Animated, { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated";
76
import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -26,19 +25,6 @@ export function GitActionProgressOverlay(props: {
2625
Platform.OS === "android"
2726
? toolbar.paddingTop + toolbar.height + toolbar.paddingBottom + 8
2827
: headerHeight + 8;
29-
const prevPhaseRef = useRef(progress.phase);
30-
31-
useEffect(() => {
32-
const prev = prevPhaseRef.current;
33-
prevPhaseRef.current = progress.phase;
34-
35-
if (prev === "running" && progress.phase === "success") {
36-
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
37-
} else if (prev === "running" && progress.phase === "error") {
38-
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error);
39-
}
40-
}, [progress.phase]);
41-
4228
const handlePress = () => {
4329
if (progress.prUrl) {
4430
void (openPullRequest
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
2+
3+
const mocks = vi.hoisted(() => ({
4+
notificationAsync: vi.fn(),
5+
}));
6+
7+
vi.mock("expo-haptics", () => ({
8+
NotificationFeedbackType: { Success: "success", Error: "error" },
9+
notificationAsync: mocks.notificationAsync,
10+
}));
11+
12+
vi.mock("./vcs", () => ({ vcsActionManager: {} }));
13+
14+
import { dismissGitActionResult, showGitActionResult } from "./use-vcs-action-state";
15+
16+
describe("showGitActionResult", () => {
17+
beforeEach(() => {
18+
vi.clearAllMocks();
19+
mocks.notificationAsync.mockResolvedValue(undefined);
20+
dismissGitActionResult();
21+
});
22+
23+
it("buzzes success once when a git action succeeds", () => {
24+
showGitActionResult({ type: "success", title: "Pushed" });
25+
26+
expect(mocks.notificationAsync).toHaveBeenCalledTimes(1);
27+
expect(mocks.notificationAsync).toHaveBeenCalledWith("success");
28+
});
29+
30+
it("buzzes error when a git action fails, even right after a success", () => {
31+
showGitActionResult({ type: "success", title: "Pushed" });
32+
showGitActionResult({ type: "error", title: "Git action failed", description: "rejected" });
33+
34+
expect(mocks.notificationAsync).toHaveBeenLastCalledWith("error");
35+
expect(mocks.notificationAsync).toHaveBeenCalledTimes(2);
36+
});
37+
});

‎apps/mobile/src/state/use-vcs-action-state.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useAtomValue } from "@effect/atom-react";
22
import { secondTick } from "@t3tools/client-runtime/clock";
33
import { type VcsActionState, type VcsActionTarget } from "@t3tools/client-runtime/state/vcs";
44
import { Atom } from "effect/reactivity";
5+
import * as Haptics from "expo-haptics";
56
import { useSyncExternalStore } from "react";
67

78
import { appAtomRegistry } from "./atom-registry";
@@ -31,6 +32,11 @@ function broadcast(result: GitActionResultNotification | null): void {
3132
}
3233

3334
export function showGitActionResult(result: GitActionResultNotification): void {
35+
void Haptics.notificationAsync(
36+
result.type === "success"
37+
? Haptics.NotificationFeedbackType.Success
38+
: Haptics.NotificationFeedbackType.Error,
39+
);
3440
if (dismissTimer) clearTimeout(dismissTimer);
3541
broadcast(result);
3642
dismissTimer = setTimeout(() => {

0 commit comments

Comments
 (0)