The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 18:15 UTC
feat(mobile): manage labels, edit PRs and comments, react, and refresh checks live (#24602)
Julius Marminge committed
Oct 24, 2026 at 19:00 UTC
edb2b2f3657b40a08c401f2c769823c58c82db45
31 files changed
+1056
-239
apps/mobile/src/Stack.tsx
+25
@@ -32,6 +32,8 @@ import {
32
import { PullRequestFilesSheet } from "./features/pull-requests/PullRequestFiles";
33
import { PullRequestReviewSheet } from "./features/pull-requests/PullRequestReviewSheet";
34
import { PullRequestReviewersScreen } from "./features/pull-requests/PullRequestReviewersScreen";
35
+import { PullRequestLabelsScreen } from "./features/pull-requests/PullRequestLabelsScreen";
36
+import { PullRequestEditScreen } from "./features/pull-requests/PullRequestEditScreen";
37
import { PullRequestFilterSearchScreen } from "./features/pull-requests/PullRequestFilterSearchScreen";
38
import {
39
RenderErrorBoundary,
@@ -669,6 +671,20 @@ const RootStackConfig = createWorkspaceStackNavigator({
671
headerBackVisible: false,
672
},
673
}),
674
+ PullRequestLabels: createNativeStackScreen({
675
+ screen: PullRequestLabelsScreen,
676
+ // Presented like PullRequestFilterSearch, whose search sheet it shares.
677
+ options:
678
+ Platform.OS === "android"
679
+ ? { presentation: "card", headerShown: false }
680
+ : {
681
+ ...DETAIL_HEADER_OPTIONS,
682
+ ...HORIZONTAL_FORM_SHEET_OPTIONS,
683
+ sheetAllowedDetents: formSheetDetents(0.75),
684
+ sheetGrabberVisible: true,
685
+ headerBackVisible: false,
686
+ },
687
+ }),
688
PullRequestFilterSearch: createNativeStackScreen({
689
screen: PullRequestFilterSearchScreen,
690
// Android pushes it like the branch picker; a formSheet there leaves the list's header
@@ -707,6 +723,15 @@ const RootStackConfig = createWorkspaceStackNavigator({
723
sheetGrabberVisible: true,
724
},
725
}),
726
+ PullRequestEdit: createNativeStackScreen({
727
+ screen: PullRequestEditScreen,
728
+ options: {
729
+ ...(Platform.OS === "ios" ? SHEET_GLASS_HEADER_OPTIONS : undefined),
730
+ ...HORIZONTAL_FORM_SHEET_OPTIONS,
731
+ sheetAllowedDetents: formSheetDetents(0.75),
732
+ sheetGrabberVisible: true,
733
+ },
734
+ }),
735
Thread: createNativeStackScreen({
736
screen: ThreadRouteScreen,
737
linking: { path: "threads/:environmentId?/:threadId?", alias: ["new/draft"] },
apps/mobile/src/components/ui/AppSymbol.tsx
+4
@@ -44,6 +44,8 @@ import IconCircleCheck from "@tabler/icons-react-native/IconCircleCheck";
44
import IconCircleDashed from "@tabler/icons-react-native/IconCircleDashed";
45
import IconCircleDot from "@tabler/icons-react-native/IconCircleDot";
46
import IconCircleXFilled from "@tabler/icons-react-native/IconCircleXFilled";
47
+import IconMoodPlus from "@tabler/icons-react-native/IconMoodPlus";
48
+import IconTag from "@tabler/icons-react-native/IconTag";
49
import IconTicket from "@tabler/icons-react-native/IconTicket";
50
import IconClock from "@tabler/icons-react-native/IconClock";
51
import IconCode from "@tabler/icons-react-native/IconCode";
@@ -184,6 +186,8 @@ const ANDROID_ICON_BY_SF_SYMBOL = {
186
"calendar.badge.clock": IconCalendarClock,
187
clock: IconClock,
188
timer: IconClock,
189
+ "face.smiling": IconMoodPlus,
190
+ tag: IconTag,
191
ticket: IconTicket,
192
cloud: IconCloud,
193
cube: IconBox,
apps/mobile/src/features/pull-requests/PullRequestDescription.tsx
+3
-1
@@ -5,7 +5,7 @@ import {
5
PullRequestMediaContext,
6
} from "./PullRequestMedia";
7
import { PullRequestSectionHeading } from "./PullRequestSectionHeading";
8
-import { useContext, useMemo, useState } from "react";
8
+import { useContext, useMemo, useState, type ReactNode } from "react";
9
import { Platform, Pressable, ScrollView, StyleSheet, View } from "react-native";
10
import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg";
11
import { pullRequestImageSource } from "./pullRequestMediaSource";
@@ -25,6 +25,7 @@ export function PullRequestDescription(props: {
25
readonly onCollapse: () => void;
26
readonly expanded: boolean;
27
readonly onExpandedChange: (expanded: boolean) => void;
28
+ readonly footer?: ReactNode;
29
}) {
30
const { expanded, onExpandedChange } = props;
31
const [bodyHeight, setBodyHeight] = useState(0);
@@ -138,6 +139,7 @@ export function PullRequestDescription(props: {
139
) : (
140
<Text className="text-sm text-foreground-muted">No description provided.</Text>
141
)}
142
+ {props.footer}
143
</View>
144
{content.attachments.length ? (
145
<View className="gap-3">
apps/mobile/src/features/pull-requests/PullRequestDiscussionScreen.tsx
+21
-1
@@ -1,7 +1,7 @@
1
import { Toolbar } from "../../components/ui/Toolbar";
2
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
3
import { useAtomRefresh } from "@effect/atom-react";
4
-import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
4
+import { useFocusEffect, useNavigation, type StaticScreenProps } from "@react-navigation/native";
5
import {
6
type AtomCommandResult,
7
squashAtomCommandFailure,
@@ -24,6 +24,7 @@ import { useAtomCommand } from "../../state/use-atom-command";
24
import { useEnvironmentQuery } from "../../state/query";
25
import { PullRequestMarkdown, PullRequestMarkdownRepository } from "./PullRequestMarkdown";
26
import { PullRequestAvatar } from "./PullRequestPresentation";
27
+import { PullRequestCommentFooter } from "./PullRequestReactions";
28
import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff";
29
import { usePullRequestPermissions } from "./usePullRequestPermissions";
30
import { pullRequestReviewKey } from "./pullRequestReviewDrafts";
@@ -63,6 +64,15 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
64
const [error, setError] = useState<string | null>(null);
65
const [notice, setNotice] = useState<string | null>(null);
66
const [composerHeight, setComposerHeight] = useState(64);
67
+ // Replies from "Load more" live only here, outside the activity an edit refreshes. After one
68
+ // is edited, drop the loaded pages so the next load reads the new body instead of the old one.
69
+ const extraEdited = useRef(false);
70
+ useFocusEffect(() => {
71
+ if (!extraEdited.current) return;
72
+ extraEdited.current = false;
73
+ setExtra([]);
74
+ setCursor(undefined);
75
+ });
76
const operation = async (run: () => Promise<AtomCommandResult<unknown, unknown> | undefined>) => {
77
if (pending.current) return;
78
pending.current = true;
@@ -200,6 +210,16 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
210
</Text>
211
</View>
212
<PullRequestMarkdown markdown={comment.body} />
213
+ <PullRequestCommentFooter
214
+ params={params}
215
+ comment={{ ...comment, kind: "review-comment" }}
216
+ permissions={permissions}
217
+ onChanged={refresh}
218
+ onEdit={() => {
219
+ if (extra.some((loaded) => loaded.id === comment.id))
220
+ extraEdited.current = true;
221
+ }}
222
+ />
223
</View>
224
))}
225
{nextCursor ? (
apps/mobile/src/features/pull-requests/PullRequestEditScreen.tsx
new
+169
@@ -0,0 +1,169 @@
1
+import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
2
+import {
3
+ capitalizeTerm,
4
+ sourceControlClients,
5
+} from "@t3tools/client-runtime/source-control-clients";
6
+import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
7
+import { useAtomValue } from "@effect/atom-react";
8
+import type { PullRequestComment } from "@t3tools/contracts";
9
+import { AsyncResult } from "effect/reactivity";
10
+import { useRef, useState } from "react";
11
+import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText";
12
+import { Button } from "../../components/ui/Button";
13
+import { composerPullRequests } from "../../state/pull-requests";
14
+import { useEnvironmentQuery } from "../../state/query";
15
+import { useAtomCommand } from "../../state/use-atom-command";
16
+import { PullRequestSheetContent } from "./PullRequestSheetContent";
17
+import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff";
18
+import { usePullRequestPermissions } from "./usePullRequestPermissions";
19
+
20
+export type PullRequestEditParams = PullRequestParams &
21
+ (
22
+ | { readonly field: "title" | "body" }
23
+ | {
24
+ readonly field: "comment";
25
+ /** Carried along because a reply loaded page by page is not in the cached activity. */
26
+ readonly comment: Pick<PullRequestComment, "id" | "body" | "author" | "canEdit"> & {
27
+ readonly kind: "issue-comment" | "review-comment";
28
+ };
29
+ }
30
+ );
31
+
32
+export function PullRequestEditScreen({ route }: StaticScreenProps<PullRequestEditParams>) {
33
+ const params = route.params;
34
+ const navigation = useNavigation();
35
+ const target = pullRequestTarget(params);
36
+ const detail = useEnvironmentQuery(composerPullRequests.detail(target));
37
+ const pr = detail.data;
38
+ const permissions = usePullRequestPermissions(params, pr);
39
+ const update = useAtomCommand(composerPullRequests.update, { reportFailure: false });
40
+ const updateComment = useAtomCommand(composerPullRequests.updateComment, {
41
+ reportFailure: false,
42
+ });
43
+ const singular = sourceControlClients.get(pr?.provider).changeRequest.singular;
44
+ const original =
45
+ params.field === "comment"
46
+ ? params.comment.body
47
+ : params.field === "title"
48
+ ? (pr?.title ?? null)
49
+ : (pr?.body ?? null);
50
+ const [draft, setDraft] = useState<string | null>(null);
51
+ const value = draft ?? original ?? "";
52
+ const [busy, setBusy] = useState(false);
53
+ const [error, setError] = useState<string | null>(null);
54
+ const inFlight = useRef(false);
55
+ const allowed =
56
+ params.field === "comment"
57
+ ? permissions.canEditComment(params.comment)
58
+ : permissions.canEditChangeRequest;
59
+ const canWrite = useAtomValue(
60
+ (params.field === "comment"
61
+ ? composerPullRequests.updateComment
62
+ : composerPullRequests.update
63
+ ).permissionAtom(target.environmentId),
64
+ );
65
+ // Name the first thing in the way, so the notice says what would actually fix it.
66
+ const readOnlyReason =
67
+ !pr || allowed
68
+ ? null
69
+ : !permissions.connected
70
+ ? "Reconnect to save changes."
71
+ : !canWrite
72
+ ? "This device isn't allowed to change source control on this environment."
73
+ : params.field === "comment"
74
+ ? "You can't edit this comment."
75
+ : `You can't edit this ${singular}.`;
76
+ const unchanged = draft === null || draft === original;
77
+ const invalid = params.field === "title" && value.trim().length === 0;
78
+ const save = async () => {
79
+ if (!allowed || unchanged || invalid || inFlight.current) return;
80
+ inFlight.current = true;
81
+ setBusy(true);
82
+ setError(null);
83
+ const result =
84
+ params.field === "comment"
85
+ ? await updateComment({
86
+ ...target,
87
+ input: {
88
+ ...target.input,
89
+ commentId: params.comment.id,
90
+ kind: params.comment.kind,
91
+ body: value,
92
+ },
93
+ })
94
+ : await update({
95
+ ...target,
96
+ input: {
97
+ ...target.input,
98
+ ...(params.field === "title" ? { title: value.trim() } : { body: value }),
99
+ },
100
+ });
101
+ inFlight.current = false;
102
+ setBusy(false);
103
+ if (AsyncResult.isFailure(result)) {
104
+ const cause = squashAtomCommandFailure(result);
105
+ setError(cause instanceof Error ? cause.message : "The provider refused the change.");
106
+ return;
107
+ }
108
+ // updateComment refreshes the activity on its own; a title or body lives on the detail.
109
+ if (params.field !== "comment") detail.refresh();
110
+ navigation.goBack();
111
+ };
112
+ const title =
113
+ params.field === "title"
114
+ ? "Edit title"
115
+ : params.field === "body"
116
+ ? "Edit description"
117
+ : "Edit comment";
118
+ return (
119
+ <PullRequestSheetContent
120
+ busy={busy}
121
+ title={title}
122
+ subtitle={`#${params.number} · ${params.repository}`}
123
+ footer={
124
+ <Button
125
+ fullWidth
126
+ tone="contrast"
127
+ label={busy ? "Saving…" : "Save"}
128
+ loading={busy}
129
+ disabled={!allowed || unchanged || invalid || original === null}
130
+ onPress={() => void save()}
131
+ />
132
+ }
133
+ >
134
+ <TextInput
135
+ multiline={params.field !== "title"}
136
+ editable={!busy && original !== null}
137
+ autoFocus
138
+ accessibilityLabel={
139
+ params.field === "title"
140
+ ? `${capitalizeTerm(singular)} title`
141
+ : params.field === "body"
142
+ ? `${capitalizeTerm(singular)} description`
143
+ : "Comment"
144
+ }
145
+ placeholder={params.field === "title" ? "Title" : "Write in Markdown…"}
146
+ placeholderTextColorClassName="accent-foreground-muted"
147
+ maxLength={params.field === "title" ? 1024 : 65536}
148
+ value={value}
149
+ onChangeText={setDraft}
150
+ returnKeyType={params.field === "title" ? "done" : undefined}
151
+ onSubmitEditing={params.field === "title" ? () => void save() : undefined}
152
+ className={
153
+ params.field === "title"
154
+ ? "min-h-12 rounded-[20px] bg-grouped-card px-4 text-base text-foreground"
155
+ : "min-h-48 rounded-[20px] bg-grouped-card p-4 text-base text-foreground"
156
+ }
157
+ style={params.field === "title" ? undefined : { textAlignVertical: "top" }}
158
+ />
159
+ {readOnlyReason ? (
160
+ <Text className="text-xs text-foreground-muted">{readOnlyReason}</Text>
161
+ ) : null}
162
+ {error || detail.error ? (
163
+ <Text selectable className="text-sm text-danger-foreground">
164
+ {error ?? detail.error}
165
+ </Text>
166
+ ) : null}
167
+ </PullRequestSheetContent>
168
+ );
169
+}
apps/mobile/src/features/pull-requests/PullRequestFilterSearchScreen.tsx
+62
-129
@@ -8,25 +8,17 @@ import {
8
} from "@t3tools/contracts";
9
import * as Option from "effect/Option";
10
import { AsyncResult, Atom } from "effect/reactivity";
11
-import { useRef, useState } from "react";
12
-import { FlatList, Platform, View, type TextInputInstance } from "react-native";
11
+import { useState } from "react";
12
+import { FlatList, Platform } from "react-native";
13
14
-import { AndroidScreenHeader } from "../../components/ui/AndroidScreenHeader";
14
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
15
import { EmptyState } from "../../components/ui/EmptyState";
17
-import { SearchField } from "../../components/ui/SearchField";
16
import { SelectionRow } from "../../components/ui/SelectionRow";
19
-import { SheetHeader } from "../../components/ui/SheetHeader";
20
-import { Toolbar } from "../../components/ui/Toolbar";
21
-import { NativeStackScreenOptions } from "../../native/StackHeader";
22
-import { useNativeMailSearchToolbar } from "../../native/use-native-mail-search-toolbar";
17
import { composerPullRequests } from "../../state/pull-requests";
18
import { useDebouncedValue } from "../../state/queries";
25
-import {
26
- createNativeMailSearchToolbarItem,
27
- NATIVE_MAIL_SEARCH_TOOLBAR_CONTENT_INSET,
28
-} from "../layout/native-mail-search-toolbar";
19
import { pullRequestFilterChoices, pullRequestLabelColors } from "./pullRequestList";
20
+import { PullRequestLabelDot } from "./PullRequestLabelDot";
21
+import { PullRequestSearchSheet } from "./PullRequestSearchSheet";
22
import { usePullRequestListControls } from "./usePullRequestListControls";
23
24
export type PullRequestFilterSearchParams = {
@@ -63,8 +55,6 @@ export function PullRequestFilterSearchScreen({
55
const { kind, environmentId, environmentIds, suggestions, labelColors } = route.params;
56
const listControls = usePullRequestListControls();
57
const controls = listControls.controlsFor(environmentId);
66
- const integratedSearch = useNativeMailSearchToolbar();
67
- const searchRef = useRef<TextInputInstance>(null);
58
const [query, setQuery] = useState("");
59
const typed = query.trim().slice(0, 100);
60
const sent = useDebouncedValue(typed, 250);
@@ -121,124 +111,67 @@ export function PullRequestFilterSearchScreen({
111
});
112
};
113
const placeholder = kind === "labels" ? "Search labels" : "Search authors";
124
- const list = (
125
- <FlatList
126
- data={rows}
127
- keyExtractor={(value) => value.toLowerCase()}
128
- className="flex-1"
129
- contentInsetAdjustmentBehavior="automatic"
130
- automaticallyAdjustKeyboardInsets={Platform.OS === "ios"}
131
- keyboardDismissMode={Platform.OS === "ios" ? "interactive" : "on-drag"}
132
- keyboardShouldPersistTaps="handled"
133
- showsVerticalScrollIndicator={false}
134
- contentContainerStyle={{
135
- paddingHorizontal: 16,
136
- paddingTop: 16,
137
- paddingBottom: integratedSearch ? NATIVE_MAIL_SEARCH_TOOLBAR_CONTENT_INSET + 16 : 16,
138
- }}
139
- renderItem={({ item, index }) => (
140
- <SelectionRow
141
- title={item}
142
- role={kind === "labels" ? "checkbox" : "radio"}
143
- selected={isSelected(item)}
144
- isFirst={index === 0}
145
- isLast={index === rows.length - 1}
146
- leading={
147
- kind === "labels" ? (
148
- // Uncolored labels keep the dot's room so every name starts at the same edge.
149
- <View
150
- className="size-2.5 rounded-full"
151
- style={{ backgroundColor: colors[item.toLowerCase()] ?? "transparent" }}
114
+ return (
115
+ <PullRequestSearchSheet
116
+ title={kind === "labels" ? "Filter by label" : "Filter by author"}
117
+ placeholder={placeholder}
118
+ closeAccessibilityLabel={kind === "labels" ? "Close label filter" : "Close author filter"}
119
+ clearAccessibilityLabel={kind === "labels" ? "Clear label search" : "Clear author search"}
120
+ searchTextChangeId="pr-filter-option-search"
121
+ query={query}
122
+ onQueryChange={setQuery}
123
+ >
124
+ {({ paddingBottom }) => (
125
+ <FlatList
126
+ data={rows}
127
+ keyExtractor={(value) => value.toLowerCase()}
128
+ className="flex-1"
129
+ contentInsetAdjustmentBehavior="automatic"
130
+ automaticallyAdjustKeyboardInsets={Platform.OS === "ios"}
131
+ keyboardDismissMode={Platform.OS === "ios" ? "interactive" : "on-drag"}
132
+ keyboardShouldPersistTaps="handled"
133
+ showsVerticalScrollIndicator={false}
134
+ contentContainerStyle={{ paddingHorizontal: 16, paddingTop: 16, paddingBottom }}
135
+ renderItem={({ item, index }) => (
136
+ <SelectionRow
137
+ title={item}
138
+ role={kind === "labels" ? "checkbox" : "radio"}
139
+ selected={isSelected(item)}
140
+ isFirst={index === 0}
141
+ isLast={index === rows.length - 1}
142
+ leading={
143
+ kind === "labels" ? (
144
+ <PullRequestLabelDot color={colors[item.toLowerCase()] ?? null} />
145
+ ) : undefined
146
+ }
147
+ onPress={() => choose(item)}
148
+ />
149
+ )}
150
+ ListEmptyComponent={
151
+ hosted.waiting || !settled ? (
152
+ <AppActivityIndicator className="my-8" />
153
+ ) : (
154
+ <EmptyState
155
+ title={
156
+ hosted.failed
157
+ ? "Couldn't search the host"
158
+ : kind === "labels"
159
+ ? "No matching labels"
160
+ : "No matching authors"
161
+ }
162
+ detail={
163
+ hosted.failed
164
+ ? "The host didn't answer. Try again in a moment."
165
+ : kind === "labels"
166
+ ? "Search the labels of the repositories this list covers."
167
+ : "Search people by name or handle on the repositories' hosts."
168
+ }
169
+ variant="plain"
170
/>
153
- ) : undefined
171
+ )
172
}
155
- onPress={() => choose(item)}
173
/>
174
)}
158
- ListEmptyComponent={
159
- hosted.waiting || !settled ? (
160
- <AppActivityIndicator className="my-8" />
161
- ) : (
162
- <EmptyState
163
- title={
164
- hosted.failed
165
- ? "Couldn't search the host"
166
- : kind === "labels"
167
- ? "No matching labels"
168
- : "No matching authors"
169
- }
170
- detail={
171
- hosted.failed
172
- ? "The host didn't answer. Try again in a moment."
173
- : kind === "labels"
174
- ? "Search the labels of the repositories this list covers."
175
- : "Search people by name or handle on the repositories' hosts."
176
- }
177
- variant="plain"
178
- />
179
- )
180
- }
181
- />
182
- );
183
- const title = kind === "labels" ? "Filter by label" : "Filter by author";
184
- if (Platform.OS === "android") {
185
- return (
186
- <View className="flex-1 bg-sheet" collapsable={false}>
187
- <AndroidScreenHeader title={title} hideBottomBorder onBack={() => navigation.goBack()} />
188
- <View className="bg-header px-4 pb-3 pt-1">
189
- <SearchField
190
- inputRef={searchRef}
191
- accessibilityLabel={placeholder}
192
- clearAccessibilityLabel={
193
- kind === "labels" ? "Clear label search" : "Clear author search"
194
- }
195
- onChangeText={setQuery}
196
- placeholder={placeholder}
197
- value={query}
198
- />
199
- </View>
200
- {list}
201
- </View>
202
- );
203
- }
204
- return (
205
- <View className="flex-1 bg-sheet">
206
- <SheetHeader
207
- title={title}
208
- onClose={() => navigation.goBack()}
209
- accessibilityLabel={kind === "labels" ? "Close label filter" : "Close author filter"}
210
- />
211
- <NativeStackScreenOptions
212
- options={{
213
- unstable_headerToolbarItems: integratedSearch
214
- ? () => [
215
- createNativeMailSearchToolbarItem({
216
- placeholder,
217
- onSearchTextChange: setQuery,
218
- showsSearchDismissButton: true,
219
- searchTextChangeId: "pr-filter-option-search",
220
- }),
221
- ]
222
- : undefined,
223
- headerSearchBarOptions: integratedSearch
224
- ? undefined
225
- : {
226
- placeholder,
227
- allowToolbarIntegration: true,
228
- autoCapitalize: "none",
229
- hideNavigationBar: false,
230
- obscureBackground: false,
231
- onChangeText: (event) => setQuery(event.nativeEvent.text),
232
- onCancelButtonPress: () => setQuery(""),
233
- },
234
- }}
235
- />
236
- {integratedSearch ? null : (
237
- <Toolbar placement="bottom">
238
- <Toolbar.SearchBarSlot />
239
- </Toolbar>
240
- )}
241
- {list}
242
- </View>
175
+ </PullRequestSearchSheet>
176
);
177
}
apps/mobile/src/features/pull-requests/PullRequestLabelDot.tsx
new
+11
@@ -0,0 +1,11 @@
1
+import { View } from "react-native";
2
+
3
+/** A label's color mark in pickers; uncolored labels keep its room so names line up. */
4
+export function PullRequestLabelDot(props: { readonly color: string | null }) {
5
+ return (
6
+ <View
7
+ className="size-2.5 rounded-full"
8
+ style={{ backgroundColor: props.color ?? "transparent" }}
9
+ />
10
+ );
11
+}
apps/mobile/src/features/pull-requests/PullRequestLabelsScreen.tsx
new
+158
@@ -0,0 +1,158 @@
1
+import { useAtomValue } from "@effect/atom-react";
2
+import type { StaticScreenProps } from "@react-navigation/native";
3
+import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
4
+import type { PullRequestLabelCandidate } from "@t3tools/contracts";
5
+import { AsyncResult } from "effect/reactivity";
6
+import { useRef, useState } from "react";
7
+import { FlatList, Platform, View } from "react-native";
8
+import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
9
+import { AppText as Text } from "../../components/ui/AppText";
10
+import { Button } from "../../components/ui/Button";
11
+import { EmptyState } from "../../components/ui/EmptyState";
12
+import { SelectionRow } from "../../components/ui/SelectionRow";
13
+import { composerPullRequests } from "../../state/pull-requests";
14
+import { useEnvironmentQuery } from "../../state/query";
15
+import { useAtomCommand } from "../../state/use-atom-command";
16
+import { PullRequestLabelDot } from "./PullRequestLabelDot";
17
+import { pullRequestLabelColor } from "./pullRequestList";
18
+import { PullRequestSearchSheet } from "./PullRequestSearchSheet";
19
+import { usePullRequestConnected } from "./usePullRequestConnected";
20
+import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff";
21
+
22
+export function PullRequestLabelsScreen({ route }: StaticScreenProps<PullRequestParams>) {
23
+ const target = pullRequestTarget(route.params);
24
+ const pr = useEnvironmentQuery(composerPullRequests.detail(target)).data;
25
+ const canWrite = useAtomValue(
26
+ composerPullRequests.setLabels.permissionAtom(target.environmentId),
27
+ );
28
+ const connected = usePullRequestConnected(route.params.environmentId);
29
+ const allowed =
30
+ connected &&
31
+ canWrite &&
32
+ pr?.capabilities.labels === true &&
33
+ pr.viewerPermissions.labels !== false;
34
+ // Name the first thing in the way, so the notice says what would actually fix it.
35
+ const readOnlyReason =
36
+ !pr || allowed
37
+ ? null
38
+ : !connected
39
+ ? "Reconnect to change labels."
40
+ : !canWrite
41
+ ? "This device isn't allowed to change source control on this environment."
42
+ : pr.capabilities.labels !== true
43
+ ? "This provider doesn't support changing labels."
44
+ : "Changing labels needs triage access on this repository.";
45
+ const result = useEnvironmentQuery(composerPullRequests.labelCandidates(target));
46
+ const setLabels = useAtomCommand(composerPullRequests.setLabels, { reportFailure: false });
47
+ const [query, setQuery] = useState("");
48
+ const [pending, setPending] = useState<{ readonly name: string; readonly applied: boolean }>();
49
+ const [error, setError] = useState<string | null>(null);
50
+ const inFlight = useRef(false);
51
+ const needle = query.trim().toLowerCase();
52
+ // Host order, not applied-first: re-sorting on toggle would move the row out from under a tap.
53
+ const candidates = (result.data?.candidates ?? []).filter((candidate) =>
54
+ `${candidate.name} ${candidate.description ?? ""}`.toLowerCase().includes(needle),
55
+ );
56
+ const toggle = async (candidate: PullRequestLabelCandidate) => {
57
+ if (!allowed || inFlight.current) return;
58
+ inFlight.current = true;
59
+ setPending({ name: candidate.name, applied: !candidate.isApplied });
60
+ setError(null);
61
+ const response = await setLabels({
62
+ ...target,
63
+ input: { ...target.input, labels: [candidate.name], applied: !candidate.isApplied },
64
+ });
65
+ inFlight.current = false;
66
+ setPending(undefined);
67
+ if (AsyncResult.isFailure(response)) {
68
+ const cause = squashAtomCommandFailure(response);
69
+ setError(cause instanceof Error ? cause.message : "Couldn't update this label. Try again.");
70
+ }
71
+ };
72
+ return (
73
+ <PullRequestSearchSheet
74
+ title="Labels"
75
+ placeholder="Search labels"
76
+ closeAccessibilityLabel="Close labels"
77
+ clearAccessibilityLabel="Clear label search"
78
+ searchTextChangeId="pr-label-search"
79
+ query={query}
80
+ onQueryChange={setQuery}
81
+ >
82
+ {({ paddingBottom }) => (
83
+ <FlatList
84
+ data={candidates}
85
+ keyExtractor={(candidate) => candidate.name}
86
+ className="flex-1"
87
+ contentInsetAdjustmentBehavior="automatic"
88
+ automaticallyAdjustKeyboardInsets={Platform.OS === "ios"}
89
+ keyboardDismissMode={Platform.OS === "ios" ? "interactive" : "on-drag"}
90
+ keyboardShouldPersistTaps="handled"
91
+ showsVerticalScrollIndicator={false}
92
+ contentContainerStyle={{ paddingHorizontal: 16, paddingTop: 16, paddingBottom }}
93
+ ListHeaderComponent={
94
+ readOnlyReason || error ? (
95
+ <View className="gap-2 pb-3">
96
+ {readOnlyReason ? (
97
+ <Text className="text-xs text-foreground-muted">{readOnlyReason}</Text>
98
+ ) : null}
99
+ {error ? (
100
+ <Text selectable className="text-sm text-danger-foreground">
101
+ {error}
102
+ </Text>
103
+ ) : null}
104
+ </View>
105
+ ) : undefined
106
+ }
107
+ renderItem={({ item, index }) => (
108
+ <SelectionRow
109
+ title={item.name}
110
+ {...(item.description ? { subtitle: item.description } : {})}
111
+ role="checkbox"
112
+ // The change shows as soon as it is tapped; a failure puts the host's answer back.
113
+ selected={pending?.name === item.name ? pending.applied : item.isApplied}
114
+ disabled={!allowed}
115
+ isFirst={index === 0}
116
+ isLast={index === candidates.length - 1}
117
+ leading={<PullRequestLabelDot color={pullRequestLabelColor(item.color)} />}
118
+ onPress={() => void toggle(item)}
119
+ />
120
+ )}
121
+ ListEmptyComponent={
122
+ result.isPending && !result.data ? (
123
+ <AppActivityIndicator className="my-8" />
124
+ ) : (
125
+ <View>
126
+ <EmptyState
127
+ title={
128
+ result.error
129
+ ? "Couldn't load labels"
130
+ : needle
131
+ ? "No matching labels"
132
+ : "This repository has no labels"
133
+ }
134
+ detail={
135
+ result.error ??
136
+ (needle
137
+ ? "Try another name."
138
+ : "Create labels on the provider to use them here.")
139
+ }
140
+ variant="plain"
141
+ />
142
+ {result.error ? <Button label="Retry" onPress={result.refresh} /> : null}
143
+ </View>
144
+ )
145
+ }
146
+ ListFooterComponent={
147
+ result.data?.truncated ? (
148
+ <Text className="py-4 text-xs text-foreground-muted">
149
+ This repository has more labels than are listed here. Apply the rest on the
150
+ provider.
151
+ </Text>
152
+ ) : undefined
153
+ }
154
+ />
155
+ )}
156
+ </PullRequestSearchSheet>
157
+ );
158
+}
apps/mobile/src/features/pull-requests/PullRequestReactions.tsx
new
+195
@@ -0,0 +1,195 @@
1
+import { useNavigation } from "@react-navigation/native";
2
+import {
3
+ applyPendingPullRequestReactions,
4
+ PULL_REQUEST_REACTION_ORDER,
5
+ pullRequestReactionEmoji,
6
+ pullRequestReactionName,
7
+ pullRequestReactionTooltip,
8
+ pullRequestReactionsSignature,
9
+} from "@t3tools/client-runtime/pull-request-reactions";
10
+import type {
11
+ PullRequestComment,
12
+ PullRequestReaction,
13
+ PullRequestReactionContent,
14
+} from "@t3tools/contracts";
15
+import { AsyncResult } from "effect/reactivity";
16
+import { useState } from "react";
17
+import { Pressable, View } from "react-native";
18
+import { SymbolView } from "../../components/ui/AppSymbol";
19
+import { AppText as Text } from "../../components/ui/AppText";
20
+import * as Dialog from "../../components/ui/Dialog";
21
+import { Menu } from "../../components/ui/Menu";
22
+import { cn } from "../../lib/cn";
23
+import { composerPullRequests } from "../../state/pull-requests";
24
+import { useEnvironmentQuery } from "../../state/query";
25
+import { useAtomCommand } from "../../state/use-atom-command";
26
+import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff";
27
+import { usePullRequestPermissions } from "./usePullRequestPermissions";
28
+
29
+const EMPTY_PENDING: ReadonlyMap<PullRequestReactionContent, boolean> = new Map();
30
+const PILL = "min-h-8 flex-row items-center gap-1 rounded-full border px-2.5 active:opacity-70";
31
+
32
+function ReactionPills(props: {
33
+ readonly params: PullRequestParams;
34
+ readonly reactions: ReadonlyArray<PullRequestReaction>;
35
+ readonly canReact: boolean;
36
+ /** Absent reacts to the change request itself. */
37
+ readonly subjectId?: string;
38
+ readonly onChanged: () => void;
39
+}) {
40
+ const target = pullRequestTarget(props.params);
41
+ const setReaction = useAtomCommand(composerPullRequests.setReaction, { reportFailure: false });
42
+ // Keyed by what the host last reported, so a refresh that lands the change drops the overlay.
43
+ const [pending, setPending] = useState({ signature: "", values: EMPTY_PENDING });
44
+ const signature = pullRequestReactionsSignature(props.reactions);
45
+ const values = pending.signature === signature ? pending.values : EMPTY_PENDING;
46
+ const shown = applyPendingPullRequestReactions(props.reactions, values);
47
+ const toggle = async (content: PullRequestReactionContent, reacted: boolean) => {
48
+ setPending({ signature, values: new Map([...values, [content, reacted]]) });
49
+ const result = await setReaction({
50
+ ...target,
51
+ input: {
52
+ ...target.input,
53
+ ...(props.subjectId === undefined ? {} : { subjectId: props.subjectId }),
54
+ content,
55
+ reacted,
56
+ },
57
+ });
58
+ if (AsyncResult.isFailure(result)) {
59
+ setPending((current) => {
60
+ const next = new Map(current.values);
61
+ next.delete(content);
62
+ return { signature: current.signature, values: next };
63
+ });
64
+ Dialog.alert("Couldn't save the reaction", "Try again in a moment.");
65
+ return;
66
+ }
67
+ props.onChanged();
68
+ };
69
+ return (
70
+ <>
71
+ {shown.map((reaction) => (
72
+ <Pressable
73
+ key={reaction.content}
74
+ accessibilityRole="button"
75
+ accessibilityLabel={pullRequestReactionTooltip(reaction)}
76
+ accessibilityState={{ selected: reaction.viewerHasReacted, disabled: !props.canReact }}
77
+ disabled={!props.canReact}
78
+ onPress={() => void toggle(reaction.content, !reaction.viewerHasReacted)}
79
+ className={cn(
80
+ PILL,
81
+ reaction.viewerHasReacted
82
+ ? "border-primary bg-primary/10"
83
+ : "border-border-subtle bg-grouped-card",
84
+ )}
85
+ >
86
+ <Text className="text-sm">{pullRequestReactionEmoji(reaction.content)}</Text>
87
+ <Text className="text-xs font-t3-medium text-foreground-muted">{reaction.count}</Text>
88
+ </Pressable>
89
+ ))}
90
+ {props.canReact ? (
91
+ <Menu
92
+ accessibilityLabel="Add a reaction"
93
+ actions={PULL_REQUEST_REACTION_ORDER.map((content) => ({
94
+ id: content,
95
+ title: `${pullRequestReactionEmoji(content)} ${pullRequestReactionName(content)}`,
96
+ state: shown.some(
97
+ (reaction) => reaction.content === content && reaction.viewerHasReacted,
98
+ )
99
+ ? ("on" as const)
100
+ : ("off" as const),
101
+ }))}
102
+ onPressAction={({ nativeEvent }) => {
103
+ const content = PULL_REQUEST_REACTION_ORDER.find((id) => id === nativeEvent.event);
104
+ if (!content) return;
105
+ const reacted = shown.some(
106
+ (reaction) => reaction.content === content && reaction.viewerHasReacted,
107
+ );
108
+ void toggle(content, !reacted);
109
+ }}
110
+ >
111
+ <View className={cn(PILL, "border-border-subtle")}>
112
+ <SymbolView name="face.smiling" size={15} tintColorClassName="accent-icon-muted" />
113
+ </View>
114
+ </Menu>
115
+ ) : null}
116
+ </>
117
+ );
118
+}
119
+
120
+/** Reactions on the change request itself, which is where its description's reactions live. */
121
+export function PullRequestReactions(props: { readonly params: PullRequestParams }) {
122
+ const target = pullRequestTarget(props.params);
123
+ const detail = useEnvironmentQuery(composerPullRequests.detail(target));
124
+ const activity = useEnvironmentQuery(composerPullRequests.activity(target));
125
+ const { canReact } = usePullRequestPermissions(props.params, detail.data);
126
+ const reactions = activity.data?.reactions ?? [];
127
+ if (!activity.data || (reactions.length === 0 && !canReact)) return null;
128
+ return (
129
+ <View className="flex-row flex-wrap items-center gap-1.5">
130
+ <ReactionPills
131
+ params={props.params}
132
+ reactions={reactions}
133
+ canReact={canReact}
134
+ onChanged={activity.refresh}
135
+ />
136
+ </View>
137
+ );
138
+}
139
+
140
+export function PullRequestCommentFooter(props: {
141
+ readonly params: PullRequestParams;
142
+ readonly comment: Pick<
143
+ PullRequestComment,
144
+ "id" | "kind" | "body" | "author" | "canEdit" | "reactions"
145
+ >;
146
+ readonly permissions: Pick<
147
+ ReturnType<typeof usePullRequestPermissions>,
148
+ "canEditComment" | "canReact"
149
+ >;
150
+ readonly onChanged: () => void;
151
+ readonly onEdit?: () => void;
152
+}) {
153
+ const navigation = useNavigation();
154
+ const { comment } = props;
155
+ const reactions = comment.reactions ?? [];
156
+ const editableKind = comment.kind === "review" ? null : comment.kind;
157
+ const canEdit = editableKind !== null && props.permissions.canEditComment(comment);
158
+ const { canReact } = props.permissions;
159
+ if (reactions.length === 0 && !canReact && !canEdit) return null;
160
+ return (
161
+ <View className="flex-row flex-wrap items-center gap-1.5">
162
+ <ReactionPills
163
+ params={props.params}
164
+ reactions={reactions}
165
+ canReact={canReact}
166
+ subjectId={comment.id}
167
+ onChanged={props.onChanged}
168
+ />
169
+ {canEdit && editableKind !== null ? (
170
+ <Pressable
171
+ accessibilityRole="button"
172
+ accessibilityLabel="Edit comment"
173
+ onPress={() => {
174
+ props.onEdit?.();
175
+ navigation.navigate("PullRequestEdit", {
176
+ ...props.params,
177
+ field: "comment",
178
+ comment: {
179
+ id: comment.id,
180
+ kind: editableKind,
181
+ body: comment.body,
182
+ author: comment.author,
183
+ ...(comment.canEdit === undefined ? {} : { canEdit: comment.canEdit }),
184
+ },
185
+ });
186
+ }}
187
+ className={cn(PILL, "ml-auto border-transparent")}
188
+ >
189
+ <SymbolView name="pencil" size={13} tintColorClassName="accent-icon-muted" />
190
+ <Text className="text-xs font-t3-medium text-foreground-muted">Edit</Text>
191
+ </Pressable>
192
+ ) : null}
193
+ </View>
194
+ );
195
+}
apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx
+97
-10
@@ -43,7 +43,7 @@ import {
43
import { usePullRequestDiffHighlightFiles } from "./usePullRequestDiffHighlightFiles";
44
import { isPullRequestTestFile } from "./pullRequestFileFilters";
45
import { useFocusEffect, useNavigation, type StaticScreenProps } from "@react-navigation/native";
46
-import { RegistryContext, useAtomRefresh } from "@effect/atom-react";
46
+import { RegistryContext, useAtomRefresh, useAtomValue } from "@effect/atom-react";
47
import { pullRequestReviewKey } from "./pullRequestReviewDrafts";
48
import { type PullRequestDetail, type PullRequestListEntry } from "@t3tools/contracts";
49
import { PullRequestOverviewLoading } from "./PullRequestOverviewLoading";
@@ -76,6 +76,9 @@ import { SymbolView } from "../../components/ui/AppSymbol";
76
import { relativeTime } from "../../lib/time";
77
import { NativeStackScreenOptions } from "../../native/StackHeader";
78
import { usePullRequestConnected } from "./usePullRequestConnected";
79
+import { usePullRequestLiveChecks } from "./usePullRequestLiveChecks";
80
+import { pullRequestLabelColor } from "./pullRequestList";
81
+import { PullRequestReactions } from "./PullRequestReactions";
82
import { composerPullRequests } from "../../state/pull-requests";
83
import { useEnvironmentQuery } from "../../state/query";
84
import { usePullToRefresh } from "../../state/use-pull-to-refresh";
@@ -135,10 +138,15 @@ function PullRequestTabScrollView(props: ScrollViewProps) {
138
function usePullRequestActivityRows(params: PullRequestParams, filter: ActivityFilter) {
139
const navigation = useNavigation();
140
const result = useEnvironmentQuery(composerPullRequests.activity(requestTarget(params)));
141
+ const detail = useEnvironmentQuery(composerPullRequests.detail(requestTarget(params)));
142
+ const permissions = usePullRequestPermissions(params, detail.data);
143
const filtered = result.data ? filterPullRequestActivity(result.data, filter) : null;
144
const rows = (() => {
145
if (!filtered) return [];
141
- const rows = pullRequestTimelineRows(filtered.activity, params, navigation);
146
+ const rows = pullRequestTimelineRows(filtered.activity, params, navigation, {
147
+ permissions,
148
+ onChanged: result.refresh,
149
+ });
150
if (filter.newestFirst) {
151
const notice = rows.at(-1)?.key === "truncated" ? rows.pop() : undefined;
152
rows.reverse();
@@ -229,6 +237,54 @@ function PullRequestIdentity(props: {
237
);
238
}
239
240
+function PullRequestLabels(props: {
241
+ readonly pr: PullRequestDetail;
242
+ readonly params: PullRequestParams;
243
+}) {
244
+ const navigation = useNavigation();
245
+ const connected = usePullRequestConnected(props.params.environmentId);
246
+ const canWrite = useAtomValue(
247
+ composerPullRequests.setLabels.permissionAtom(requestTarget(props.params).environmentId),
248
+ );
249
+ const editable =
250
+ connected &&
251
+ canWrite &&
252
+ props.pr.capabilities.labels === true &&
253
+ props.pr.viewerPermissions.labels !== false;
254
+ if (!props.pr.labels.length && !editable) return null;
255
+ return (
256
+ <Animated.View layout={PR_ROW_LAYOUT} className="flex-row flex-wrap gap-2">
257
+ {props.pr.labels.map((label) => {
258
+ const color = pullRequestLabelColor(label.color);
259
+ // Tinted like the list row's label pills, at the overview's chip size.
260
+ return (
261
+ <View
262
+ key={label.name}
263
+ className="max-w-full flex-row items-center gap-1.5 rounded-2xl bg-grouped-card px-3 py-1"
264
+ style={color ? { backgroundColor: `${color}20` } : undefined}
265
+ >
266
+ {color ? (
267
+ <View style={{ width: 6, height: 6, borderRadius: 3, backgroundColor: color }} />
268
+ ) : null}
269
+ <Text textRole="caption" className="shrink text-foreground-muted" numberOfLines={1}>
270
+ {label.name}
271
+ </Text>
272
+ </View>
273
+ );
274
+ })}
275
+ {editable ? (
276
+ <Chip
277
+ label={props.pr.labels.length ? "Edit" : "Add labels"}
278
+ icon="tag"
279
+ size="small"
280
+ accessibilityLabel="Edit labels"
281
+ onPress={() => navigation.navigate("PullRequestLabels", props.params)}
282
+ />
283
+ ) : null}
284
+ </Animated.View>
285
+ );
286
+}
287
+
288
function PullRequestOverview(props: {
289
readonly pr: PullRequestDetail;
290
readonly params: PullRequestParams;
@@ -252,13 +308,7 @@ function PullRequestOverview(props: {
308
<PullRequestMergeControls pr={pr} params={props.params} stack={props.stack} />
309
</Animated.View>
310
</PullRequestCardGroup>
255
- {pr.labels.length ? (
256
- <Animated.View layout={PR_ROW_LAYOUT} className="flex-row flex-wrap gap-2">
257
- {pr.labels.map((label) => (
258
- <Chip key={label.name} label={label.name} size="small" />
259
- ))}
260
- </Animated.View>
261
- ) : null}
311
+ <PullRequestLabels pr={pr} params={props.params} />
312
<Animated.View
313
layout={PR_POSITION_LAYOUT}
314
onLayout={(event) => props.onDescriptionLayout(event.nativeEvent.layout.y)}
@@ -268,6 +318,7 @@ function PullRequestOverview(props: {
318
onCollapse={props.onDescriptionCollapse}
319
expanded={props.descriptionExpanded}
320
onExpandedChange={props.onDescriptionExpandedChange}
321
+ footer={<PullRequestReactions params={props.params} />}
322
/>
323
</Animated.View>
324
</View>
@@ -347,7 +398,7 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
398
const pullRefresh = usePullToRefresh(detailAtom);
399
const { refresh: refreshDetail } = result;
400
useFocusEffect(() => refreshDetail());
350
- const pr = result.data;
401
+ const pr = usePullRequestLiveChecks(params, result.data);
402
const summary = params.initialSummary;
403
const identity = pr ?? summary;
404
const terminology = sourceControlClients.get(identity?.provider).changeRequest;
@@ -436,6 +487,24 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
487
},
488
]
489
: []),
490
+ ...(permissions.canEditChangeRequest
491
+ ? [
492
+ {
493
+ accessibilityLabel: "Edit title",
494
+ icon: "pencil" as const,
495
+ overflowOnly: true,
496
+ onPress: () =>
497
+ navigation.navigate("PullRequestEdit", { ...params, field: "title" }),
498
+ },
499
+ {
500
+ accessibilityLabel: "Edit description",
501
+ icon: "doc.text" as const,
502
+ overflowOnly: true,
503
+ onPress: () =>
504
+ navigation.navigate("PullRequestEdit", { ...params, field: "body" }),
505
+ },
506
+ ]
507
+ : []),
508
...(identity
509
? [
510
{
@@ -498,6 +567,24 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
567
<Toolbar.Label>Add comment</Toolbar.Label>
568
</Toolbar.MenuAction>
569
) : null}
570
+ {permissions.canEditChangeRequest ? (
571
+ <Toolbar.MenuAction
572
+ icon="pencil"
573
+ onPress={() =>
574
+ navigation.navigate("PullRequestEdit", { ...params, field: "title" })
575
+ }
576
+ >
577
+ <Toolbar.Label>Edit title</Toolbar.Label>
578
+ </Toolbar.MenuAction>
579
+ ) : null}
580
+ {permissions.canEditChangeRequest ? (
581
+ <Toolbar.MenuAction
582
+ icon="doc.text"
583
+ onPress={() => navigation.navigate("PullRequestEdit", { ...params, field: "body" })}
584
+ >
585
+ <Toolbar.Label>Edit description</Toolbar.Label>
586
+ </Toolbar.MenuAction>
587
+ ) : null}
588
{identity ? (
589
<Toolbar.MenuAction
590
icon="arrow.up.right"
apps/mobile/src/features/pull-requests/PullRequestSearchSheet.tsx
new
+99
@@ -0,0 +1,99 @@
1
+import { useNavigation } from "@react-navigation/native";
2
+import { useRef, type ReactNode } from "react";
3
+import { Platform, View, type TextInputInstance } from "react-native";
4
+
5
+import { AndroidScreenHeader } from "../../components/ui/AndroidScreenHeader";
6
+import { SearchField } from "../../components/ui/SearchField";
7
+import { SheetHeader } from "../../components/ui/SheetHeader";
8
+import { Toolbar } from "../../components/ui/Toolbar";
9
+import { NativeStackScreenOptions } from "../../native/StackHeader";
10
+import { useNativeMailSearchToolbar } from "../../native/use-native-mail-search-toolbar";
11
+import {
12
+ createNativeMailSearchToolbarItem,
13
+ NATIVE_MAIL_SEARCH_TOOLBAR_CONTENT_INSET,
14
+} from "../layout/native-mail-search-toolbar";
15
+
16
+/**
17
+ * A searchable picker over a pull request list or a pull request: a pushed card with a search
18
+ * field on Android, a sheet with the native search toolbar on iOS.
19
+ */
20
+export function PullRequestSearchSheet(props: {
21
+ readonly title: string;
22
+ readonly placeholder: string;
23
+ readonly closeAccessibilityLabel: string;
24
+ readonly clearAccessibilityLabel: string;
25
+ readonly searchTextChangeId: string;
26
+ readonly query: string;
27
+ readonly onQueryChange: (query: string) => void;
28
+ /** Renders the list, given the bottom padding that keeps its end clear of the search bar. */
29
+ readonly children: (list: { readonly paddingBottom: number }) => ReactNode;
30
+}) {
31
+ const navigation = useNavigation();
32
+ const integratedSearch = useNativeMailSearchToolbar();
33
+ const searchRef = useRef<TextInputInstance>(null);
34
+ const list = props.children({
35
+ paddingBottom: integratedSearch ? NATIVE_MAIL_SEARCH_TOOLBAR_CONTENT_INSET + 16 : 16,
36
+ });
37
+ if (Platform.OS === "android") {
38
+ return (
39
+ <View className="flex-1 bg-sheet" collapsable={false}>
40
+ <AndroidScreenHeader
41
+ title={props.title}
42
+ hideBottomBorder
43
+ onBack={() => navigation.goBack()}
44
+ />
45
+ <View className="bg-header px-4 pb-3 pt-1">
46
+ <SearchField
47
+ inputRef={searchRef}
48
+ accessibilityLabel={props.placeholder}
49
+ clearAccessibilityLabel={props.clearAccessibilityLabel}
50
+ onChangeText={props.onQueryChange}
51
+ placeholder={props.placeholder}
52
+ value={props.query}
53
+ />
54
+ </View>
55
+ {list}
56
+ </View>
57
+ );
58
+ }
59
+ return (
60
+ <View className="flex-1 bg-sheet">
61
+ <SheetHeader
62
+ title={props.title}
63
+ onClose={() => navigation.goBack()}
64
+ accessibilityLabel={props.closeAccessibilityLabel}
65
+ />
66
+ <NativeStackScreenOptions
67
+ options={{
68
+ unstable_headerToolbarItems: integratedSearch
69
+ ? () => [
70
+ createNativeMailSearchToolbarItem({
71
+ placeholder: props.placeholder,
72
+ onSearchTextChange: props.onQueryChange,
73
+ showsSearchDismissButton: true,
74
+ searchTextChangeId: props.searchTextChangeId,
75
+ }),
76
+ ]
77
+ : undefined,
78
+ headerSearchBarOptions: integratedSearch
79
+ ? undefined
80
+ : {
81
+ placeholder: props.placeholder,
82
+ allowToolbarIntegration: true,
83
+ autoCapitalize: "none",
84
+ hideNavigationBar: false,
85
+ obscureBackground: false,
86
+ onChangeText: (event) => props.onQueryChange(event.nativeEvent.text),
87
+ onCancelButtonPress: () => props.onQueryChange(""),
88
+ },
89
+ }}
90
+ />
91
+ {integratedSearch ? null : (
92
+ <Toolbar placement="bottom">
93
+ <Toolbar.SearchBarSlot />
94
+ </Toolbar>
95
+ )}
96
+ {list}
97
+ </View>
98
+ );
99
+}
apps/mobile/src/features/pull-requests/PullRequestTimeline.tsx
+24
-3
@@ -4,7 +4,7 @@ import { useAppearancePreferences } from "../settings/appearance/AppearancePrefe
4
import IconGitCommit from "@tabler/icons-react-native/IconGitCommit";
5
import type { PullRequestActivity, PullRequestComment } from "@t3tools/contracts";
6
import { StackActions, type NavigationProp } from "@react-navigation/native";
7
-import { useMemo, useState, type ReactNode } from "react";
7
+import { useMemo, useState, type ComponentProps, type ReactNode } from "react";
8
import { Pressable, StyleSheet, View } from "react-native";
9
import { parseMarkdownDocument } from "../../lib/markdownDocument";
10
import { AppText as Text } from "../../components/ui/AppText";
@@ -12,6 +12,7 @@ import { SymbolView, type AppSymbolName } from "../../components/ui/AppSymbol";
12
import { relativeTime } from "../../lib/time";
13
import { PullRequestAvatar } from "./PullRequestPresentation";
14
import { PullRequestMarkdown } from "./PullRequestMarkdown";
15
+import { PullRequestCommentFooter } from "./PullRequestReactions";
16
import { pullRequestDescriptionContent } from "./pullRequestDescriptionContent";
17
import type { PullRequestParams } from "./usePullRequestDiff";
18
@@ -57,7 +58,20 @@ function TimelineEvent(props: {
58
);
59
}
60
60
-function TimelineComment({ comment }: { comment: PullRequestComment }) {
61
+type CommentActions = {
62
+ readonly permissions: ComponentProps<typeof PullRequestCommentFooter>["permissions"];
63
+ readonly onChanged: () => void;
64
+};
65
+
66
+function TimelineComment({
67
+ comment,
68
+ params,
69
+ actions,
70
+}: {
71
+ comment: PullRequestComment;
72
+ params: PullRequestParams;
73
+ actions: CommentActions;
74
+}) {
75
const [expanded, setExpanded] = useState(false);
76
const { themeVariables: colors } = useAppearancePreferences();
77
const long = comment.body.length > 450 || comment.body.split("\n").length > 8;
@@ -169,6 +183,12 @@ function TimelineComment({ comment }: { comment: PullRequestComment }) {
183
) : null}
184
</View>
185
) : null}
186
+ <PullRequestCommentFooter
187
+ params={params}
188
+ comment={comment}
189
+ permissions={actions.permissions}
190
+ onChanged={actions.onChanged}
191
+ />
192
</TimelineEvent>
193
);
194
}
@@ -177,6 +197,7 @@ export function pullRequestTimelineRows(
197
activity: PullRequestActivity,
198
params: PullRequestParams,
199
navigation: Pick<NavigationProp<ReactNavigation.RootParamList>, "navigate" | "dispatch">,
200
+ actions: CommentActions,
201
) {
202
const discussionIds = new Set(
203
activity.reviewThreads.flatMap((thread) => thread.comments.map((comment) => comment.id)),
@@ -187,7 +208,7 @@ export function pullRequestTimelineRows(
208
.map((comment) => ({
209
key: `comment:${comment.id}`,
210
date: comment.createdAt,
190
- content: <TimelineComment comment={comment} />,
211
+ content: <TimelineComment comment={comment} params={params} actions={actions} />,
212
})),
213
...activity.reviewThreads.map((thread) => ({
214
key: `discussion:${thread.id}`,
apps/mobile/src/features/pull-requests/usePullRequestLiveChecks.ts
new
+42
@@ -0,0 +1,42 @@
1
+import { useFocusEffect } from "@react-navigation/native";
2
+import {
3
+ pullRequestChecksRefreshIntervalMs,
4
+ resolvePullRequestDetailChecks,
5
+} from "@t3tools/client-runtime/pull-request-checks";
6
+import type { PullRequestDetail } from "@t3tools/contracts";
7
+import { useEnvironmentServerConfig } from "../../state/entities";
8
+import { composerPullRequests } from "../../state/pull-requests";
9
+import { useEnvironmentQuery } from "../../state/query";
10
+import { usePullRequestConnected } from "./usePullRequestConnected";
11
+import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff";
12
+
13
+/**
14
+ * Re-reads only the checks while an open change request is on screen, so a running CI shows up
15
+ * without paying for a full detail read every poll.
16
+ */
17
+export function usePullRequestLiveChecks(
18
+ params: PullRequestParams,
19
+ detail: PullRequestDetail | null,
20
+): PullRequestDetail | null {
21
+ const target = pullRequestTarget(params);
22
+ const connected = usePullRequestConnected(target.environmentId);
23
+ const supported =
24
+ useEnvironmentServerConfig(target.environmentId)?.environment.capabilities.pullRequestChecks ===
25
+ true;
26
+ const checks = useEnvironmentQuery(
27
+ supported && detail !== null ? composerPullRequests.checks(target) : null,
28
+ );
29
+ // Both reads carry the server's observedAt; without it the poll is the fresher stream.
30
+ const live = resolvePullRequestDetailChecks(detail, checks.data, true);
31
+ // A failed read keeps polling; only a host that answers "no checks" (null) stops it.
32
+ const enabled =
33
+ connected && supported && live?.state === "open" && !(checks.isSuccess && checks.data === null);
34
+ const intervalMs = pullRequestChecksRefreshIntervalMs(live?.checks ?? []);
35
+ const { refresh } = checks;
36
+ useFocusEffect(() => {
37
+ if (!enabled) return;
38
+ const timer = setInterval(refresh, intervalMs);
39
+ return () => clearInterval(timer);
40
+ });
41
+ return live;
42
+}
apps/mobile/src/features/pull-requests/usePullRequestPermissions.ts
+17
-1
@@ -1,5 +1,9 @@
1
import { useAtomValue } from "@effect/atom-react";
2
-import type { PullRequestDetail } from "@t3tools/contracts";
2
+import {
3
+ canEditPullRequestChangeRequest,
4
+ canEditPullRequestComment,
5
+} from "@t3tools/client-runtime/pull-request-editing";
6
+import type { PullRequestComment, PullRequestDetail } from "@t3tools/contracts";
7
import { usePullRequestConnected } from "./usePullRequestConnected";
8
import { composerPullRequests } from "../../state/pull-requests";
9
import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff";
@@ -14,6 +18,13 @@ export function usePullRequestPermissions(params: PullRequestParams, pr: PullReq
18
const canResolve = useAtomValue(
19
composerPullRequests.setThreadResolution.permissionAtom(environmentId),
20
);
21
+ const canUpdate = useAtomValue(composerPullRequests.update.permissionAtom(environmentId));
22
+ const canUpdateComment = useAtomValue(
23
+ composerPullRequests.updateComment.permissionAtom(environmentId),
24
+ );
25
+ const canSetReaction = useAtomValue(
26
+ composerPullRequests.setReaction.permissionAtom(environmentId),
27
+ );
28
return {
29
connected,
30
canInlineComment:
@@ -36,6 +47,11 @@ export function usePullRequestPermissions(params: PullRequestParams, pr: PullReq
47
pr?.capabilities.review.resolve === true &&
48
pr.viewerPermissions.resolve,
49
canWrite: connected && canWrite,
50
+ canEditChangeRequest:
51
+ connected && canUpdate && pr !== null && canEditPullRequestChangeRequest(pr),
52
+ canEditComment: (comment: Pick<PullRequestComment, "author" | "canEdit" | "kind">) =>
53
+ connected && canUpdateComment && pr !== null && canEditPullRequestComment(pr, comment),
54
+ canReact: connected && canSetReaction && pr?.capabilities.reactions === true,
55
canComment:
56
connected && canComment && pr?.capabilities.comment === true && pr.viewerPermissions.comment,
57
verdicts:
apps/web/src/components/chat/ThreadDetailsPrRow.tsx
+1
-1
@@ -1,3 +1,4 @@
1
+import { resolvePullRequestDetailChecks } from "@t3tools/client-runtime/pull-request-checks";
2
import {
3
capitalizeTerm,
4
sourceControlClients,
@@ -35,7 +36,6 @@ import {
36
buildFixFindingsHandoff,
37
buildResolveConflictsPrompt,
38
classifyPullRequestChecks,
38
- resolvePullRequestDetailChecks,
39
describePullRequestChecks,
40
isPullRequestConflicting,
41
resolvePullRequestMergeMethod,
apps/web/src/components/pullRequest/PullRequestCodeTab.tsx
+4
-1
@@ -45,7 +45,10 @@ import { useClientSettings, updateClientSettings } from "~/hooks/useSettings";
45
import { useRenderedAppearance } from "~/hooks/useTheme";
46
import { areAllDiffFilesCollapsed } from "~/lib/diffCollapse";
47
import { pullRequestFindingKey, type PullRequestFinding } from "./pullRequestDetail.logic";
48
-import { canEditPullRequestComment, canResolvePullRequestThread } from "./pullRequestEditing.logic";
48
+import {
49
+ canEditPullRequestComment,
50
+ canResolvePullRequestThread,
51
+} from "@t3tools/client-runtime/pull-request-editing";
52
import { orderDiffFiles } from "./pullRequestFileOrder.logic";
53
import {
54
buildFileDiffRenderKey,
apps/web/src/components/pullRequest/PullRequestReactions.tsx
+3
-8
@@ -20,19 +20,14 @@ import {
20
pullRequestReactionEmoji,
21
pullRequestReactionName,
22
pullRequestReactionTooltip,
23
-} from "./pullRequestReactions.logic";
23
+ pullRequestReactionsSignature,
24
+} from "@t3tools/client-runtime/pull-request-reactions";
25
26
const PILL_CLASS =
27
"inline-flex h-6 shrink-0 items-center gap-1 rounded-full border px-2 text-xs outline-none transition-colors focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring";
28
29
const EMPTY_PENDING: ReadonlyMap<PullRequestReactionContent, boolean> = new Map();
30
30
-function reactionsSignature(reactions: ReadonlyArray<PullRequestReaction>): string {
31
- return reactions
32
- .map((reaction) => `${reaction.content}:${reaction.count}:${reaction.viewerHasReacted ? 1 : 0}`)
33
- .join(" ");
34
-}
35
-
31
export function PullRequestReactionBar({
32
reactions,
33
canReact,
@@ -60,7 +55,7 @@ export function PullRequestReactionBar({
55
reportFailure: false,
56
});
57
63
- const signature = reactionsSignature(reactions);
58
+ const signature = pullRequestReactionsSignature(reactions);
59
const values = pending.signature === signature ? pending.values : EMPTY_PENDING;
60
const shown = applyPendingPullRequestReactions(reactions, values);
61
apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx
+1
-1
@@ -72,7 +72,7 @@ import {
72
import {
73
canEditPullRequestChangeRequest,
74
canEditPullRequestComment,
75
-} from "./pullRequestEditing.logic";
75
+} from "@t3tools/client-runtime/pull-request-editing";
76
import { PullRequestMarkdown } from "./PullRequestMarkdown";
77
import { PullRequestCommentBody } from "./PullRequestCommentBody";
78
import { PullRequestMoreReplies } from "./PullRequestMoreReplies";
apps/web/src/components/pullRequest/PullRequestTimelineTab.tsx
+1
-1
@@ -41,7 +41,7 @@ import {
41
type PullRequestTimelineEvent,
42
type PullRequestTimelineThread,
43
} from "./pullRequestDetail.logic";
44
-import { canEditPullRequestComment } from "./pullRequestEditing.logic";
44
+import { canEditPullRequestComment } from "@t3tools/client-runtime/pull-request-editing";
45
import { PullRequestMarkdown } from "./PullRequestMarkdown";
46
import { PullRequestMoreReplies } from "./PullRequestMoreReplies";
47
import { PullRequestMarkdownEditor } from "./PullRequestMarkdownEditor";
apps/web/src/components/pullRequest/PullRequestTitleEditor.tsx
+1
-1
@@ -15,7 +15,7 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
15
import { PullRequestDetailTitleRow } from "./PullRequestDetailLayout";
16
import { PullRequestEditButton } from "./PullRequestEditButton";
17
import { readableFailure } from "./pullRequestDetail.logic";
18
-import { canEditPullRequestChangeRequest } from "./pullRequestEditing.logic";
18
+import { canEditPullRequestChangeRequest } from "@t3tools/client-runtime/pull-request-editing";
19
20
/** The pull request title, which the reader can rename in place when the host allows it. */
21
export function PullRequestTitleEditor({
apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts
-54
@@ -48,7 +48,6 @@ import {
48
checkoutFailureDescription,
49
readPullRequestDetailSnapshot,
50
resolveDisplayedPullRequestDetail,
51
- resolvePullRequestDetailChecks,
51
resolvePullRequestReferenceHost,
52
resolvePullRequestPrimaryControl,
53
allowsSinglePullRequestMerge,
@@ -1294,59 +1293,6 @@ describe("cached pull request detail", () => {
1293
...overrides,
1294
}) as PullRequestDetail;
1295
1297
- it("uses fresh checks for detail counts without replacing other PR fields", () => {
1298
- const pending = (name: string): PullRequestCheck => ({
1299
- name,
1300
- status: "pending",
1301
- url: null,
1302
- description: null,
1303
- });
1304
- const original = detail({ checks: [pending("build"), pending("test")] });
1305
- const checks = [pending("build"), { ...pending("test"), status: "success" as const }];
1306
- expect(resolvePullRequestDetailChecks(original, { state: "closed", checks }, true)).toEqual({
1307
- ...original,
1308
- state: "closed",
1309
- checks,
1310
- });
1311
- expect(resolvePullRequestDetailChecks(original, { state: "closed", checks }, false)).toBe(
1312
- original,
1313
- );
1314
- expect(resolvePullRequestDetailChecks(original, null, true)).toBe(original);
1315
- expect(resolvePullRequestDetailChecks(null, { state: "closed", checks }, true)).toBeNull();
1316
- });
1317
-
1318
- it("keeps newer checks when an older cached detail arrives later", () => {
1319
- const pending: PullRequestCheck = {
1320
- name: "build",
1321
- status: "pending",
1322
- url: null,
1323
- description: null,
1324
- };
1325
- const cached = detail({ observedAt: 1_000, checks: [pending] });
1326
- const checks = {
1327
- state: "open" as const,
1328
- checks: [{ ...pending, status: "success" as const }],
1329
- observedAt: 2_000,
1330
- };
1331
- const resolved = resolvePullRequestDetailChecks(cached, checks, false);
1332
- expect(resolved?.checks).toEqual(checks.checks);
1333
- expect(resolved?.observedAt).toBe(1_000);
1334
- expect(
1335
- resolvePullRequestDetailChecks(cached, { state: checks.state, checks: checks.checks }, true)
1336
- ?.checks,
1337
- ).toEqual(checks.checks);
1338
- const refreshed = detail({ observedAt: 3_000, checks: [pending] });
1339
- expect(resolvePullRequestDetailChecks(refreshed, checks, true)).toBe(refreshed);
1340
- });
1341
-
1342
- it("keeps merged details settled while applying newer checks", () => {
1343
- const merged = detail({ state: "merged", observedAt: 1_000 });
1344
- const checks = [{ name: "build", status: "success" as const, url: null, description: null }];
1345
- expect(
1346
- resolvePullRequestDetailChecks(merged, { state: "open", observedAt: 2_000, checks }, true),
1347
- ).toEqual({ ...merged, checks });
1348
- });
1349
-
1296
const makeStorage = () => {
1297
const held = new Map<string, string>();
1298
return {
apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
-19
@@ -1430,22 +1430,3 @@ export function resolveDisplayedPullRequestDetail(input: {
1430
? input.cached
1431
: null;
1432
}
1433
-
1434
-export function resolvePullRequestDetailChecks(
1435
- detail: PullRequestDetail | null,
1436
- checks: PullRequestChecks | null,
1437
- checksAreNewer: boolean,
1438
-): PullRequestDetail | null {
1439
- if (detail === null || checks === null) return detail;
1440
- const newer =
1441
- detail.observedAt !== undefined && checks.observedAt !== undefined
1442
- ? checks.observedAt >= detail.observedAt
1443
- : checksAreNewer;
1444
- return newer
1445
- ? {
1446
- ...detail,
1447
- state: detail.state === "merged" ? "merged" : checks.state,
1448
- checks: checks.checks,
1449
- }
1450
- : detail;
1451
-}
apps/web/src/components/pullRequest/usePullRequestDetail.ts
+1
-1
@@ -1,3 +1,4 @@
1
+import { resolvePullRequestDetailChecks } from "@t3tools/client-runtime/pull-request-checks";
2
import {
3
AuthSourceControlWriteScope,
4
type EnvironmentId,
@@ -20,7 +21,6 @@ import {
21
import {
22
readPullRequestDetailSnapshot,
23
resolveDisplayedPullRequestDetail,
23
- resolvePullRequestDetailChecks,
24
writePullRequestDetailSnapshot,
25
} from "./pullRequestDetail.logic";
26
import { pullRequestChecksState } from "./pullRequestPresentation";
apps/web/src/hooks/usePullRequestChecksRefresh.ts
+2
-5
@@ -1,3 +1,4 @@
1
+import { pullRequestChecksRefreshIntervalMs } from "@t3tools/client-runtime/pull-request-checks";
2
import type { PullRequestCheck } from "@t3tools/contracts";
3
4
import { useLiveRefresh } from "./useLiveRefresh";
@@ -11,10 +12,6 @@ export function usePullRequestChecksRefresh(input: {
12
useLiveRefresh(input.refresh, {
13
key: input.key,
14
enabled: input.enabled,
14
- intervalMs:
15
- input.checks.length === 0 ||
16
- input.checks.some((check) => check.status === "pending" || check.status === "action-required")
17
- ? 45_000
18
- : 60_000,
15
+ intervalMs: pullRequestChecksRefreshIntervalMs(input.checks),
16
});
17
}
packages/client-runtime/package.json
+12
@@ -447,6 +447,18 @@
447
"types": "./src/pullRequestMarkdown.ts",
448
"default": "./src/pullRequestMarkdown.ts"
449
},
450
+ "./pull-request-checks": {
451
+ "types": "./src/pullRequestChecks.ts",
452
+ "default": "./src/pullRequestChecks.ts"
453
+ },
454
+ "./pull-request-editing": {
455
+ "types": "./src/pullRequestEditing.ts",
456
+ "default": "./src/pullRequestEditing.ts"
457
+ },
458
+ "./pull-request-reactions": {
459
+ "types": "./src/pullRequestReactions.ts",
460
+ "default": "./src/pullRequestReactions.ts"
461
+ },
462
"./pull-request-query": {
463
"types": "./src/pullRequestQuery.ts",
464
"default": "./src/pullRequestQuery.ts"
packages/client-runtime/src/pullRequestChecks.test.ts
new
+62
@@ -0,0 +1,62 @@
1
+import type { PullRequestCheck, PullRequestDetail } from "@t3tools/contracts";
2
+import { describe, expect, it } from "vite-plus/test";
3
+
4
+import { resolvePullRequestDetailChecks } from "./pullRequestChecks.ts";
5
+
6
+const detail = (overrides: Partial<PullRequestDetail> = {}): PullRequestDetail =>
7
+ ({ title: "Cache the title", state: "open", checks: [], ...overrides }) as PullRequestDetail;
8
+
9
+describe("resolvePullRequestDetailChecks", () => {
10
+ it("uses fresh checks for detail counts without replacing other PR fields", () => {
11
+ const pending = (name: string): PullRequestCheck => ({
12
+ name,
13
+ status: "pending",
14
+ url: null,
15
+ description: null,
16
+ });
17
+ const original = detail({ checks: [pending("build"), pending("test")] });
18
+ const checks = [pending("build"), { ...pending("test"), status: "success" as const }];
19
+ expect(resolvePullRequestDetailChecks(original, { state: "closed", checks }, true)).toEqual({
20
+ ...original,
21
+ state: "closed",
22
+ checks,
23
+ });
24
+ expect(resolvePullRequestDetailChecks(original, { state: "closed", checks }, false)).toBe(
25
+ original,
26
+ );
27
+ expect(resolvePullRequestDetailChecks(original, null, true)).toBe(original);
28
+ expect(resolvePullRequestDetailChecks(null, { state: "closed", checks }, true)).toBeNull();
29
+ });
30
+
31
+ it("keeps newer checks when an older cached detail arrives later", () => {
32
+ const pending: PullRequestCheck = {
33
+ name: "build",
34
+ status: "pending",
35
+ url: null,
36
+ description: null,
37
+ };
38
+ const cached = detail({ observedAt: 1_000, checks: [pending] });
39
+ const checks = {
40
+ state: "open" as const,
41
+ checks: [{ ...pending, status: "success" as const }],
42
+ observedAt: 2_000,
43
+ };
44
+ const resolved = resolvePullRequestDetailChecks(cached, checks, false);
45
+ expect(resolved?.checks).toEqual(checks.checks);
46
+ expect(resolved?.observedAt).toBe(1_000);
47
+ expect(
48
+ resolvePullRequestDetailChecks(cached, { state: checks.state, checks: checks.checks }, true)
49
+ ?.checks,
50
+ ).toEqual(checks.checks);
51
+ const refreshed = detail({ observedAt: 3_000, checks: [pending] });
52
+ expect(resolvePullRequestDetailChecks(refreshed, checks, true)).toBe(refreshed);
53
+ });
54
+
55
+ it("keeps merged details settled while applying newer checks", () => {
56
+ const merged = detail({ state: "merged", observedAt: 1_000 });
57
+ const checks = [{ name: "build", status: "success" as const, url: null, description: null }];
58
+ expect(
59
+ resolvePullRequestDetailChecks(merged, { state: "open", observedAt: 2_000, checks }, true),
60
+ ).toEqual({ ...merged, checks });
61
+ });
62
+});
packages/client-runtime/src/pullRequestChecks.ts
new
+30
@@ -0,0 +1,30 @@
1
+import type { PullRequestCheck, PullRequestChecks, PullRequestDetail } from "@t3tools/contracts";
2
+
3
+export function resolvePullRequestDetailChecks(
4
+ detail: PullRequestDetail | null,
5
+ checks: PullRequestChecks | null,
6
+ checksAreNewer: boolean,
7
+): PullRequestDetail | null {
8
+ if (detail === null || checks === null) return detail;
9
+ const newer =
10
+ detail.observedAt !== undefined && checks.observedAt !== undefined
11
+ ? checks.observedAt >= detail.observedAt
12
+ : checksAreNewer;
13
+ return newer
14
+ ? {
15
+ ...detail,
16
+ state: detail.state === "merged" ? "merged" : checks.state,
17
+ checks: checks.checks,
18
+ }
19
+ : detail;
20
+}
21
+
22
+/** Checks still running are worth a tighter poll than a settled head. */
23
+export function pullRequestChecksRefreshIntervalMs(
24
+ checks: ReadonlyArray<PullRequestCheck>,
25
+): number {
26
+ return checks.length === 0 ||
27
+ checks.some((check) => check.status === "pending" || check.status === "action-required")
28
+ ? 45_000
29
+ : 60_000;
30
+}
packages/client-runtime/src/pullRequestEditing.test.ts
renamed
+1
-1
@@ -11,7 +11,7 @@ import {
11
canEditPullRequestChangeRequest,
12
canEditPullRequestComment,
13
canResolvePullRequestThread,
14
-} from "./pullRequestEditing.logic";
14
+} from "./pullRequestEditing.ts";
15
16
type Subject = Pick<PullRequestDetail, "author" | "capabilities" | "viewer" | "viewerPermissions">;
17
packages/client-runtime/src/pullRequestEditing.ts
renamed
packages/client-runtime/src/pullRequestReactions.test.ts
renamed
+1
-1
@@ -1,7 +1,7 @@
1
import type { PullRequestReaction, PullRequestReactionContent } from "@t3tools/contracts";
2
import { describe, expect, it } from "vite-plus/test";
3
4
-import { applyPendingPullRequestReactions } from "./pullRequestReactions.logic";
4
+import { applyPendingPullRequestReactions } from "./pullRequestReactions.ts";
5
6
function reaction(overrides: Partial<PullRequestReaction> = {}): PullRequestReaction {
7
return {
packages/client-runtime/src/pullRequestReactions.ts
renamed
+9
@@ -72,6 +72,15 @@ export function pullRequestReactionTooltip(reaction: PullRequestReaction): strin
72
return `${joinNames(parts)} reacted with ${pullRequestReactionName(reaction.content)} emoji`;
73
}
74
75
+/** Changes whenever the host reports different reactions, so pending overlays can reset. */
76
+export function pullRequestReactionsSignature(
77
+ reactions: ReadonlyArray<PullRequestReaction>,
78
+): string {
79
+ return reactions
80
+ .map((reaction) => `${reaction.content}:${reaction.count}:${reaction.viewerHasReacted ? 1 : 0}`)
81
+ .join(" ");
82
+}
83
+
84
export function applyPendingPullRequestReactions(
85
reactions: ReadonlyArray<PullRequestReaction>,
86
pending: ReadonlyMap<PullRequestReactionContent, boolean>,