Skip to content

Commit 319c572

Browse files
refactor(mobile): git action results buzz from where they are reported (pingdotgg#25912)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 6dc4842 commit 319c572

3 files changed

Lines changed: 32 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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { describe, expect, it, vi } from "vite-plus/test";
2+
3+
const mocks = vi.hoisted(() => ({
4+
notificationAsync: vi.fn(() => Promise.resolve()),
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+
it("buzzes once per reported result with the matching feedback type", () => {
18+
showGitActionResult({ type: "success", title: "Pushed" });
19+
showGitActionResult({ type: "error", title: "Git action failed", description: "rejected" });
20+
dismissGitActionResult();
21+
22+
expect(mocks.notificationAsync.mock.calls).toEqual([["success"], ["error"]]);
23+
});
24+
});

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

Lines changed: 7 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,12 @@ function broadcast(result: GitActionResultNotification | null): void {
3132
}
3233

3334
export function showGitActionResult(result: GitActionResultNotification): void {
35+
// Best effort: devices without a haptics engine reject.
36+
Haptics.notificationAsync(
37+
result.type === "success"
38+
? Haptics.NotificationFeedbackType.Success
39+
: Haptics.NotificationFeedbackType.Error,
40+
).catch(() => undefined);
3441
if (dismissTimer) clearTimeout(dismissTimer);
3542
broadcast(result);
3643
dismissTimer = setTimeout(() => {

0 commit comments

Comments
 (0)