Skip to content

Commit d07a07f

Browse files
feat(mobile): keep pull requests available offline (pingdotgg#18351)
1 parent 5cbe82a commit d07a07f

47 files changed

Lines changed: 1566 additions & 419 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { EnvironmentQueryStore } from "@t3tools/client-runtime/state/query-persistence";
2+
import * as Effect from "effect/Effect";
3+
import * as Layer from "effect/Layer";
4+
5+
import { MobileDatabase } from "../persistence/mobile-database";
6+
7+
export const layer = Layer.effect(
8+
EnvironmentQueryStore,
9+
Effect.gen(function* () {
10+
const database = yield* MobileDatabase;
11+
return {
12+
load: (environmentId, key) =>
13+
database
14+
.loadCache(environmentId, "pull-request", `v1:${key}`)
15+
.pipe(Effect.catch(() => Effect.succeedNone)),
16+
save: (environmentId, key, payload) =>
17+
database
18+
.saveCache(environmentId, "pull-request", `v1:${key}`, 1, payload)
19+
.pipe(Effect.catch(() => Effect.logWarning("Offline query database save failed"))),
20+
} satisfies NonNullable<typeof EnvironmentQueryStore.Service>;
21+
}),
22+
);

‎apps/mobile/src/features/pull-requests/PullRequestControls.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ export function PullRequestActionToolbar(props: {
123123
const agent = usePullRequestAgentActions(props.params, props.pr, props.filePath);
124124
const canReview = permissions.verdicts.length > 0;
125125
const pendingReview = canReview && draft.comments.length > 0;
126-
const canOpenThread = agent.threads.length > 0 || agent.canAsk;
126+
const showAgentControls = agent.canAsk || !permissions.connected;
127+
const canOpenThread = agent.threads.length > 0 || showAgentControls;
127128
const threadLabel = agent.threads.length ? "Continue thread" : "Work on PR";
128129
const primaryLabel = pendingReview ? `Submit review · ${draft.comments.length}` : threadLabel;
129130
const chooseThread = agent.threads.length > 1;
@@ -142,7 +143,7 @@ export function PullRequestActionToolbar(props: {
142143
// Reserve the native outer margins, custom-button padding, and item gaps.
143144
// UIKit needs this space to keep every action out of its overflow menu.
144145
// Duo's side rail uses an intrinsic icon item instead.
145-
const sideControls = Number(agent.canAsk) + 1;
146+
const sideControls = Number(showAgentControls) + 1;
146147
const primaryWidth = verticalControls
147148
? undefined
148149
: Math.max(
@@ -166,7 +167,7 @@ export function PullRequestActionToolbar(props: {
166167
className="flex-row items-center justify-between gap-3 border-t border-border-subtle bg-screen px-4 pt-2"
167168
style={{ paddingBottom: Math.max(insets.bottom, 8) }}
168169
>
169-
{agent.canAsk ? (
170+
{showAgentControls ? (
170171
<ControlPillMenu
171172
title="AI helpers"
172173
actions={agentActions.map((action) => agent.menuAction(action.task))}
@@ -259,7 +260,7 @@ export function PullRequestActionToolbar(props: {
259260
/>
260261
)
261262
) : null;
262-
const agentControl = agent.canAsk ? (
263+
const agentControl = showAgentControls ? (
263264
<NativeHeaderToolbar.Menu
264265
identifier="pull-request-agent"
265266
width={controlSize}

‎apps/mobile/src/features/pull-requests/PullRequestDescription.tsx‎

Lines changed: 50 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
import { useMemo, useState } from "react";
2-
import { ActivityIndicator, Pressable, ScrollView, StyleSheet, View } from "react-native";
1+
import { splitPullRequestBody } from "@t3tools/client-runtime/pull-request-markdown";
2+
import {
3+
PullRequestImageAttachment,
4+
PullRequestMedia,
5+
PullRequestMediaContext,
6+
} from "./PullRequestMedia";
7+
import { PullRequestSectionHeading } from "./PullRequestSectionHeading";
8+
import { useContext, useMemo, useState } from "react";
9+
import { Pressable, ScrollView, StyleSheet, View } from "react-native";
310
import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg";
4-
import { Image } from "expo-image";
11+
import { pullRequestImageSource } from "./pullRequestMediaSource";
512
import { parseMarkdownWithOptions } from "react-native-nitro-markdown/headless";
613
import { nativeMarkdownWithHtml } from "@t3tools/mobile-markdown-text/markdown";
714
import { SymbolView } from "../../components/AppSymbol";
815
import { AppText as Text } from "../../components/AppText";
916
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
10-
import { FilePreviewModal, type FilePreviewSource } from "../../components/FilePreviewModal";
17+
import type { FilePreviewItem } from "../../components/FilePreviewModal";
1118
import { PullRequestMarkdown } from "./PullRequestMarkdown";
1219
import { pullRequestDescriptionContent } from "./pullRequestDescriptionContent";
1320

@@ -21,31 +28,33 @@ export function PullRequestDescription(props: {
2128
}) {
2229
const { expanded, onExpandedChange } = props;
2330
const [bodyHeight, setBodyHeight] = useState(0);
24-
const [preview, setPreview] = useState<FilePreviewSource | null>(null);
25-
const openingUri = preview && "uri" in preview ? preview.uri : null;
31+
const mediaContext = useContext(PullRequestMediaContext);
2632
const { themeVariables: colors } = useAppearancePreferences();
2733
const content = useMemo(() => {
2834
const document = nativeMarkdownWithHtml(
2935
parseMarkdownWithOptions(props.markdown, { gfm: true, html: true, math: false }),
3036
(markdown) => parseMarkdownWithOptions(markdown, { gfm: true, html: false, math: false }),
3137
);
32-
return pullRequestDescriptionContent(document);
38+
return pullRequestDescriptionContent(document, splitPullRequestBody(props.markdown));
3339
}, [props.markdown]);
34-
const gallery = useMemo(
40+
const gallery = useMemo<FilePreviewItem[]>(
3541
() =>
36-
content.attachments.map((attachment) => ({
37-
kind: "image" as const,
38-
uri: attachment.uri,
39-
name: new URL(attachment.uri).pathname.split("/").pop() || "Image",
40-
})),
41-
[content],
42+
content.attachments
43+
.filter((attachment) => attachment.kind === "image")
44+
.map((attachment) => {
45+
return {
46+
...pullRequestImageSource(attachment.uri, mediaContext),
47+
name: new URL(attachment.uri).pathname.split("/").pop() || "Image",
48+
};
49+
}),
50+
[content, mediaContext],
4251
);
4352
const canCollapse = bodyHeight > COLLAPSED_HEIGHT;
4453
const collapsed = canCollapse && !expanded;
4554
return (
4655
<View className="gap-5">
4756
<View className="gap-3">
48-
<Text className="text-base font-t3-semibold">Description</Text>
57+
<PullRequestSectionHeading>Description</PullRequestSectionHeading>
4958
{props.markdown.trim() ? (
5059
<View className="overflow-hidden">
5160
<View
@@ -130,58 +139,42 @@ export function PullRequestDescription(props: {
130139
</View>
131140
{content.attachments.length ? (
132141
<View className="gap-3">
133-
<Text className="text-base font-t3-semibold">Attachments</Text>
142+
<PullRequestSectionHeading>Attachments</PullRequestSectionHeading>
134143
<ScrollView
135144
horizontal
136145
keyboardShouldPersistTaps="always"
137146
scrollsToTop={false}
138147
showsHorizontalScrollIndicator={false}
139148
contentContainerStyle={{ gap: 12 }}
140149
>
141-
{content.attachments.map((attachment) => (
142-
<Pressable
143-
key={attachment.uri}
144-
accessibilityRole="imagebutton"
145-
accessibilityLabel={`View attachment: ${attachment.caption}`}
146-
accessibilityState={{ busy: openingUri === attachment.uri }}
147-
disabled={preview !== null}
148-
onPress={() =>
149-
setPreview({
150-
kind: "image",
151-
uri: attachment.uri,
152-
name: gallery.find((item) => item.uri === attachment.uri)?.name ?? "Image",
153-
gallery,
154-
})
155-
}
156-
className="gap-2 active:opacity-70"
157-
style={{ width: 176 }}
158-
>
159-
<View className="overflow-hidden rounded-2xl border border-border-subtle bg-grouped-card">
160-
<Image
161-
source={{ uri: attachment.uri }}
162-
style={{ width: 174, height: 112 }}
163-
contentFit="contain"
164-
cachePolicy="memory-disk"
165-
/>
166-
{openingUri === attachment.uri ? (
167-
<View
168-
pointerEvents="none"
169-
style={StyleSheet.absoluteFill}
170-
className="items-center justify-center bg-black/30"
171-
>
172-
<ActivityIndicator color="white" />
173-
</View>
174-
) : null}
175-
</View>
176-
<Text numberOfLines={1} className="text-xs text-foreground-muted">
177-
{attachment.caption}
178-
</Text>
179-
</Pressable>
180-
))}
150+
{content.attachments.map((attachment) =>
151+
attachment.kind !== "image" ? (
152+
<PullRequestMedia
153+
key={attachment.uri}
154+
url={attachment.uri}
155+
kind={attachment.kind}
156+
caption={attachment.caption}
157+
compact
158+
/>
159+
) : (
160+
<PullRequestImageAttachment
161+
key={attachment.uri}
162+
url={attachment.uri}
163+
caption={attachment.caption}
164+
source={
165+
gallery[
166+
content.attachments
167+
.filter((item) => item.kind === "image")
168+
.indexOf(attachment)
169+
]!
170+
}
171+
gallery={gallery}
172+
/>
173+
),
174+
)}
181175
</ScrollView>
182176
</View>
183177
) : null}
184-
<FilePreviewModal source={preview} onRequestClose={() => setPreview(null)} />
185178
</View>
186179
);
187180
}

‎apps/mobile/src/features/pull-requests/PullRequestDiscussionScreen.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
118118
const resolveLabel = thread?.isResolved ? "Unresolve" : "Resolve";
119119
return (
120120
<PullRequestMarkdownRepository
121+
params={params}
121122
value={detail.data?.provider === "github" ? detail.data.url : null}
122123
>
123124
<KeyboardAvoidingView automaticOffset behavior="height" className="flex-1 bg-screen">

‎apps/mobile/src/features/pull-requests/PullRequestFiles.tsx‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PullRequestSectionHeading } from "./PullRequestSectionHeading";
12
import { AnimatedLegendList } from "@legendapp/list/reanimated";
23
import Animated from "react-native-reanimated";
34
import { PR_ROW_LAYOUT, PR_ROW_ENTER, PR_ROW_EXIT } from "./pullRequestAnimations";
@@ -167,15 +168,15 @@ export function usePullRequestFilesContent(props: {
167168
accessibilityState={{ busy: true }}
168169
className="min-h-17 flex-row items-center gap-2 py-3"
169170
>
170-
<View className="min-w-0 flex-1 gap-2">
171-
<Text className="text-base font-t3-semibold">
172-
{fileCount === undefined
173-
? "Changed files"
174-
: `${fileCount} changed ${fileCount === 1 ? "file" : "files"}`}
175-
</Text>
176-
{filter.hideTestFiles ? (
171+
<View className="min-w-0 flex-1 gap-1">
172+
<PullRequestSectionHeading>Changed files</PullRequestSectionHeading>
173+
{fileCount !== undefined ? (
174+
<Text className="text-2xs text-foreground-muted">
175+
{fileCount} {fileCount === 1 ? "file" : "files"}
176+
</Text>
177+
) : (
177178
<View className="h-2.5 w-28 rounded bg-subtle-strong" />
178-
) : null}
179+
)}
179180
</View>
180181
{summary?.additions !== undefined && summary.deletions !== undefined ? (
181182
<PullRequestDiffStats
@@ -196,14 +197,14 @@ export function usePullRequestFilesContent(props: {
196197
<>
197198
<View className="min-h-17 flex-row items-center gap-2 py-3">
198199
<View className="min-w-0 flex-1 gap-1">
199-
<Text className="text-base font-t3-semibold">
200+
<PullRequestSectionHeading>Changed files</PullRequestSectionHeading>
201+
<Text className="text-2xs text-foreground-muted">
200202
{parsed.fileCount} {filter.hiddenCount ? "visible" : "changed"}{" "}
201203
{parsed.fileCount === 1 ? "file" : "files"}
202204
{viewed.supported
203205
? ` · ${parsed.files.filter((file) => viewed.isViewed(file.path)).length} viewed`
204206
: ""}
205-
</Text>
206-
<Text className="text-2xs text-foreground-muted">
207+
{" · "}
207208
{filter.hideTestFiles
208209
? `${filter.hiddenCount} test ${filter.hiddenCount === 1 ? "file" : "files"} hidden`
209210
: "Test files included"}

0 commit comments

Comments
 (0)