Open History to see the last commit
1import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
2import * as Haptics from "expo-haptics";
3import { useEffect, useRef } from "react";
4import Animated, { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated";
5import { useSafeAreaInsets } from "react-native-safe-area-context";
6import { Toast } from "../../components/ui/Toast";
7import { MOBILE_MOTION } from "../../lib/designTokens";
8import { APP_BAR_HEIGHT } from "../../lib/layoutMetrics";
9import type { GitActionProgress } from "../../state/use-vcs-action-state";
10
11export function GitActionProgressOverlay(props: {
12 readonly progress: GitActionProgress;
13 readonly onDismiss: () => void;
14 readonly onOpenPullRequest?: (url: string) => Promise<boolean>;
15}) {
16 const { progress, onDismiss } = props;
17 const openPullRequest = props.onOpenPullRequest;
18 const insets = useSafeAreaInsets();
19 const prevPhaseRef = useRef(progress.phase);
20
21 useEffect(() => {
22 const prev = prevPhaseRef.current;
23 prevPhaseRef.current = progress.phase;
24
25 if (prev === "running" && progress.phase === "success") {
26 Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
27 } else if (prev === "running" && progress.phase === "error") {
28 Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error);
29 }
30 }, [progress.phase]);
31
32 const handlePress = () => {
33 if (progress.prUrl) {
34 void (openPullRequest
35 ? openPullRequest(progress.prUrl)
36 : tryOpenExternalUrl(progress.prUrl, "pull-request"));
37 return;
38 }
39 if (progress.phase === "success" || progress.phase === "error") {
40 onDismiss();
41 }
42 };
43
44 if (progress.phase === "idle") {
45 return null;
46 }
47
48 return (
49 <Animated.View
50 entering={FadeIn.duration(MOBILE_MOTION.enter).reduceMotion(ReduceMotion.System)}
51 exiting={FadeOut.duration(MOBILE_MOTION.exit).reduceMotion(ReduceMotion.System)}
52 className="absolute inset-x-3 z-[100]"
53 style={{ top: insets.top + APP_BAR_HEIGHT + 8 }}
54 pointerEvents="box-none"
55 >
56 <Toast
57 message={progress.label ?? "Source control"}
58 description={progress.description ?? undefined}
59 tone={
60 progress.phase === "error"
61 ? "danger"
62 : progress.phase === "success"
63 ? "success"
64 : "default"
65 }
66 busy={progress.phase === "running"}
67 action={progress.prUrl ? { label: "Open PR", onPress: handlePress } : undefined}
68 onDismiss={progress.phase === "running" ? undefined : onDismiss}
69 />
70 </Animated.View>
71 );
72}