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