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