Fix profile lists/feeds/starterpacks tabs position issue (#8935)
This commit is contained in:
@@ -1,13 +1,9 @@
|
|||||||
import React, {
|
import {useCallback, useEffect, useImperativeHandle, useState} from 'react'
|
||||||
useCallback,
|
|
||||||
useEffect,
|
|
||||||
useImperativeHandle,
|
|
||||||
useState,
|
|
||||||
} from 'react'
|
|
||||||
import {
|
import {
|
||||||
findNodeHandle,
|
findNodeHandle,
|
||||||
type ListRenderItemInfo,
|
type ListRenderItemInfo,
|
||||||
type StyleProp,
|
type StyleProp,
|
||||||
|
useWindowDimensions,
|
||||||
View,
|
View,
|
||||||
type ViewStyle,
|
type ViewStyle,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
@@ -42,6 +38,7 @@ interface SectionRef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ProfileFeedgensProps {
|
interface ProfileFeedgensProps {
|
||||||
|
ref?: React.Ref<SectionRef>
|
||||||
scrollElRef: ListRef
|
scrollElRef: ListRef
|
||||||
did: string
|
did: string
|
||||||
headerOffset: number
|
headerOffset: number
|
||||||
@@ -56,24 +53,20 @@ function keyExtractor(item: AppBskyGraphDefs.StarterPackView) {
|
|||||||
return item.uri
|
return item.uri
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ProfileStarterPacks = React.forwardRef<
|
export function ProfileStarterPacks({
|
||||||
SectionRef,
|
|
||||||
ProfileFeedgensProps
|
|
||||||
>(function ProfileFeedgensImpl(
|
|
||||||
{
|
|
||||||
scrollElRef,
|
|
||||||
did,
|
|
||||||
headerOffset,
|
|
||||||
enabled,
|
|
||||||
style,
|
|
||||||
testID,
|
|
||||||
setScrollViewTag,
|
|
||||||
isMe,
|
|
||||||
},
|
|
||||||
ref,
|
ref,
|
||||||
) {
|
scrollElRef,
|
||||||
|
did,
|
||||||
|
headerOffset,
|
||||||
|
enabled,
|
||||||
|
style,
|
||||||
|
testID,
|
||||||
|
setScrollViewTag,
|
||||||
|
isMe,
|
||||||
|
}: ProfileFeedgensProps) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const bottomBarOffset = useBottomBarOffset(100)
|
const bottomBarOffset = useBottomBarOffset(100)
|
||||||
|
const {height} = useWindowDimensions()
|
||||||
const [isPTRing, setIsPTRing] = useState(false)
|
const [isPTRing, setIsPTRing] = useState(false)
|
||||||
const {
|
const {
|
||||||
data,
|
data,
|
||||||
@@ -101,7 +94,7 @@ export const ProfileStarterPacks = React.forwardRef<
|
|||||||
setIsPTRing(false)
|
setIsPTRing(false)
|
||||||
}, [refetch, setIsPTRing])
|
}, [refetch, setIsPTRing])
|
||||||
|
|
||||||
const onEndReached = React.useCallback(async () => {
|
const onEndReached = useCallback(async () => {
|
||||||
if (isFetchingNextPage || !hasNextPage || isError) return
|
if (isFetchingNextPage || !hasNextPage || isError) return
|
||||||
try {
|
try {
|
||||||
await fetchNextPage()
|
await fetchNextPage()
|
||||||
@@ -144,7 +137,10 @@ export const ProfileStarterPacks = React.forwardRef<
|
|||||||
refreshing={isPTRing}
|
refreshing={isPTRing}
|
||||||
headerOffset={headerOffset}
|
headerOffset={headerOffset}
|
||||||
progressViewOffset={ios(0)}
|
progressViewOffset={ios(0)}
|
||||||
contentContainerStyle={{paddingBottom: headerOffset + bottomBarOffset}}
|
contentContainerStyle={{
|
||||||
|
minHeight: height + headerOffset,
|
||||||
|
paddingBottom: bottomBarOffset,
|
||||||
|
}}
|
||||||
removeClippedSubviews={true}
|
removeClippedSubviews={true}
|
||||||
desktopFixedHeight
|
desktopFixedHeight
|
||||||
onEndReached={onEndReached}
|
onEndReached={onEndReached}
|
||||||
@@ -158,7 +154,7 @@ export const ProfileStarterPacks = React.forwardRef<
|
|||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
})
|
}
|
||||||
|
|
||||||
function CreateAnother() {
|
function CreateAnother() {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react'
|
import {useCallback, useEffect, useImperativeHandle, useState} from 'react'
|
||||||
import {findNodeHandle, View} from 'react-native'
|
import {findNodeHandle, View} from 'react-native'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
@@ -18,6 +18,7 @@ import {Text} from '#/components/Typography'
|
|||||||
import {type SectionRef} from './types'
|
import {type SectionRef} from './types'
|
||||||
|
|
||||||
interface FeedSectionProps {
|
interface FeedSectionProps {
|
||||||
|
ref?: React.Ref<SectionRef>
|
||||||
feed: FeedDescriptor
|
feed: FeedDescriptor
|
||||||
headerHeight: number
|
headerHeight: number
|
||||||
isFocused: boolean
|
isFocused: boolean
|
||||||
@@ -25,31 +26,26 @@ interface FeedSectionProps {
|
|||||||
ignoreFilterFor?: string
|
ignoreFilterFor?: string
|
||||||
setScrollViewTag: (tag: number | null) => void
|
setScrollViewTag: (tag: number | null) => void
|
||||||
}
|
}
|
||||||
export const ProfileFeedSection = React.forwardRef<
|
export function ProfileFeedSection({
|
||||||
SectionRef,
|
|
||||||
FeedSectionProps
|
|
||||||
>(function FeedSectionImpl(
|
|
||||||
{
|
|
||||||
feed,
|
|
||||||
headerHeight,
|
|
||||||
isFocused,
|
|
||||||
scrollElRef,
|
|
||||||
ignoreFilterFor,
|
|
||||||
setScrollViewTag,
|
|
||||||
},
|
|
||||||
ref,
|
ref,
|
||||||
) {
|
feed,
|
||||||
|
headerHeight,
|
||||||
|
isFocused,
|
||||||
|
scrollElRef,
|
||||||
|
ignoreFilterFor,
|
||||||
|
setScrollViewTag,
|
||||||
|
}: FeedSectionProps) {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const [hasNew, setHasNew] = React.useState(false)
|
const [hasNew, setHasNew] = useState(false)
|
||||||
const [isScrolledDown, setIsScrolledDown] = React.useState(false)
|
const [isScrolledDown, setIsScrolledDown] = useState(false)
|
||||||
const shouldUseAdjustedNumToRender = feed.endsWith('posts_and_author_threads')
|
const shouldUseAdjustedNumToRender = feed.endsWith('posts_and_author_threads')
|
||||||
const isVideoFeed = isNative && feed.endsWith('posts_with_video')
|
const isVideoFeed = isNative && feed.endsWith('posts_with_video')
|
||||||
const adjustedInitialNumToRender = useInitialNumToRender({
|
const adjustedInitialNumToRender = useInitialNumToRender({
|
||||||
screenHeightOffset: headerHeight,
|
screenHeightOffset: headerHeight,
|
||||||
})
|
})
|
||||||
|
|
||||||
const onScrollToTop = React.useCallback(() => {
|
const onScrollToTop = useCallback(() => {
|
||||||
scrollElRef.current?.scrollToOffset({
|
scrollElRef.current?.scrollToOffset({
|
||||||
animated: isNative,
|
animated: isNative,
|
||||||
offset: -headerHeight,
|
offset: -headerHeight,
|
||||||
@@ -58,15 +54,15 @@ export const ProfileFeedSection = React.forwardRef<
|
|||||||
setHasNew(false)
|
setHasNew(false)
|
||||||
}, [scrollElRef, headerHeight, queryClient, feed, setHasNew])
|
}, [scrollElRef, headerHeight, queryClient, feed, setHasNew])
|
||||||
|
|
||||||
React.useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
scrollToTop: onScrollToTop,
|
scrollToTop: onScrollToTop,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const renderPostsEmpty = React.useCallback(() => {
|
const renderPostsEmpty = useCallback(() => {
|
||||||
return <EmptyState icon="growth" message={_(msg`No posts yet.`)} />
|
return <EmptyState icon="growth" message={_(msg`No posts yet.`)} />
|
||||||
}, [_])
|
}, [_])
|
||||||
|
|
||||||
React.useEffect(() => {
|
useEffect(() => {
|
||||||
if (isIOS && isFocused && scrollElRef.current) {
|
if (isIOS && isFocused && scrollElRef.current) {
|
||||||
const nativeTag = findNodeHandle(scrollElRef.current)
|
const nativeTag = findNodeHandle(scrollElRef.current)
|
||||||
setScrollViewTag(nativeTag)
|
setScrollViewTag(nativeTag)
|
||||||
@@ -101,7 +97,7 @@ export const ProfileFeedSection = React.forwardRef<
|
|||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
})
|
}
|
||||||
|
|
||||||
function ProfileEndOfFeed() {
|
function ProfileEndOfFeed() {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ interface LabelsSectionProps {
|
|||||||
isFocused: boolean
|
isFocused: boolean
|
||||||
setScrollViewTag: (tag: number | null) => void
|
setScrollViewTag: (tag: number | null) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ProfileLabelsSection({
|
export function ProfileLabelsSection({
|
||||||
ref,
|
ref,
|
||||||
isLabelerLoading,
|
isLabelerLoading,
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
import React from 'react'
|
import {
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useImperativeHandle,
|
||||||
|
useMemo,
|
||||||
|
useState,
|
||||||
|
} from 'react'
|
||||||
import {
|
import {
|
||||||
findNodeHandle,
|
findNodeHandle,
|
||||||
type ListRenderItemInfo,
|
type ListRenderItemInfo,
|
||||||
type StyleProp,
|
type StyleProp,
|
||||||
|
useWindowDimensions,
|
||||||
View,
|
View,
|
||||||
type ViewStyle,
|
type ViewStyle,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
@@ -34,6 +41,7 @@ interface SectionRef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ProfileFeedgensProps {
|
interface ProfileFeedgensProps {
|
||||||
|
ref?: React.Ref<SectionRef>
|
||||||
did: string
|
did: string
|
||||||
scrollElRef: ListRef
|
scrollElRef: ListRef
|
||||||
headerOffset: number
|
headerOffset: number
|
||||||
@@ -43,17 +51,21 @@ interface ProfileFeedgensProps {
|
|||||||
setScrollViewTag: (tag: number | null) => void
|
setScrollViewTag: (tag: number | null) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ProfileFeedgens = React.forwardRef<
|
export function ProfileFeedgens({
|
||||||
SectionRef,
|
|
||||||
ProfileFeedgensProps
|
|
||||||
>(function ProfileFeedgensImpl(
|
|
||||||
{did, scrollElRef, headerOffset, enabled, style, testID, setScrollViewTag},
|
|
||||||
ref,
|
ref,
|
||||||
) {
|
did,
|
||||||
|
scrollElRef,
|
||||||
|
headerOffset,
|
||||||
|
enabled,
|
||||||
|
style,
|
||||||
|
testID,
|
||||||
|
setScrollViewTag,
|
||||||
|
}: ProfileFeedgensProps) {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const [isPTRing, setIsPTRing] = React.useState(false)
|
const [isPTRing, setIsPTRing] = useState(false)
|
||||||
const opts = React.useMemo(() => ({enabled}), [enabled])
|
const {height} = useWindowDimensions()
|
||||||
|
const opts = useMemo(() => ({enabled}), [enabled])
|
||||||
const {
|
const {
|
||||||
data,
|
data,
|
||||||
isPending,
|
isPending,
|
||||||
@@ -67,7 +79,7 @@ export const ProfileFeedgens = React.forwardRef<
|
|||||||
const isEmpty = !isPending && !data?.pages[0]?.feeds.length
|
const isEmpty = !isPending && !data?.pages[0]?.feeds.length
|
||||||
const {data: preferences} = usePreferencesQuery()
|
const {data: preferences} = usePreferencesQuery()
|
||||||
|
|
||||||
const items = React.useMemo(() => {
|
const items = useMemo(() => {
|
||||||
let items: any[] = []
|
let items: any[] = []
|
||||||
if (isError && isEmpty) {
|
if (isError && isEmpty) {
|
||||||
items = items.concat([ERROR_ITEM])
|
items = items.concat([ERROR_ITEM])
|
||||||
@@ -91,7 +103,7 @@ export const ProfileFeedgens = React.forwardRef<
|
|||||||
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
const onScrollToTop = React.useCallback(() => {
|
const onScrollToTop = useCallback(() => {
|
||||||
scrollElRef.current?.scrollToOffset({
|
scrollElRef.current?.scrollToOffset({
|
||||||
animated: isNative,
|
animated: isNative,
|
||||||
offset: -headerOffset,
|
offset: -headerOffset,
|
||||||
@@ -99,11 +111,11 @@ export const ProfileFeedgens = React.forwardRef<
|
|||||||
queryClient.invalidateQueries({queryKey: RQKEY(did)})
|
queryClient.invalidateQueries({queryKey: RQKEY(did)})
|
||||||
}, [scrollElRef, queryClient, headerOffset, did])
|
}, [scrollElRef, queryClient, headerOffset, did])
|
||||||
|
|
||||||
React.useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
scrollToTop: onScrollToTop,
|
scrollToTop: onScrollToTop,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const onRefresh = React.useCallback(async () => {
|
const onRefresh = useCallback(async () => {
|
||||||
setIsPTRing(true)
|
setIsPTRing(true)
|
||||||
try {
|
try {
|
||||||
await refetch()
|
await refetch()
|
||||||
@@ -113,7 +125,7 @@ export const ProfileFeedgens = React.forwardRef<
|
|||||||
setIsPTRing(false)
|
setIsPTRing(false)
|
||||||
}, [refetch, setIsPTRing])
|
}, [refetch, setIsPTRing])
|
||||||
|
|
||||||
const onEndReached = React.useCallback(async () => {
|
const onEndReached = useCallback(async () => {
|
||||||
if (isFetchingNextPage || !hasNextPage || isError) return
|
if (isFetchingNextPage || !hasNextPage || isError) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -123,14 +135,14 @@ export const ProfileFeedgens = React.forwardRef<
|
|||||||
}
|
}
|
||||||
}, [isFetchingNextPage, hasNextPage, isError, fetchNextPage])
|
}, [isFetchingNextPage, hasNextPage, isError, fetchNextPage])
|
||||||
|
|
||||||
const onPressRetryLoadMore = React.useCallback(() => {
|
const onPressRetryLoadMore = useCallback(() => {
|
||||||
fetchNextPage()
|
fetchNextPage()
|
||||||
}, [fetchNextPage])
|
}, [fetchNextPage])
|
||||||
|
|
||||||
// rendering
|
// rendering
|
||||||
// =
|
// =
|
||||||
|
|
||||||
const renderItem = React.useCallback(
|
const renderItem = useCallback(
|
||||||
({item, index}: ListRenderItemInfo<any>) => {
|
({item, index}: ListRenderItemInfo<any>) => {
|
||||||
if (item === EMPTY) {
|
if (item === EMPTY) {
|
||||||
return (
|
return (
|
||||||
@@ -174,14 +186,14 @@ export const ProfileFeedgens = React.forwardRef<
|
|||||||
[_, t, error, refetch, onPressRetryLoadMore, preferences],
|
[_, t, error, refetch, onPressRetryLoadMore, preferences],
|
||||||
)
|
)
|
||||||
|
|
||||||
React.useEffect(() => {
|
useEffect(() => {
|
||||||
if (isIOS && enabled && scrollElRef.current) {
|
if (isIOS && enabled && scrollElRef.current) {
|
||||||
const nativeTag = findNodeHandle(scrollElRef.current)
|
const nativeTag = findNodeHandle(scrollElRef.current)
|
||||||
setScrollViewTag(nativeTag)
|
setScrollViewTag(nativeTag)
|
||||||
}
|
}
|
||||||
}, [enabled, scrollElRef, setScrollViewTag])
|
}, [enabled, scrollElRef, setScrollViewTag])
|
||||||
|
|
||||||
const ProfileFeedgensFooter = React.useCallback(() => {
|
const ProfileFeedgensFooter = useCallback(() => {
|
||||||
if (isEmpty) return null
|
if (isEmpty) return null
|
||||||
return (
|
return (
|
||||||
<ListFooter
|
<ListFooter
|
||||||
@@ -217,10 +229,11 @@ export const ProfileFeedgens = React.forwardRef<
|
|||||||
removeClippedSubviews={true}
|
removeClippedSubviews={true}
|
||||||
desktopFixedHeight
|
desktopFixedHeight
|
||||||
onEndReached={onEndReached}
|
onEndReached={onEndReached}
|
||||||
|
contentContainerStyle={{minHeight: height + headerOffset}}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
})
|
}
|
||||||
|
|
||||||
function keyExtractor(item: any) {
|
function keyExtractor(item: any) {
|
||||||
return item._reactKey || item.uri
|
return item._reactKey || item.uri
|
||||||
|
|||||||
+169
-158
@@ -1,8 +1,15 @@
|
|||||||
import React from 'react'
|
import {
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useImperativeHandle,
|
||||||
|
useMemo,
|
||||||
|
useState,
|
||||||
|
} from 'react'
|
||||||
import {
|
import {
|
||||||
findNodeHandle,
|
findNodeHandle,
|
||||||
type ListRenderItemInfo,
|
type ListRenderItemInfo,
|
||||||
type StyleProp,
|
type StyleProp,
|
||||||
|
useWindowDimensions,
|
||||||
View,
|
View,
|
||||||
type ViewStyle,
|
type ViewStyle,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
@@ -33,6 +40,7 @@ interface SectionRef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ProfileListsProps {
|
interface ProfileListsProps {
|
||||||
|
ref?: React.Ref<SectionRef>
|
||||||
did: string
|
did: string
|
||||||
scrollElRef: ListRef
|
scrollElRef: ListRef
|
||||||
headerOffset: number
|
headerOffset: number
|
||||||
@@ -42,182 +50,185 @@ interface ProfileListsProps {
|
|||||||
setScrollViewTag: (tag: number | null) => void
|
setScrollViewTag: (tag: number | null) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ProfileLists = React.forwardRef<SectionRef, ProfileListsProps>(
|
export function ProfileLists({
|
||||||
function ProfileListsImpl(
|
ref,
|
||||||
{did, scrollElRef, headerOffset, enabled, style, testID, setScrollViewTag},
|
did,
|
||||||
ref,
|
scrollElRef,
|
||||||
) {
|
headerOffset,
|
||||||
const t = useTheme()
|
enabled,
|
||||||
const {_} = useLingui()
|
style,
|
||||||
const [isPTRing, setIsPTRing] = React.useState(false)
|
testID,
|
||||||
const opts = React.useMemo(() => ({enabled}), [enabled])
|
setScrollViewTag,
|
||||||
const {
|
}: ProfileListsProps) {
|
||||||
data,
|
const t = useTheme()
|
||||||
isPending,
|
const {_} = useLingui()
|
||||||
hasNextPage,
|
const {height} = useWindowDimensions()
|
||||||
fetchNextPage,
|
const [isPTRing, setIsPTRing] = useState(false)
|
||||||
isFetchingNextPage,
|
const opts = useMemo(() => ({enabled}), [enabled])
|
||||||
isError,
|
const {
|
||||||
error,
|
data,
|
||||||
refetch,
|
isPending,
|
||||||
} = useProfileListsQuery(did, opts)
|
hasNextPage,
|
||||||
const isEmpty = !isPending && !data?.pages[0]?.lists.length
|
fetchNextPage,
|
||||||
|
isFetchingNextPage,
|
||||||
|
isError,
|
||||||
|
error,
|
||||||
|
refetch,
|
||||||
|
} = useProfileListsQuery(did, opts)
|
||||||
|
const isEmpty = !isPending && !data?.pages[0]?.lists.length
|
||||||
|
|
||||||
const items = React.useMemo(() => {
|
const items = useMemo(() => {
|
||||||
let items: any[] = []
|
let items: any[] = []
|
||||||
if (isError && isEmpty) {
|
if (isError && isEmpty) {
|
||||||
items = items.concat([ERROR_ITEM])
|
items = items.concat([ERROR_ITEM])
|
||||||
|
}
|
||||||
|
if (isPending) {
|
||||||
|
items = items.concat([LOADING])
|
||||||
|
} else if (isEmpty) {
|
||||||
|
items = items.concat([EMPTY])
|
||||||
|
} else if (data?.pages) {
|
||||||
|
for (const page of data?.pages) {
|
||||||
|
items = items.concat(page.lists)
|
||||||
}
|
}
|
||||||
if (isPending) {
|
}
|
||||||
items = items.concat([LOADING])
|
if (isError && !isEmpty) {
|
||||||
} else if (isEmpty) {
|
items = items.concat([LOAD_MORE_ERROR_ITEM])
|
||||||
items = items.concat([EMPTY])
|
}
|
||||||
} else if (data?.pages) {
|
return items
|
||||||
for (const page of data?.pages) {
|
}, [isError, isEmpty, isPending, data])
|
||||||
items = items.concat(page.lists)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isError && !isEmpty) {
|
|
||||||
items = items.concat([LOAD_MORE_ERROR_ITEM])
|
|
||||||
}
|
|
||||||
return items
|
|
||||||
}, [isError, isEmpty, isPending, data])
|
|
||||||
|
|
||||||
// events
|
// events
|
||||||
// =
|
// =
|
||||||
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
const onScrollToTop = React.useCallback(() => {
|
const onScrollToTop = useCallback(() => {
|
||||||
scrollElRef.current?.scrollToOffset({
|
scrollElRef.current?.scrollToOffset({
|
||||||
animated: isNative,
|
animated: isNative,
|
||||||
offset: -headerOffset,
|
offset: -headerOffset,
|
||||||
})
|
})
|
||||||
queryClient.invalidateQueries({queryKey: RQKEY(did)})
|
queryClient.invalidateQueries({queryKey: RQKEY(did)})
|
||||||
}, [scrollElRef, queryClient, headerOffset, did])
|
}, [scrollElRef, queryClient, headerOffset, did])
|
||||||
|
|
||||||
React.useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
scrollToTop: onScrollToTop,
|
scrollToTop: onScrollToTop,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const onRefresh = React.useCallback(async () => {
|
const onRefresh = useCallback(async () => {
|
||||||
setIsPTRing(true)
|
setIsPTRing(true)
|
||||||
try {
|
try {
|
||||||
await refetch()
|
await refetch()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('Failed to refresh lists', {message: err})
|
logger.error('Failed to refresh lists', {message: err})
|
||||||
}
|
}
|
||||||
setIsPTRing(false)
|
setIsPTRing(false)
|
||||||
}, [refetch, setIsPTRing])
|
}, [refetch, setIsPTRing])
|
||||||
|
|
||||||
const onEndReached = React.useCallback(async () => {
|
const onEndReached = useCallback(async () => {
|
||||||
if (isFetchingNextPage || !hasNextPage || isError) return
|
if (isFetchingNextPage || !hasNextPage || isError) return
|
||||||
try {
|
try {
|
||||||
await fetchNextPage()
|
await fetchNextPage()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('Failed to load more lists', {message: err})
|
logger.error('Failed to load more lists', {message: err})
|
||||||
}
|
}
|
||||||
}, [isFetchingNextPage, hasNextPage, isError, fetchNextPage])
|
}, [isFetchingNextPage, hasNextPage, isError, fetchNextPage])
|
||||||
|
|
||||||
const onPressRetryLoadMore = React.useCallback(() => {
|
const onPressRetryLoadMore = useCallback(() => {
|
||||||
fetchNextPage()
|
fetchNextPage()
|
||||||
}, [fetchNextPage])
|
}, [fetchNextPage])
|
||||||
|
|
||||||
// rendering
|
// rendering
|
||||||
// =
|
// =
|
||||||
|
|
||||||
const renderItemInner = React.useCallback(
|
const renderItemInner = useCallback(
|
||||||
({item, index}: ListRenderItemInfo<any>) => {
|
({item, index}: ListRenderItemInfo<any>) => {
|
||||||
if (item === EMPTY) {
|
if (item === EMPTY) {
|
||||||
return (
|
|
||||||
<EmptyState
|
|
||||||
icon="list-ul"
|
|
||||||
message={_(msg`You have no lists.`)}
|
|
||||||
testID="listsEmpty"
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
} else if (item === ERROR_ITEM) {
|
|
||||||
return (
|
|
||||||
<ErrorMessage
|
|
||||||
message={cleanError(error)}
|
|
||||||
onPressTryAgain={refetch}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
} else if (item === LOAD_MORE_ERROR_ITEM) {
|
|
||||||
return (
|
|
||||||
<LoadMoreRetryBtn
|
|
||||||
label={_(
|
|
||||||
msg`There was an issue fetching your lists. Tap here to try again.`,
|
|
||||||
)}
|
|
||||||
onPress={onPressRetryLoadMore}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
} else if (item === LOADING) {
|
|
||||||
return <FeedLoadingPlaceholder />
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<View
|
<EmptyState
|
||||||
style={[
|
icon="list-ul"
|
||||||
(index !== 0 || isWeb) && a.border_t,
|
message={_(msg`You have no lists.`)}
|
||||||
t.atoms.border_contrast_low,
|
testID="listsEmpty"
|
||||||
a.px_lg,
|
/>
|
||||||
a.py_lg,
|
|
||||||
]}>
|
|
||||||
<ListCard.Default view={item} />
|
|
||||||
</View>
|
|
||||||
)
|
)
|
||||||
},
|
} else if (item === ERROR_ITEM) {
|
||||||
[error, refetch, onPressRetryLoadMore, _, t.atoms.border_contrast_low],
|
return (
|
||||||
)
|
<ErrorMessage message={cleanError(error)} onPressTryAgain={refetch} />
|
||||||
|
)
|
||||||
React.useEffect(() => {
|
} else if (item === LOAD_MORE_ERROR_ITEM) {
|
||||||
if (isIOS && enabled && scrollElRef.current) {
|
return (
|
||||||
const nativeTag = findNodeHandle(scrollElRef.current)
|
<LoadMoreRetryBtn
|
||||||
setScrollViewTag(nativeTag)
|
label={_(
|
||||||
|
msg`There was an issue fetching your lists. Tap here to try again.`,
|
||||||
|
)}
|
||||||
|
onPress={onPressRetryLoadMore}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
} else if (item === LOADING) {
|
||||||
|
return <FeedLoadingPlaceholder />
|
||||||
}
|
}
|
||||||
}, [enabled, scrollElRef, setScrollViewTag])
|
|
||||||
|
|
||||||
const ProfileListsFooter = React.useCallback(() => {
|
|
||||||
if (isEmpty) return null
|
|
||||||
return (
|
return (
|
||||||
<ListFooter
|
<View
|
||||||
hasNextPage={hasNextPage}
|
style={[
|
||||||
isFetchingNextPage={isFetchingNextPage}
|
(index !== 0 || isWeb) && a.border_t,
|
||||||
onRetry={fetchNextPage}
|
t.atoms.border_contrast_low,
|
||||||
error={cleanError(error)}
|
a.px_lg,
|
||||||
height={180 + headerOffset}
|
a.py_lg,
|
||||||
/>
|
]}>
|
||||||
|
<ListCard.Default view={item} />
|
||||||
|
</View>
|
||||||
)
|
)
|
||||||
}, [
|
},
|
||||||
hasNextPage,
|
[error, refetch, onPressRetryLoadMore, _, t.atoms.border_contrast_low],
|
||||||
error,
|
)
|
||||||
isFetchingNextPage,
|
|
||||||
headerOffset,
|
|
||||||
fetchNextPage,
|
|
||||||
isEmpty,
|
|
||||||
])
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isIOS && enabled && scrollElRef.current) {
|
||||||
|
const nativeTag = findNodeHandle(scrollElRef.current)
|
||||||
|
setScrollViewTag(nativeTag)
|
||||||
|
}
|
||||||
|
}, [enabled, scrollElRef, setScrollViewTag])
|
||||||
|
|
||||||
|
const ProfileListsFooter = useCallback(() => {
|
||||||
|
if (isEmpty) return null
|
||||||
return (
|
return (
|
||||||
<View testID={testID} style={style}>
|
<ListFooter
|
||||||
<List
|
hasNextPage={hasNextPage}
|
||||||
testID={testID ? `${testID}-flatlist` : undefined}
|
isFetchingNextPage={isFetchingNextPage}
|
||||||
ref={scrollElRef}
|
onRetry={fetchNextPage}
|
||||||
data={items}
|
error={cleanError(error)}
|
||||||
keyExtractor={keyExtractor}
|
height={180 + headerOffset}
|
||||||
renderItem={renderItemInner}
|
/>
|
||||||
ListFooterComponent={ProfileListsFooter}
|
|
||||||
refreshing={isPTRing}
|
|
||||||
onRefresh={onRefresh}
|
|
||||||
headerOffset={headerOffset}
|
|
||||||
progressViewOffset={ios(0)}
|
|
||||||
removeClippedSubviews={true}
|
|
||||||
desktopFixedHeight
|
|
||||||
onEndReached={onEndReached}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
)
|
)
|
||||||
},
|
}, [
|
||||||
)
|
hasNextPage,
|
||||||
|
error,
|
||||||
|
isFetchingNextPage,
|
||||||
|
headerOffset,
|
||||||
|
fetchNextPage,
|
||||||
|
isEmpty,
|
||||||
|
])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View testID={testID} style={style}>
|
||||||
|
<List
|
||||||
|
testID={testID ? `${testID}-flatlist` : undefined}
|
||||||
|
ref={scrollElRef}
|
||||||
|
data={items}
|
||||||
|
keyExtractor={keyExtractor}
|
||||||
|
renderItem={renderItemInner}
|
||||||
|
ListFooterComponent={ProfileListsFooter}
|
||||||
|
refreshing={isPTRing}
|
||||||
|
onRefresh={onRefresh}
|
||||||
|
headerOffset={headerOffset}
|
||||||
|
progressViewOffset={ios(0)}
|
||||||
|
removeClippedSubviews={true}
|
||||||
|
desktopFixedHeight
|
||||||
|
onEndReached={onEndReached}
|
||||||
|
contentContainerStyle={{minHeight: height + headerOffset}}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function keyExtractor(item: any) {
|
function keyExtractor(item: any) {
|
||||||
return item._reactKey || item.uri
|
return item._reactKey || item.uri
|
||||||
|
|||||||
Reference in New Issue
Block a user