import { useMemo, useState } from "react"; import { FlatList, View } from "react-native"; import { useReplies, useCommentSection } from "@replyke/core"; import { useSocialStyleConfig } from "@replyke/comments-social-core"; import { CommentSkeleton } from "@replyke/ui-core-react-native"; import Comment from "../Comment"; import ShowHideButton from "./ShowHideButton"; function Replies({ commentId }: { commentId: string }) { const { sortBy, entityCommentsTree, highlightedComment } = useCommentSection(); const { styleConfig } = useSocialStyleConfig(); const { replies, newReplies, page, setPage, loading } = useReplies({ commentId, sortBy: sortBy!, }); const [areRepliesVisible, setAreRepliesVisible] = useState(false); const { repliesGap, repliesPaddingTop } = styleConfig!.commentProps; const comment = entityCommentsTree![commentId]?.comment; const filteredReplies = useMemo(() => { return replies.filter((c) => c.id !== highlightedComment?.comment.id); }, [replies, highlightedComment]); const newRepliesList = ( ( )} keyExtractor={(item) => item.id} ItemSeparatorComponent={() => } keyboardShouldPersistTaps="always" /> ); const oldRepliesList = ( ( )} keyExtractor={(item) => item.id} ItemSeparatorComponent={() => } keyboardShouldPersistTaps="always" /> ); const someRepliesShow = newReplies.length > 0 || highlightedComment?.parentComment?.id === commentId || (areRepliesVisible && filteredReplies.length > 0) || loading; if ((!comment || comment.repliesCount === 0) && newReplies.length === 0) return null; return ( {someRepliesShow && ( {/* New replies should always show */} {newRepliesList} {/* Highlighted reply */} {highlightedComment && highlightedComment.parentComment?.id === commentId && ( )} {/* Old replies should only show if it is set to show */} {areRepliesVisible && oldRepliesList} )} {/* If replies are fetched we show the skeleton */} {loading && ( index + 1 )} renderItem={() => } keyExtractor={(item) => String(item)} ItemSeparatorComponent={() => } style={{ paddingLeft: 42, paddingRight: 16 }} keyboardShouldPersistTaps="always" /> )} ); } export default Replies;