diff --git a/packages/app/components/carousel/index.tsx b/packages/app/components/carousel/index.tsx index 099405f72..077d573be 100644 --- a/packages/app/components/carousel/index.tsx +++ b/packages/app/components/carousel/index.tsx @@ -4,8 +4,10 @@ import { Platform, Dimensions, NativeScrollEvent, + RefreshControl, + FlatList, } from 'react-native'; -import { RStack } from '@packrat/ui'; +import { RStack, RText } from '@packrat/ui'; import ScrollButton from './ScrollButton'; import useCustomStyles from 'app/hooks/useCustomStyles'; @@ -13,6 +15,9 @@ interface CarouselProps { children?: ReactNode[]; itemWidth?: number; iconColor?: string; + refreshing?: boolean; + onEndReached: () => void; + onRefresh?: () => void; } const { width: screenWidth } = Dimensions.get('window'); @@ -20,9 +25,12 @@ const { width: screenWidth } = Dimensions.get('window'); const Carousel: React.FC = ({ children = [], itemWidth, + refreshing, + onRefresh, + onEndReached, iconColor, }) => { - const scrollViewRef = useRef(null); + const scrollViewRef = useRef(null); const [currentIndex, setCurrentIndex] = useState(0); const styles = useCustomStyles(loadStyles); @@ -67,31 +75,39 @@ const Carousel: React.FC = ({ /> )} - - {children && - children.map((child, index) => ( - - {child} - - ))} - + refreshControl={ + + } + // keyExtractor={keyExtractor} + data={children} // Pass the children as data to FlatList + renderItem={({ item, index }) => ( + + {item} + + )} + onEndReached={onEndReached} + onEndReachedThreshold={1} + /> {/* Show buttons only on web */} {Platform.OS === 'web' && ( diff --git a/packages/app/modules/feed/components/FeedCard/.FeedCard.tsx.swp b/packages/app/modules/feed/components/FeedCard/.FeedCard.tsx.swp new file mode 100644 index 000000000..9f0159269 Binary files /dev/null and b/packages/app/modules/feed/components/FeedCard/.FeedCard.tsx.swp differ diff --git a/packages/app/modules/feed/hooks/useFeed.ts b/packages/app/modules/feed/hooks/useFeed.ts index 911e566fe..fa6b20dad 100644 --- a/packages/app/modules/feed/hooks/useFeed.ts +++ b/packages/app/modules/feed/hooks/useFeed.ts @@ -46,7 +46,7 @@ export const useFeed = ({ const userPacks = useUserPacks( ownerId || undefined, { searchTerm: searchQuery }, - queryString, + queryString, feedType === 'userPacks', ); const userTrips = useUserTrips( diff --git a/packages/app/modules/feed/hooks/usePublicFeed.ts b/packages/app/modules/feed/hooks/usePublicFeed.ts index d7f8c6daa..fc1f03010 100644 --- a/packages/app/modules/feed/hooks/usePublicFeed.ts +++ b/packages/app/modules/feed/hooks/usePublicFeed.ts @@ -16,6 +16,7 @@ export const usePublicFeed = ( const [pagination, setPagination] = useState( getPaginationInitialParams(), ); + const { data, isLoading, refetch } = queryTrpc.getPublicFeed.useQuery( { queryBy: queryBy ?? 'Favorites', @@ -46,7 +47,7 @@ export const usePublicFeed = ( setPagination, { nextPage: data?.nextOffset, enabled }, ); - + console.log('allData ', allData) return { data: allData, isLoading, diff --git a/packages/app/modules/feed/widgets/FeedPreview/FeedPreview.tsx b/packages/app/modules/feed/widgets/FeedPreview/FeedPreview.tsx index 0950bd7d9..0c408a21c 100644 --- a/packages/app/modules/feed/widgets/FeedPreview/FeedPreview.tsx +++ b/packages/app/modules/feed/widgets/FeedPreview/FeedPreview.tsx @@ -1,4 +1,4 @@ -import React, { memo } from 'react'; +import React, { memo, useCallback, useState } from 'react'; import Carousel from 'app/components/carousel'; import { useFeed } from '../../hooks'; import Loader from 'app/components/Loader'; @@ -16,12 +16,26 @@ const FeedPreviewScroll: React.FC = ({ feedType, id, }) => { - const { data: feedData, isLoading } = useFeed({ feedType, id }); + const { data: feedData, isLoading, refetch, fetchNextPage, nextPage } = useFeed({ feedType, id }); + const [refreshing, setRefreshing] = useState(false); + console.log('feedData', feedData) + + const onRefresh = useCallback(async () => { + setRefreshing(true); + await refetch(); + setRefreshing(false); + }, [refetch]); + + const onEndReached = useCallback(async () => { + if (!isLoading && nextPage) { + fetchNextPage(); + } + }, [isLoading, nextPage, fetchNextPage]); return isLoading ? ( ) : ( - + {feedData ?.filter((item): item is FeedItem => item.type !== null) .map((item: FeedItem) => {