GeezerVison is showing github.com — refactor(mobile): git action results buzz from where they are reporte… · pingdotgg/t3code@319c572
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/GitActionProgressOverlay.tsx +1-15Lines changed: 1 addition & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { tryOpenExternalUrl } from "../../lib/openExternalUrl"; | 2 | | -import * as Haptics from "expo-haptics"; | 3 | 2 | import { HeaderHeightContext } from "@react-navigation/elements"; | 4 | | -import { useContext, useEffect, useRef } from "react"; | | 3 | +import { useContext } from "react"; | 5 | 4 | import { Platform } from "react-native"; | 6 | 5 | import Animated, { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated"; | 7 | 6 | import { useSafeAreaInsets } from "react-native-safe-area-context"; | @@ -26,19 +25,6 @@ export function GitActionProgressOverlay(props: { | 26 | 25 | Platform.OS === "android" | 27 | 26 | ? toolbar.paddingTop + toolbar.height + toolbar.paddingBottom + 8 | 28 | 27 | : 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 | | - | 42 | 28 | const handlePress = () => { | 43 | 29 | if (progress.prUrl) { | 44 | 30 | void (openPullRequest | |
Collapse file Copy file name to clipboard +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/state/use-vcs-action-state.ts +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,7 @@ import { useAtomValue } from "@effect/atom-react"; | 2 | 2 | import { secondTick } from "@t3tools/client-runtime/clock"; | 3 | 3 | import { type VcsActionState, type VcsActionTarget } from "@t3tools/client-runtime/state/vcs"; | 4 | 4 | import { Atom } from "effect/reactivity"; | | 5 | +import * as Haptics from "expo-haptics"; | 5 | 6 | import { useSyncExternalStore } from "react"; | 6 | 7 |
| 7 | 8 | import { appAtomRegistry } from "./atom-registry"; | @@ -31,6 +32,12 @@ function broadcast(result: GitActionResultNotification | null): void { | 31 | 32 | } | 32 | 33 |
| 33 | 34 | 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); | 34 | 41 | if (dismissTimer) clearTimeout(dismissTimer); | 35 | 42 | broadcast(result); | 36 | 43 | dismissTimer = setTimeout(() => { | |
|