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" ;
310import Svg , { Defs , LinearGradient , Rect , Stop } from "react-native-svg" ;
4- import { Image } from "expo-image " ;
11+ import { pullRequestImageSource } from "./pullRequestMediaSource " ;
512import { parseMarkdownWithOptions } from "react-native-nitro-markdown/headless" ;
613import { nativeMarkdownWithHtml } from "@t3tools/mobile-markdown-text/markdown" ;
714import { SymbolView } from "../../components/AppSymbol" ;
815import { AppText as Text } from "../../components/AppText" ;
916import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider" ;
10- import { FilePreviewModal , type FilePreviewSource } from "../../components/FilePreviewModal" ;
17+ import type { FilePreviewItem } from "../../components/FilePreviewModal" ;
1118import { PullRequestMarkdown } from "./PullRequestMarkdown" ;
1219import { 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}
0 commit comments