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

GuideOutline.tsx

126 lines5.0 KB

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