Skip to content

Commit

Permalink
Profile cleanup (react-query refactor) (#1891)
Browse files Browse the repository at this point in the history
* Only fetch profile tab content when focused

* Fix keys

* Add missing behaviors to post tabs

* Delete old profile mobx model
  • Loading branch information
pfrazee authored Nov 13, 2023
1 parent 47204d9 commit 0501c2b
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 327 deletions.
306 changes: 0 additions & 306 deletions src/state/models/content/profile.ts

This file was deleted.

7 changes: 6 additions & 1 deletion src/state/queries/profile-feedgens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ type RQPageParam = string | undefined

export const RQKEY = (did: string) => ['profile-feedgens', did]

export function useProfileFeedgensQuery(did: string) {
export function useProfileFeedgensQuery(
did: string,
opts?: {enabled?: boolean},
) {
const {agent} = useSession()
const enabled = opts?.enabled !== false
return useInfiniteQuery<
AppBskyFeedGetActorFeeds.OutputSchema,
Error,
Expand All @@ -27,5 +31,6 @@ export function useProfileFeedgensQuery(did: string) {
},
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
enabled,
})
}
4 changes: 3 additions & 1 deletion src/state/queries/profile-lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ type RQPageParam = string | undefined

export const RQKEY = (did: string) => ['profile-lists', did]

export function useProfileListsQuery(did: string) {
export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
const {agent} = useSession()
const enabled = opts?.enabled !== false
return useInfiniteQuery<
AppBskyGraphGetLists.OutputSchema,
Error,
Expand All @@ -27,5 +28,6 @@ export function useProfileListsQuery(did: string) {
},
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
enabled,
})
}
7 changes: 5 additions & 2 deletions src/view/com/feeds/ProfileFeedgens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function ProfileFeedgens({
onScroll,
scrollEventThrottle,
headerOffset,
enabled,
style,
testID,
}: {
Expand All @@ -43,12 +44,14 @@ export function ProfileFeedgens({
onScroll?: OnScrollHandler
scrollEventThrottle?: number
headerOffset: number
enabled?: boolean
style?: StyleProp<ViewStyle>
testID?: string
}) {
const pal = usePalette('default')
const theme = useTheme()
const [isPTRing, setIsPTRing] = React.useState(false)
const opts = React.useMemo(() => ({enabled}), [enabled])
const {
data,
isFetching,
Expand All @@ -58,7 +61,7 @@ export function ProfileFeedgens({
isError,
error,
refetch,
} = useProfileFeedgensQuery(did)
} = useProfileFeedgensQuery(did, opts)
const isEmpty = !isFetching && !data?.pages[0]?.feeds.length
const {data: preferences} = usePreferencesQuery()

Expand Down Expand Up @@ -163,7 +166,7 @@ export function ProfileFeedgens({
testID={testID ? `${testID}-flatlist` : undefined}
ref={scrollElRef}
data={items}
keyExtractor={(item: any) => item._reactKey}
keyExtractor={(item: any) => item._reactKey || item.uri}
renderItem={renderItemInner}
refreshControl={
<RefreshControl
Expand Down
Loading

0 comments on commit 0501c2b

Please sign in to comment.