ICS React Native App
1import { FlashList } from "@shopify/flash-list";
2import { RefreshControl, TouchableOpacity } from "react-native";
3import { ThemedText } from "@/components/theme";
4
5import { TransactionCard } from "./transaction-card";
6
7import {
8 useTransactions,
9 TransactionFilterOptions,
10} from "@/hooks/use-transactions";
11
12interface TransactionListProps {
13 accountId?: number;
14 filter?: TransactionFilterOptions;
15}
16
17export const TransactionList = ({
18 accountId,
19 filter,
20}: TransactionListProps) => {
21 const { transactions, isRefetching, refetch, hasNextPage, fetchNextPage } =
22 useTransactions(accountId, filter);
23
24 return (
25 <FlashList
26 nestedScrollEnabled={true}
27 data={(transactions?.pages ?? []).flatMap(({ data }) => data)}
28 keyExtractor={({ id }) => id.toString()}
29 refreshControl={
30 <RefreshControl
31 tintColor="blue"
32 refreshing={isRefetching}
33 onRefresh={refetch}
34 />
35 }
36 ListFooterComponent={
37 hasNextPage ? (
38 <TouchableOpacity
39 onPress={() => fetchNextPage}
40 style={{ display: "flex" }}
41 >
42 <ThemedText>fetch more</ThemedText>
43 </TouchableOpacity>
44 ) : null
45 }
46 renderItem={({ item }) => (
47 <TransactionCard key={`${item.id}`} transaction={item} />
48 )}
49 onEndReachedThreshold={0.95}
50 onEndReached={() => {
51 fetchNextPage();
52 }}
53 />
54 );
55};