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

ProjectCloneBanner.tsx

77 lines2.5 KB

1import {
2 projectCloneDisplayName,
3 projectCloneProgressSummary,
4 type ProjectCloneSnapshot,
5} from "@t3tools/contracts";
6import { Pressable, View } from "react-native";
7​
8import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
9import { cn } from "../../lib/cn";
10import { AppText as Text } from "../../components/ui/AppText";
11​
12export function ProjectCloneBanner(props: {
13 readonly clone: ProjectCloneSnapshot;
14 readonly onCancel: () => void;
15 readonly onRetry: () => void;
16 readonly onRemove: () => void;
17}) {
18 const { clone } = props;
19 const name = projectCloneDisplayName(clone);
20 if (clone.phase === "running") {
21 return (
22 <View className="flex-row items-center gap-3 rounded-2xl border border-border bg-card px-3.5 py-3">
23 <AppActivityIndicator size="small" />
24 <View className="min-w-0 flex-1">
25 <Text className="font-t3-medium text-sm" numberOfLines={1}>
26 Cloning {name}
27 </Text>
28 <Text className="text-xs text-foreground-muted" numberOfLines={1}>
29 {projectCloneProgressSummary(clone)}
30 </Text>
31 </View>
32 <BannerAction label="Cancel" onPress={props.onCancel} />
33 </View>
34 );
35 }
36 const cancelled = clone.phase === "cancelled";
37 return (
38 <View
39 className={cn(
40 "rounded-2xl border px-3.5 py-3",
41 cancelled ? "border-warning-border bg-warning" : "border-danger-border bg-danger",
42 )}
43 >
44 <Text
45 className={cn(
46 "font-t3-medium text-sm",
47 cancelled ? "text-warning-foreground" : "text-danger-foreground",
48 )}
49 numberOfLines={1}
50 >
51 {cancelled ? `Cancelled cloning ${name}` : `Failed to clone ${name}`}
52 </Text>
53 {clone.error ? (
54 <Text className="mt-0.5 text-xs text-danger-foreground" numberOfLines={3}>
55 {clone.error}
56 </Text>
57 ) : null}
58 <View className="mt-2 flex-row justify-end gap-2">
59 <BannerAction label="Remove project" onPress={props.onRemove} />
60 <BannerAction label="Retry" onPress={props.onRetry} />
61 </View>
62 </View>
63 );
65​
66function BannerAction(props: { readonly label: string; readonly onPress: () => void }) {
67 return (
68 <Pressable
69 accessibilityRole="button"
70 accessibilityLabel={props.label}
71 className="rounded-full border border-border bg-card px-3 py-1.5"
72 onPress={props.onPress}
73 >
74 <Text className="font-t3-medium text-xs">{props.label}</Text>
75 </Pressable>
76 );