TypeScript
refactor(mobile): git action results buzz from where they are reported (#25912)
Julius Marminge319c572c966b
diff --git a/apps/mobile/src/features/threads/GitActionProgressOverlay.tsx b/apps/mobile/src/features/threads/GitActionProgressOverlay.tsxindex 08342cefcdf..17475f9e33d 100644--- a/apps/mobile/src/features/threads/GitActionProgressOverlay.tsx+++ b/apps/mobile/src/features/threads/GitActionProgressOverlay.tsx@@ -1,7 +1,6 @@import { tryOpenExternalUrl } from "../../lib/openExternalUrl";-import * as Haptics from "expo-haptics";import { HeaderHeightContext } from "@react-navigation/elements";-import { useContext, useEffect, useRef } from "react";+import { useContext } from "react";import { Platform } from "react-native";import Animated, { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated";import { useSafeAreaInsets } from "react-native-safe-area-context";@@ -26,19 +25,6 @@ export function GitActionProgressOverlay(props: {Platform.OS === "android"? toolbar.paddingTop + toolbar.height + toolbar.paddingBottom + 8: headerHeight + 8;- const prevPhaseRef = useRef(progress.phase);-- useEffect(() => {- const prev = prevPhaseRef.current;- prevPhaseRef.current = progress.phase;-- if (prev === "running" && progress.phase === "success") {- Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);- } else if (prev === "running" && progress.phase === "error") {- Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error);- }- }, [progress.phase]);-const handlePress = () => {if (progress.prUrl) {void (openPullRequestdiff --git a/apps/mobile/src/state/use-vcs-action-state.test.ts b/apps/mobile/src/state/use-vcs-action-state.test.tsnew file mode 100644index 00000000000..5d6409bdb12--- /dev/null+++ b/apps/mobile/src/state/use-vcs-action-state.test.ts@@ -0,0 +1,24 @@+import { describe, expect, it, vi } from "vite-plus/test";++const mocks = vi.hoisted(() => ({+ notificationAsync: vi.fn(() => Promise.resolve()),+}));++vi.mock("expo-haptics", () => ({+ NotificationFeedbackType: { Success: "success", Error: "error" },+ notificationAsync: mocks.notificationAsync,+}));++vi.mock("./vcs", () => ({ vcsActionManager: {} }));++import { dismissGitActionResult, showGitActionResult } from "./use-vcs-action-state";++describe("showGitActionResult", () => {+ it("buzzes once per reported result with the matching feedback type", () => {+ showGitActionResult({ type: "success", title: "Pushed" });+ showGitActionResult({ type: "error", title: "Git action failed", description: "rejected" });+ dismissGitActionResult();++ expect(mocks.notificationAsync.mock.calls).toEqual([["success"], ["error"]]);+ });+});diff --git a/apps/mobile/src/state/use-vcs-action-state.ts b/apps/mobile/src/state/use-vcs-action-state.tsindex dadc7b3e3ad..1709cce06a4 100644--- a/apps/mobile/src/state/use-vcs-action-state.ts+++ b/apps/mobile/src/state/use-vcs-action-state.ts@@ -2,6 +2,7 @@ import { useAtomValue } from "@effect/atom-react";import { secondTick } from "@t3tools/client-runtime/clock";import { type VcsActionState, type VcsActionTarget } from "@t3tools/client-runtime/state/vcs";import { Atom } from "effect/reactivity";+import * as Haptics from "expo-haptics";import { useSyncExternalStore } from "react";import { appAtomRegistry } from "./atom-registry";@@ -31,6 +32,12 @@ function broadcast(result: GitActionResultNotification | null): void {}export function showGitActionResult(result: GitActionResultNotification): void {+ // Best effort: devices without a haptics engine reject.+ Haptics.notificationAsync(+ result.type === "success"+ ? Haptics.NotificationFeedbackType.Success+ : Haptics.NotificationFeedbackType.Error,+ ).catch(() => undefined);if (dismissTimer) clearTimeout(dismissTimer);broadcast(result);dismissTimer = setTimeout(() => {