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

GuideOutline.tsx

114 lines4.5 KB

1import type { PullRequestReviewGuide } from "@t3tools/contracts";
2import { stopFilePaths } from "@t3tools/client-runtime/review-guide-tour";
3import { Pressable, View } from "react-native";
4import { AppText as Text } from "../../../components/ui/AppText";
5import { SymbolView } from "../../../components/ui/AppSymbol";
6import { PullRequestMarkdown } from "../PullRequestMarkdown";
7import { Menu } from "../../../components/ui/Menu";
8​
9import { useAppearancePreferences } from "../../settings/appearance/AppearancePreferencesProvider";
10​
11export function GuideOutline({
12 guide,
13 onOpen,
14 onRewrite,
15}: {
16 readonly guide: PullRequestReviewGuide;
17 readonly onOpen: (position: number) => void;
18 readonly onRewrite?: () => void;
19}) {
20 const { appearance, setCodeWordBreak } = useAppearancePreferences();
21 const files = new Set(guide.stops.flatMap(stopFilePaths));
22 return (
23 <View>
24 <View className="mb-5 flex-row items-center justify-between">
25 <View className="flex-row items-baseline gap-2">
26 <Text className="text-base font-t3-semibold">{guide.stops.length} stops</Text>
27 <Text className="text-sm text-foreground-muted">
28 through {files.size} {files.size === 1 ? "file" : "files"}
29 </Text>
30 </View>
31 <Menu
32 title="Guide options"
33 actions={[
34 {
35 id: "word-wrap",
36 title: "Word wrap",
37 image: "text.alignleft",
38 state: appearance.codeWordBreak ? "on" : "off",
39 },
40 ...(onRewrite
41 ? [{ id: "rewrite", title: "Rewrite guide", image: "arrow.clockwise" }]
42 : []),
43 ]}
44 onPressAction={({ nativeEvent }) =>
45 nativeEvent.event === "word-wrap"
46 ? setCodeWordBreak(!appearance.codeWordBreak)
47 : onRewrite?.()
48 }
49 >
50 <Pressable
51 accessibilityRole="button"
52 accessibilityLabel="Guide options"
53 className="h-11 w-11 items-center justify-center rounded-full active:bg-grouped-card"
54 >
55 <SymbolView name="ellipsis" size={20} tintColorClassName="accent-icon-muted" />
56 </Pressable>
57 </Menu>
58 </View>
59 {guide.stops[0]?.summary ? (
60 <View className="mb-6">
61 <PullRequestMarkdown markdown={guide.stops[0].summary} />
62 </View>
63 ) : null}
64 {guide.stops.map((stop, position) => {
65 const paths = stopFilePaths(stop);
66 const firstPath = paths[0];
67 const filename = firstPath?.split("/").at(-1);
68 return (
69 <Pressable
70 key={`${guide.headSha}:${JSON.stringify(stop)}`}
71 accessibilityRole="button"
72 accessibilityLabel={`Stop ${position + 1}: ${stop.title}`}
73 onPress={() => onOpen(position)}
74 className="flex-row gap-4 active:opacity-60"
75 >
76 <View className="w-8 items-center">
77 <View className="h-8 w-8 items-center justify-center rounded-full border border-border bg-grouped-card">
78 <Text className="text-sm font-t3-medium tabular-nums">{position + 1}</Text>
79 </View>
80 {position < guide.stops.length - 1 ? (
81 <View className="min-h-5 w-px flex-1 bg-border-subtle" />
82 ) : null}
83 </View>
84 <View className="min-w-0 flex-1 gap-2 pb-7 pt-0.5">
85 <Text className="text-base leading-6 font-t3-medium">{stop.title}</Text>
86 <View className="flex-row items-center gap-1.5">
87 {stop.attention ? (
88 <SymbolView name="eye" size={14} tintColorClassName="accent-warning-foreground" />
89 ) : null}
90 <Text className="shrink text-xs text-foreground-muted" numberOfLines={1}>
91 {filename ?? "Context"}
92 {paths.length > 1 ? ` +${paths.length - 1}` : ""}
93 </Text>
94 </View>
95 </View>
96 <View className="pt-2">
97 <SymbolView name="chevron.right" size={12} tintColorClassName="accent-icon-muted" />
98 </View>
99 </Pressable>
100 );
101 })}
102 {guide.stops.length ? (
103 <Pressable
104 accessibilityRole="button"
105 onPress={() => onOpen(0)}
106 className="min-h-11 flex-row items-center justify-end gap-2 active:opacity-60"
107 >
108 <Text className="text-sm font-t3-medium">Start tour</Text>
109 <SymbolView name="arrow.right" size={17} tintColorClassName="accent-foreground" />
110 </Pressable>
111 ) : null}
112 </View>
113 );