Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions apps/mobile/src/features/threads/GitActionProgressOverlay.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 (openPullRequest
Expand Down
24 changes: 24 additions & 0 deletions apps/mobile/src/state/use-vcs-action-state.test.ts
Original file line number Diff line number Diff line change
@@ -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"]]);
});
});
7 changes: 7 additions & 0 deletions apps/mobile/src/state/use-vcs-action-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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(() => {
Expand Down
Loading