Skip to content

Commit

Permalink
feat(app): cursor based pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-h1 committed Dec 25, 2024
1 parent d98227f commit 3a68820
Show file tree
Hide file tree
Showing 11 changed files with 367 additions and 202 deletions.
19 changes: 9 additions & 10 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/* eslint-disable */
import { registerRootComponent } from 'expo';
import NewRelic from 'newrelic-react-native-agent';
import * as SplashScreen from 'expo-splash-screen';
import newRelic from 'newrelic-react-native-agent';
import { Platform } from 'react-native';
import App from './src/App';
import { version } from '../package.json';
import App from './App';
import 'expo-dev-client';
import { version } from './package.json' assert { type: 'json' };
import './src/polyfills';
import * as SplashScreen from 'expo-splash-screen';

// eslint-disable-next-line no-undef
if (!__DEV__) {
Expand Down Expand Up @@ -38,22 +36,23 @@ if (!__DEV__) {
loggingEnabled: true,
// Optional:Specifies the log level. Omit this field for the default log level.
// Options include: ERROR (least verbose), WARNING, INFO, VERBOSE, AUDIT (most verbose).
logLevel: NewRelic.LogLevel.INFO,
logLevel: newRelic.LogLevel.INFO,
// iOS Specific
// Optional:Enable/Disable automatic instrumentation of WebViews
webViewInstrumentation: true,
};

agentConfiguration.loggingEnabled = true;
agentConfiguration.logLevel = NewRelic.LogLevel.VERBOSE;
agentConfiguration.logLevel = newRelic.LogLevel.VERBOSE;

NewRelic.startAgent(appToken, agentConfiguration);
NewRelic.setJSAppVersion(version);
newRelic.startAgent(appToken, agentConfiguration);
newRelic.setJSAppVersion(version);
}

SplashScreen.preventAutoHideAsync();

function FoamApp() {
// eslint-disable-next-line react/jsx-filename-extension
return <App hideSplashScreen={SplashScreen.hideAsync} />;
}

Expand Down
14 changes: 7 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ export default function App(props: AppProps) {

// otherwise, we're ready to render the app
return (
<SafeAreaProvider initialMetrics={initialWindowMetrics}>
<ErrorBoundary
catchErrors={Config.catchErrors}
onReset={() => setRecoveredFromError(true)}
>
<ErrorBoundary
catchErrors={Config.catchErrors}
onReset={() => setRecoveredFromError(true)}
>
<SafeAreaProvider initialMetrics={initialWindowMetrics}>
<QueryClientProvider client={queryClient}>
<GestureHandlerRootView style={$bottomSheetContainer}>
<BottomSheetModalProvider>
Expand All @@ -131,8 +131,8 @@ export default function App(props: AppProps) {
</BottomSheetModalProvider>
</GestureHandlerRootView>
</QueryClientProvider>
</ErrorBoundary>
</SafeAreaProvider>
</SafeAreaProvider>
</ErrorBoundary>
);
}

Expand Down
28 changes: 28 additions & 0 deletions src/components/ScrollToTop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { colors } from '@app/styles';
import { TextStyle, TouchableOpacity, ViewStyle } from 'react-native';
import { Text } from './ui/Text';

interface Props {
onPress: () => void;
}

export default function ScrollToTop({ onPress }: Props) {
return (
<TouchableOpacity style={$topButton} onPress={onPress}>
<Text style={$topText}>TOP</Text>
</TouchableOpacity>
);
}
const $topButton: ViewStyle = {
position: 'absolute',
bottom: 20,
right: 20,
backgroundColor: 'rgba(0,0,0,0.5)',
borderRadius: 25,
padding: 10,
};

const $topText: TextStyle = {
color: colors.text,
fontWeight: 'bold',
};
6 changes: 3 additions & 3 deletions src/navigators/TopStackNavigator.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import CategoriesSecreen from '@app/screens/Top/Categories';
import TopCategoriesScreen from '@app/screens/Top/Categories';
import TopStreamsScreen from '@app/screens/Top/Streams';
import TopScreen from '@app/screens/Top/TopScreen';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { StackScreenProps } from '@react-navigation/stack';

export type TopStackParamList = {
Top: undefined;
Categories: undefined;
TopCategories: undefined;
TopStreams: undefined;
};

Expand All @@ -19,7 +19,7 @@ export default function TopStackNavigator() {
return (
<Stack.Navigator initialRouteName="Top">
<Stack.Screen name="Top" component={TopScreen} />
<Stack.Screen name="Categories" component={CategoriesSecreen} />
<Stack.Screen name="TopCategories" component={TopCategoriesScreen} />
<Stack.Screen name="TopStreams" component={TopStreamsScreen} />
</Stack.Navigator>
);
Expand Down
4 changes: 4 additions & 0 deletions src/navigators/navigationUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
NavigationAction,
createNavigationContainerRef,
} from '@react-navigation/native';
import newRelic from 'newrelic-react-native-agent';
import { useCallback, useEffect, useRef, useState } from 'react';
import { BackHandler, Platform } from 'react-native';
import Config, { type PersistNavigationConfig } from '../config';
Expand Down Expand Up @@ -165,6 +166,9 @@ export function useNavigationPersistence(storage: any, persistenceKey: string) {

// persist state to storage
storage.save(persistenceKey, state);

// log to new relic
newRelic.onStateChange(state);
}
}
};
Expand Down
10 changes: 7 additions & 3 deletions src/queries/twitchQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import twitchService, {
Category,
UserInfoResponse,
SearchChannelResponse,
PaginatedList,
} from '@app/services/twitchService';
import { UseQueryOptions } from '@tanstack/react-query';

Expand All @@ -20,7 +21,7 @@ const twitchQueries = {
queryFn: () => twitchService.getChannel(userId),
};
},
getTopCategories(): UseQueryOptions<Category[]> {
getTopCategories(): UseQueryOptions<PaginatedList<Category>> {
return {
queryKey: ['topCategories'],
queryFn: () => twitchService.getTopCategories(),
Expand Down Expand Up @@ -56,7 +57,7 @@ const twitchQueries = {
queryFn: () => twitchService.searchChannels(query),
};
},
getTopStreams(cursor?: string): UseQueryOptions<Stream[]> {
getTopStreams(cursor?: string): UseQueryOptions<PaginatedList<Stream>> {
return {
queryKey: ['topStreams', cursor],
queryFn: () => twitchService.getTopStreams(cursor),
Expand All @@ -68,7 +69,10 @@ const twitchQueries = {
queryFn: () => twitchService.getCategory(id),
};
},
getStreamsByCategory(id: string, cursor?: string): UseQueryOptions<Stream[]> {
getStreamsByCategory(
id: string,
cursor?: string,
): UseQueryOptions<PaginatedList<Stream>> {
return {
queryKey: ['streamsByCategory', id, cursor],
queryFn: () => twitchService.getStreamsByCategory(id, cursor),
Expand Down
Loading

0 comments on commit 3a68820

Please sign in to comment.