From d6c31b6ecba9512dac05978a2bd6a874e66952ae Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Mon, 13 Nov 2023 14:56:53 -0800 Subject: [PATCH] Add missing behaviors to post tabs --- src/view/screens/Profile.tsx | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/view/screens/Profile.tsx b/src/view/screens/Profile.tsx index fe8ec98ef0..1a2982027e 100644 --- a/src/view/screens/Profile.tsx +++ b/src/view/screens/Profile.tsx @@ -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 export const ProfileScreen = withAuthRequired(function ProfileScreenImpl({ @@ -323,22 +326,17 @@ interface FeedSectionProps { } const FeedSection = React.forwardRef( 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, })) @@ -353,12 +351,20 @@ const FeedSection = React.forwardRef( testID="postsFeed" feed={feed} scrollElRef={scrollElRef} + onHasNew={setHasNew} onScroll={onScroll} scrollEventThrottle={1} renderEmptyState={renderPostsEmpty} headerOffset={headerHeight} enabled={isFocused} /> + {(isScrolledDown || hasNew) && ( + + )} ) },