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

GuideNotice.tsx

73 lines3.0 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 items-center justify-between gap-3">
43 {state.canWrite || busy || notice.kind === "unavailable" ? (
44 <View className="w-40">
45 <Button
46 label={notice.action}
47 tone={compact ? "secondary" : "contrast"}
48 disabled={busy}
49 onPress={() => (notice.kind === "unavailable" ? state.refresh() : void state.write())}
50 fullWidth
51 loading={busy}
52 />
53 </View>
54 ) : (
55 <Text className="text-xs text-foreground-muted">
56 {notice.kind === "failed"
57 ? "Reconnect or ask someone with write access to retry."
58 : "Writing a guide requires a connection and write access."}
59 </Text>
60 )}
61 {notice.kind === "writing" && state.data?.run?._tag === "Running" ? (
62 <Text className="shrink text-xs text-foreground-muted">
63 Started{" "}
64 {new Date(state.data.run.startedAt).toLocaleTimeString([], {
65 hour: "2-digit",
66 minute: "2-digit",
67 })}
68 </Text>
69 ) : null}
70 </View>
71 </Animated.View>
72 );