@@ -4,15 +4,15 @@ import { useSharedValue, withSpring, withDelay } from "react-native-reanimated";
44import { useSafeAreaInsets } from "react-native-safe-area-context" ;
55
66import type { NativeStackScreenProps } from "@react-navigation/native-stack" ;
7- import type { NoteEntity } from "crossbell" ;
87import { Stack } from "tamagui" ;
98
109import { DelayedRender } from "@/components/DelayRender" ;
11- import { ImageGallery } from "@/components/ImageGallery" ;
1210import { usePostWebViewLink } from "@/hooks/use-post-link" ;
1311import { useScrollVisibilityHandler } from "@/hooks/use-scroll-visibility-handler" ;
1412import { useThemeStore } from "@/hooks/use-theme-store" ;
1513import type { RootStackParamList } from "@/navigation/types" ;
14+ import { useGetPage } from "@/queries/page" ;
15+ import { useGetSite } from "@/queries/site" ;
1616import type { ExpandedNote } from "@/types/crossbell" ;
1717import { GA } from "@/utils/GA" ;
1818
@@ -24,8 +24,10 @@ import { Header } from "./Header";
2424import { Navigator } from "./Navigator" ;
2525
2626export interface Props {
27- characterId : number
28- note : ExpandedNote
27+ characterId ?: number
28+ note ?: ExpandedNote
29+ slug ?: string
30+ handle ?: string
2931 coverImage ?: string
3032 placeholderCoverImageIndex ?: number
3133}
@@ -35,7 +37,16 @@ const animationTimeout = 300;
3537export const PostDetailsPage : FC < NativeStackScreenProps < RootStackParamList , "PostDetails" > > = ( props ) => {
3638 const { route } = props ;
3739 const { params } = route ;
38- const { note, characterId } = params ;
40+ const { slug, handle, coverImage, placeholderCoverImageIndex } = params ;
41+ const site = useGetSite ( handle ) ;
42+ const page = useGetPage ( site && {
43+ characterId : site . data ?. characterId ,
44+ slug,
45+ handle,
46+ } ) ;
47+
48+ const note = params . note || page . data ;
49+ const characterId = params . characterId || site . data ?. characterId ;
3950 const { isDarkMode } = useThemeStore ( ) ;
4051 const { bottom } = useSafeAreaInsets ( ) ;
4152 const bottomBarHeight = bottom + 45 ;
@@ -44,24 +55,28 @@ export const PostDetailsPage: FC<NativeStackScreenProps<RootStackParamList, "Pos
4455 const bottomSheetModalRef = React . useRef < BottomSheetModalInstance > ( null ) ;
4556 const followAnimValue = useSharedValue < number > ( 0 ) ;
4657 const scrollVisibilityHandler = useScrollVisibilityHandler ( { scrollThreshold : 30 } ) ;
47- const postUri = usePostWebViewLink ( { ...params , noteId : note . noteId } ) ;
58+ const postUri = usePostWebViewLink ( { ...params , characterId , noteId : note ? .noteId } ) ;
4859 const onTakeScreenshot = React . useCallback ( async ( ) : Promise < string > => contentRef . current . takeScreenshot ( ) , [ ] ) ;
4960
5061 useEffect ( ( ) => {
5162 followAnimValue . value = withDelay ( 1500 , withSpring ( 1 ) ) ;
5263 GA . logEvent ( "start_reading_post" , {
53- node_id : note . noteId ,
64+ node_id : note ? .noteId ,
5465 character_id : characterId ,
5566 } ) ;
5667 } , [ ] ) ;
5768
69+ if ( ! note || ! characterId ) {
70+ return null ;
71+ }
72+
5873 return (
5974 < Stack flex = { 1 } backgroundColor = { isDarkMode ? "black" : "white" } >
6075 < Navigator
6176 onTakeScreenshot = { onTakeScreenshot }
6277 isExpandedAnimValue = { scrollVisibilityHandler . isExpandedAnimValue }
63- characterId = { params . characterId }
64- note = { params . note }
78+ characterId = { characterId }
79+ note = { note }
6580 postUri = { postUri }
6681 headerContainerHeight = { headerContainerHeight }
6782 />
@@ -75,15 +90,15 @@ export const PostDetailsPage: FC<NativeStackScreenProps<RootStackParamList, "Pos
7590 isCapturing = { isCapturing }
7691 headerContainerHeight = { headerContainerHeight }
7792 postUri = { postUri }
78- note = { params . note }
79- characterId = { params . characterId }
80- placeholderCoverImageIndex = { params . placeholderCoverImageIndex }
81- coverImage = { params . coverImage }
93+ note = { note }
94+ characterId = { characterId }
95+ placeholderCoverImageIndex = { placeholderCoverImageIndex }
96+ coverImage = { coverImage }
8297 />
8398 ) ;
8499 } }
85- characterId = { params . characterId }
86- note = { params . note }
100+ characterId = { characterId }
101+ note = { note }
87102 scrollEventHandler = { scrollVisibilityHandler }
88103 bottomBarHeight = { bottomBarHeight }
89104 headerContainerHeight = { headerContainerHeight }
@@ -94,8 +109,8 @@ export const PostDetailsPage: FC<NativeStackScreenProps<RootStackParamList, "Pos
94109 < DelayedRender timeout = { animationTimeout } >
95110 < BottomSheetModal
96111 ref = { bottomSheetModalRef }
97- note = { params . note }
98- characterId = { params . characterId }
112+ note = { note }
113+ characterId = { characterId }
99114 bottomBarHeight = { bottomBarHeight }
100115 />
101116 </ DelayedRender >
0 commit comments