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

GuideNotice.tsx

70 lines2.9 KB

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