-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
156 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/components/Comment/components/CommentShowMoreButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { useCallback } from 'react'; | ||
import { ICommentInfo } from '@src/types'; | ||
import VStack from '@components/Common/Stack/VStack'; | ||
import { Separator, Text } from 'tamagui'; | ||
import { NativeStackNavigationProp } from '@react-navigation/native-stack'; | ||
import { useNavigation } from '@react-navigation/core'; | ||
import { Pressable } from 'react-native'; | ||
|
||
interface IProps { | ||
commentInfo: ICommentInfo; | ||
} | ||
|
||
function CommentShowMoreButton({ commentInfo }: IProps): React.JSX.Element { | ||
const navigation = useNavigation<NativeStackNavigationProp<any>>(); | ||
|
||
const onPress = useCallback(() => { | ||
navigation.navigate('CommentChain', { | ||
commentInfo, | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<Pressable onPress={onPress}> | ||
<VStack backgroundColor="$fg"> | ||
<VStack | ||
marginLeft={commentInfo.depth * 10} | ||
marginVertical="$2" | ||
borderLeftColor="$secondary" | ||
borderLeftWidth={2} | ||
paddingHorizontal="$2" | ||
paddingVertical="$1" | ||
> | ||
<Text | ||
color="$secondary" | ||
fontStyle="italic" | ||
marginBottom="$1" | ||
margin="auto" | ||
> | ||
Show More Comments... | ||
</Text> | ||
</VStack> | ||
<Separator borderColor="$bg" marginLeft={commentInfo.depth * 10 + 10} /> | ||
</VStack> | ||
</Pressable> | ||
); | ||
} | ||
|
||
export default React.memo(CommentShowMoreButton); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useCallback, useMemo } from 'react'; | ||
import { NativeStackNavigationProp } from '@react-navigation/native-stack'; | ||
import VStack from '@components/Common/Stack/VStack'; | ||
import { ICommentInfo } from '@src/types'; | ||
import { usePostCommentsInfo } from '@src/state/post/postStore'; | ||
import { FlatList, ListRenderItemInfo } from 'react-native'; | ||
import CommentChain from '@components/Comment/components/CommentChain'; | ||
|
||
interface IProps { | ||
navigation: NativeStackNavigationProp<any>; | ||
route: any; | ||
} | ||
|
||
const keyExtractor = (item: ICommentInfo): string => item.commentId.toString(); | ||
|
||
export default function CommentChainScreen({ | ||
navigation, | ||
route, | ||
}: IProps): React.JSX.Element { | ||
const params = route.params; | ||
const commentInfo = params.commentInfo as ICommentInfo; | ||
|
||
const commentsInfo = usePostCommentsInfo(commentInfo.postId); | ||
|
||
const commentsToShow = useMemo( | ||
() => | ||
commentsInfo?.filter((item) => | ||
item.path.includes(commentInfo.parentId!.toString()), | ||
), | ||
[], | ||
); | ||
|
||
const renderItem = useCallback( | ||
({ item }: ListRenderItemInfo<ICommentInfo>): React.JSX.Element => { | ||
return <CommentChain commentInfo={item} ignoreLoadMore />; | ||
}, | ||
[], | ||
); | ||
|
||
return ( | ||
<VStack flex={1} backgroundColor="$bg"> | ||
<FlatList | ||
renderItem={renderItem} | ||
data={commentsToShow} | ||
keyExtractor={keyExtractor} | ||
initialNumToRender={10} | ||
maxToRenderPerBatch={5} | ||
updateCellsBatchingPeriod={300} | ||
windowSize={10} | ||
removeClippedSubviews={true} | ||
/> | ||
</VStack> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
export interface ICommentInfo { | ||
postId: number; | ||
commentId: number; | ||
replies: ICommentInfo[]; | ||
replies: ICommentInfo[] | undefined; | ||
depth: number; | ||
hidden: boolean; | ||
collapsed: boolean; | ||
path: string; | ||
topId: number; | ||
parentId?: number; | ||
|
||
showInPost: boolean; | ||
showLoadMore: boolean; | ||
} |