diff --git a/android/app/build.gradle b/android/app/build.gradle index 2bdfb8d..53bdf1c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -135,8 +135,8 @@ android { applicationId "com.spotifyclone" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1 - versionName "1.0" + versionCode 2 + versionName "1.0.1" } splits { abi { diff --git a/src/constants/feed.ts b/src/constants/feed.ts index 47d1b6c..6898133 100644 --- a/src/constants/feed.ts +++ b/src/constants/feed.ts @@ -1,6 +1,6 @@ import {IFeedItemDataSource} from '../interfaces/feed'; -export const FEED_PAGE_LIMIT = 3; +export const FEED_PAGE_LIMIT = 1; export const FEED_ITEMS_SOURCE: IFeedItemDataSource[] = [ { diff --git a/src/screens/HomeScreen/index.tsx b/src/screens/HomeScreen/index.tsx index ae5524b..34f0065 100644 --- a/src/screens/HomeScreen/index.tsx +++ b/src/screens/HomeScreen/index.tsx @@ -1,4 +1,4 @@ -import React, {useEffect} from 'react'; +import React, {useEffect, useState} from 'react'; import {RouteProp} from '@react-navigation/native'; import {StackNavigationProp} from '@react-navigation/stack'; import {useSelector} from 'react-redux'; @@ -9,7 +9,7 @@ import {HomeStackParamList} from '../MainScreen'; import {RootState, useAppDispatch} from '../../store'; import {fetchFeed} from '../../slices/feed'; import {FEED_ITEMS_SOURCE, FEED_PAGE_LIMIT} from '../../constants/feed'; -import {FlatList, StyleSheet} from 'react-native'; +import {FlatList, RefreshControl, StyleSheet} from 'react-native'; import {SPACE_8} from '../../constants/dimens'; import {useSafeAreaInsets} from 'react-native-safe-area-context'; import {IFeedItem} from '../../interfaces/feed'; @@ -27,11 +27,23 @@ const HomeScreen: React.FC = ({navigation}) => { const {data, isLoading} = useSelector((state: RootState) => state.feed); const dispatch = useAppDispatch(); const insets = useSafeAreaInsets(); + const [refreshing, setRefreshing] = useState(false); - useEffect(() => { + const fetchFirstPage = async () => { const dataSources = FEED_ITEMS_SOURCE.slice(0, FEED_PAGE_LIMIT); - dispatch(fetchFeed({page: 1, dataSources})); - }, [dispatch]); + await dispatch(fetchFeed({page: 1, dataSources})); + }; + + useEffect(() => { + fetchFirstPage(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + const handleRefresh = async () => { + setRefreshing(true); + await fetchFirstPage(); + setRefreshing(false); + }; const handleEndReached = () => { const feedItemsCount = data?.length ?? 0; @@ -69,6 +81,10 @@ const HomeScreen: React.FC = ({navigation}) => { ); }; + const renderRefreshControl = () => { + return ; + }; + if (!data && isLoading) { return ; } @@ -83,6 +99,7 @@ const HomeScreen: React.FC = ({navigation}) => { onEndReached={handleEndReached} contentContainerStyle={contentStyle} showsVerticalScrollIndicator={false} + refreshControl={renderRefreshControl()} /> );