Skip to content

Commit

Permalink
Token expiry fix (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gopalakrishnan-V authored May 16, 2023
1 parent c9507cd commit 4cbc3d9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/constants/feed.ts
Original file line number Diff line number Diff line change
@@ -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[] = [
{
Expand Down
27 changes: 22 additions & 5 deletions src/screens/HomeScreen/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand All @@ -27,11 +27,23 @@ const HomeScreen: React.FC<HomeScreenProps> = ({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;
Expand Down Expand Up @@ -69,6 +81,10 @@ const HomeScreen: React.FC<HomeScreenProps> = ({navigation}) => {
);
};

const renderRefreshControl = () => {
return <RefreshControl refreshing={refreshing} onRefresh={handleRefresh} />;
};

if (!data && isLoading) {
return <Loader />;
}
Expand All @@ -83,6 +99,7 @@ const HomeScreen: React.FC<HomeScreenProps> = ({navigation}) => {
onEndReached={handleEndReached}
contentContainerStyle={contentStyle}
showsVerticalScrollIndicator={false}
refreshControl={renderRefreshControl()}
/>
</ScreenWrapper>
);
Expand Down

0 comments on commit 4cbc3d9

Please sign in to comment.