mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {StyleSheet, View} from 'react-native'
3import Animated from 'react-native-reanimated'
4import {useSafeAreaInsets} from 'react-native-safe-area-context'
5import {useFocusEffect} from '@react-navigation/native'
6import {useQueryClient} from '@tanstack/react-query'
7import {clamp} from 'lodash'
8
9import {isWeb} from '#/platform/detection'
10import {
11 RQKEY as POST_THREAD_RQKEY,
12 ThreadNode,
13} from '#/state/queries/post-thread'
14import {useSession} from '#/state/session'
15import {useSetMinimalShellMode} from '#/state/shell'
16import {useComposerControls} from '#/state/shell/composer'
17import {useMinimalShellMode} from 'lib/hooks/useMinimalShellMode'
18import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
19import {CommonNavigatorParams, NativeStackScreenProps} from 'lib/routes/types'
20import {makeRecordUri} from 'lib/strings/url-helpers'
21import {s} from 'lib/styles'
22import {ComposePrompt} from 'view/com/composer/Prompt'
23import {PostThread as PostThreadComponent} from '../com/post-thread/PostThread'
24
25type Props = NativeStackScreenProps<CommonNavigatorParams, 'PostThread'>
26export function PostThreadScreen({route}: Props) {
27 const queryClient = useQueryClient()
28 const {hasSession} = useSession()
29 const {fabMinimalShellTransform} = useMinimalShellMode()
30 const setMinimalShellMode = useSetMinimalShellMode()
31 const {openComposer} = useComposerControls()
32 const safeAreaInsets = useSafeAreaInsets()
33 const {name, rkey} = route.params
34 const {isMobile} = useWebMediaQueries()
35 const uri = makeRecordUri(name, 'app.bsky.feed.post', rkey)
36 const [canReply, setCanReply] = React.useState(false)
37
38 useFocusEffect(
39 React.useCallback(() => {
40 setMinimalShellMode(false)
41 }, [setMinimalShellMode]),
42 )
43
44 const onPressReply = React.useCallback(() => {
45 if (!uri) {
46 return
47 }
48 const thread = queryClient.getQueryData<ThreadNode>(POST_THREAD_RQKEY(uri))
49 if (thread?.type !== 'post') {
50 return
51 }
52 openComposer({
53 replyTo: {
54 uri: thread.post.uri,
55 cid: thread.post.cid,
56 text: thread.record.text,
57 author: thread.post.author,
58 embed: thread.post.embed,
59 },
60 onPost: () =>
61 queryClient.invalidateQueries({
62 queryKey: POST_THREAD_RQKEY(uri),
63 }),
64 })
65 }, [openComposer, queryClient, uri])
66
67 return (
68 <View style={s.hContentRegion}>
69 <View style={s.flex1}>
70 <PostThreadComponent
71 uri={uri}
72 onPressReply={onPressReply}
73 onCanReply={setCanReply}
74 />
75 </View>
76 {isMobile && canReply && hasSession && (
77 <Animated.View
78 style={[
79 styles.prompt,
80 fabMinimalShellTransform,
81 {
82 bottom: clamp(safeAreaInsets.bottom, 15, 30),
83 },
84 ]}>
85 <ComposePrompt onPressCompose={onPressReply} />
86 </Animated.View>
87 )}
88 </View>
89 )
90}
91
92const styles = StyleSheet.create({
93 prompt: {
94 // @ts-ignore web-only
95 position: isWeb ? 'fixed' : 'absolute',
96 left: 0,
97 right: 0,
98 },
99})