Open History to see the last commit
1import { Pressable, View } from "react-native";
2import Animated, { FadeIn, ReduceMotion } from "react-native-reanimated";
3import { AppText as Text } from "../../../components/ui/AppText";
4import { SymbolView } from "../../../components/ui/AppSymbol";
5import { PR_ROW_EXIT, PR_ROW_LAYOUT } from "../pullRequestAnimations";
6import { guideNoticeState } from "./reviewGuideState";
7import type { useReviewGuide } from "./useReviewGuide";
8
9const NOTICE_ENTER = FadeIn.delay(180).duration(120).reduceMotion(ReduceMotion.System);
10
11export function GuideNotice({ state }: { readonly state: ReturnType<typeof useReviewGuide> }) {
12 const notice = guideNoticeState(state);
13 if (notice.kind === "ready") return null;
14 const compact = state.data?.guide != null;
15 const failed = notice.kind === "failed" || notice.kind === "unavailable";
16 const busy = notice.kind === "loading" || notice.kind === "writing";
17 return (
18 <Animated.View
19 layout={PR_ROW_LAYOUT}
20 entering={compact ? NOTICE_ENTER : undefined}
21 exiting={PR_ROW_EXIT}
22 className={
23 compact ? "mb-5 rounded-2xl bg-grouped-card p-4" : "rounded-2xl bg-grouped-card p-5"
24 }
25 accessibilityLiveRegion="polite"
26 accessibilityState={{ busy }}
27 >
28 <View className="flex-row items-center gap-3">
29 <SymbolView
30 name={failed ? "exclamationmark.circle" : busy ? "clock" : "list.number"}
31 size={19}
32 tintColorClassName={failed ? "accent-danger-foreground" : "accent-icon-muted"}
33 />
34 <Text className="text-base font-t3-semibold">
35 {compact ? notice.title : "Review guide"}
36 </Text>
37 </View>
38 <View style={compact ? undefined : { minHeight: 100 }} className="pt-3 pb-4">
39 <Text className="text-sm leading-6 text-foreground-muted">{notice.description}</Text>
40 </View>
41 <View className="min-h-12 flex-row items-center justify-between gap-3">
42 {state.canWrite || busy || notice.kind === "unavailable" ? (
43 <Pressable
44 accessibilityRole="button"
45 accessibilityState={{ disabled: busy, busy }}
46 disabled={busy}
47 style={{ width: 152 }}
48 className={
49 compact
50 ? "min-h-12 items-center justify-center rounded-full bg-secondary px-4 active:opacity-70"
51 : "min-h-12 items-center justify-center rounded-full bg-foreground px-4 active:opacity-70"
52 }
53 onPress={() => (notice.kind === "unavailable" ? state.refresh() : void state.write())}
54 >
55 <Text
56 className={
57 compact
58 ? "text-center font-t3-medium text-secondary-foreground"
59 : "text-center font-t3-medium text-screen"
60 }
61 >
62 {notice.action}
63 </Text>
64 </Pressable>
65 ) : (
66 <Text className="text-xs text-foreground-muted">
67 {notice.kind === "failed"
68 ? "Reconnect or ask someone with write access to retry."
69 : "Writing a guide requires a connection and write access."}
70 </Text>
71 )}
72 {notice.kind === "writing" && state.data?.run?._tag === "Running" ? (
73 <Text className="shrink text-xs text-foreground-muted">
74 Started{" "}
75 {new Date(state.data.run.startedAt).toLocaleTimeString([], {
76 hour: "2-digit",
77 minute: "2-digit",
78 })}
79 </Text>
80 ) : null}
81 </View>
82 </Animated.View>
83 );
84}