Skip to content

Commit

Permalink
Add missing behaviors to post tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
pfrazee committed Nov 13, 2023
1 parent c55a34f commit d6c31b6
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/view/screens/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ import {useProfileShadow} from '#/state/cache/profile-shadow'
import {useSession} from '#/state/session'
import {useModerationOpts} from '#/state/queries/preferences'
import {useProfileExtraInfoQuery} from '#/state/queries/profile-extra-info'
import {RQKEY as FEED_RQKEY} from '#/state/queries/post-feed'
import {useSetDrawerSwipeDisabled, useSetMinimalShellMode} from '#/state/shell'
import {cleanError} from '#/lib/strings/errors'
import {LoadLatestBtn} from '../com/util/load-latest/LoadLatestBtn'
import {useQueryClient} from '@tanstack/react-query'

type Props = NativeStackScreenProps<CommonNavigatorParams, 'Profile'>
export const ProfileScreen = withAuthRequired(function ProfileScreenImpl({
Expand Down Expand Up @@ -323,22 +326,17 @@ interface FeedSectionProps {
}
const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>(
function FeedSectionImpl(
{
feed,
onScroll,
headerHeight,
isFocused,
// isScrolledDown,
scrollElRef,
},
{feed, onScroll, headerHeight, isFocused, isScrolledDown, scrollElRef},
ref,
) {
// const hasNew = false //TODO feed.hasNewLatest && !feed.isRefreshing
const queryClient = useQueryClient()
const [hasNew, setHasNew] = React.useState(false)

const onScrollToTop = React.useCallback(() => {
scrollElRef.current?.scrollToOffset({offset: -headerHeight})
// feed.refresh() TODO
}, [scrollElRef, headerHeight])
queryClient.invalidateQueries({queryKey: FEED_RQKEY(feed)})
setHasNew(false)
}, [scrollElRef, headerHeight, queryClient, feed, setHasNew])
React.useImperativeHandle(ref, () => ({
scrollToTop: onScrollToTop,
}))
Expand All @@ -353,12 +351,20 @@ const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>(
testID="postsFeed"
feed={feed}
scrollElRef={scrollElRef}
onHasNew={setHasNew}
onScroll={onScroll}
scrollEventThrottle={1}
renderEmptyState={renderPostsEmpty}
headerOffset={headerHeight}
enabled={isFocused}
/>
{(isScrolledDown || hasNew) && (
<LoadLatestBtn
onPress={onScrollToTop}
label="Load new posts"
showIndicator={hasNew}
/>
)}
</View>
)
},
Expand Down

0 comments on commit d6c31b6

Please sign in to comment.