mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React, {useCallback} from 'react'
2import {View} from 'react-native'
3import {msg} from '@lingui/macro'
4import {useLingui} from '@lingui/react'
5
6import {isNative} from '#/platform/detection'
7import {FeedDescriptor} from '#/state/queries/post-feed'
8import {PostFeed} from '#/view/com/posts/PostFeed'
9import {EmptyState} from '#/view/com/util/EmptyState'
10import {ListRef} from '#/view/com/util/List'
11import {SectionRef} from '#/screens/Profile/Sections/types'
12
13interface ProfilesListProps {
14 listUri: string
15 headerHeight: number
16 scrollElRef: ListRef
17}
18
19export const PostsList = React.forwardRef<SectionRef, ProfilesListProps>(
20 function PostsListImpl({listUri, headerHeight, scrollElRef}, ref) {
21 const feed: FeedDescriptor = `list|${listUri}`
22 const {_} = useLingui()
23
24 const onScrollToTop = useCallback(() => {
25 scrollElRef.current?.scrollToOffset({
26 animated: isNative,
27 offset: -headerHeight,
28 })
29 }, [scrollElRef, headerHeight])
30
31 React.useImperativeHandle(ref, () => ({
32 scrollToTop: onScrollToTop,
33 }))
34
35 const renderPostsEmpty = useCallback(() => {
36 return <EmptyState icon="hashtag" message={_(msg`This feed is empty.`)} />
37 }, [_])
38
39 return (
40 <View>
41 <PostFeed
42 feed={feed}
43 pollInterval={60e3}
44 scrollElRef={scrollElRef}
45 renderEmptyState={renderPostsEmpty}
46 headerOffset={headerHeight}
47 />
48 </View>
49 )
50 },
51)