Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

GitActionProgressOverlay.tsx

66 lines2.4 KB

1import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
2import { HeaderHeightContext } from "@react-navigation/elements";
3import { useContext } from "react";
4import { Platform } from "react-native";
5import Animated, { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated";
6import { useSafeAreaInsets } from "react-native-safe-area-context";
7import { Toast } from "../../components/ui/Toast";
8import { useToolbarLayout } from "../../components/ui/useToolbarLayout";
9import { MOBILE_MOTION } from "../../lib/designTokens";
10import { APP_BAR_HEIGHT } from "../../lib/layoutMetrics";
11import type { GitActionProgress } from "../../state/use-vcs-action-state";
12​
13export function GitActionProgressOverlay(props: {
14 readonly progress: GitActionProgress;
15 readonly onDismiss: () => void;
16 readonly onOpenPullRequest?: (url: string) => Promise<boolean>;
17}) {
18 const { progress, onDismiss } = props;
19 const openPullRequest = props.onOpenPullRequest;
20 const insets = useSafeAreaInsets();
21 // Keyboard-copy feedback sits outside the screen's native header context.
22 const headerHeight = useContext(HeaderHeightContext) ?? insets.top + APP_BAR_HEIGHT;
23 const toolbar = useToolbarLayout();
24 const top =
25 Platform.OS === "android"
26 ? toolbar.paddingTop + toolbar.height + toolbar.paddingBottom + 8
27 : headerHeight + 8;
28 const handlePress = () => {
29 if (progress.prUrl) {
30 void (openPullRequest
31 ? openPullRequest(progress.prUrl)
32 : tryOpenExternalUrl(progress.prUrl, "pull-request"));
33 return;
34 }
35 };
36​
37 if (progress.phase === "idle") {
38 return null;
39 }
40​
41 return (
42 <Animated.View
43 entering={FadeIn.duration(MOBILE_MOTION.enter).reduceMotion(ReduceMotion.System)}
44 exiting={FadeOut.duration(MOBILE_MOTION.exit).reduceMotion(ReduceMotion.System)}
45 className="absolute inset-x-3 z-[100]"
46 style={{ top }}
47 pointerEvents="box-none"
48 onAccessibilityEscape={onDismiss}
49 >
50 <Toast
51 singleLine
52 message={progress.label ?? "Source control"}
53 description={progress.description ?? undefined}
54 tone={
55 progress.phase === "error"
56 ? "danger"
57 : progress.phase === "success"
58 ? "success"
59 : "default"
60 }
61 busy={progress.phase === "running"}
62 action={progress.prUrl ? { label: "View", onPress: handlePress } : undefined}
63 />
64 </Animated.View>
65 );