diff --git a/src/components/TransactionList.js b/src/components/TransactionList.js new file mode 100644 index 0000000..71b043f --- /dev/null +++ b/src/components/TransactionList.js @@ -0,0 +1,132 @@ +import React from 'react'; +import { View, Text, FlatList, StyleSheet } from 'react-native'; +import { Ionicons } from '@expo/vector-icons'; +import { COLORS } from '../constants/colors'; + +const TransactionList = ({ transactions }) => { + if (!transactions || transactions.length === 0) { + return ( + + No transactions yet. + + ); + } + + const groupedTransactions = transactions.reduce((acc, transaction) => { + const date = new Date(transaction.date).toLocaleDateString('en-US', { + year: 'numeric', + month: 'long', + day: 'numeric', + }); + if (!acc[date]) { + acc[date] = []; + } + acc[date].push(transaction); + return acc; + }, {}); + + const renderTransactionItem = ({ item }) => ( + + + + + + {item.description} + {new Date(item.date).toLocaleTimeString()} + + + {item.type === 'credit' ? '+' : '-'} + {item.amount} {item.currency} + + + ); + + const renderTransactionSection = ({ item: date }) => ( + + {date} + item.id.toString()} + scrollEnabled={false} + ItemSeparatorComponent={() => } + /> + + ); + + return ( + date} + scrollEnabled={false} + ItemSeparatorComponent={() => } + /> + ); +}; + +const styles = StyleSheet.create({ + container: { + padding: 16, + }, + emptyText: { + textAlign: 'center', + color: COLORS.textSecondary, + }, + transactionItem: { + flexDirection: 'row', + alignItems: 'center', + paddingVertical: 12, + }, + transactionIcon: { + width: 44, + height: 44, + borderRadius: 22, + backgroundColor: COLORS.background, + alignItems: 'center', + justifyContent: 'center', + marginRight: 16, + }, + transactionDetails: { + flex: 1, + }, + transactionTitle: { + fontSize: 16, + fontWeight: '600', + color: COLORS.textPrimary, + marginBottom: 2, + }, + transactionDate: { + fontSize: 13, + color: COLORS.textSecondary, + }, + transactionAmount: { + fontSize: 16, + fontWeight: '700', + }, + transactionDateHeader: { + fontSize: 14, + fontWeight: '600', + color: COLORS.textSecondary, + backgroundColor: COLORS.white, + paddingTop: 16, + paddingBottom: 8, + paddingHorizontal: 4, + }, + separator: { + height: 1, + backgroundColor: COLORS.gray[200], + marginLeft: 60, + }, +}); + +export default TransactionList; diff --git a/src/screens/Main/HomeScreen.js b/src/screens/Main/HomeScreen.js index 8d28ef0..2c5570e 100644 --- a/src/screens/Main/HomeScreen.js +++ b/src/screens/Main/HomeScreen.js @@ -16,6 +16,7 @@ import { useAuth } from '../../contexts/AuthContext'; import { COLORS } from '../../constants/colors'; import MetricCard from '../../components/MetricCard'; import apiService from '../../services/apiService'; +import TransactionList from '../../components/TransactionList'; const STATIC_TRANSACTIONS = [ { @@ -212,57 +213,6 @@ const HomeScreen = () => { setRefreshing(false); }; - const groupedTransactions = transactions.reduce((acc, transaction) => { - const date = new Date(transaction.date).toLocaleDateString('en-US', { - year: 'numeric', - month: 'long', - day: 'numeric', - }); - if (!acc[date]) { - acc[date] = []; - } - acc[date].push(transaction); - return acc; - }, {}); - - const renderTransactionItem = ({ item }) => ( - - - - - - {item.description} - {new Date(item.date).toLocaleTimeString()} - - - {item.type === 'credit' ? '+' : '-'} - {item.amount} {item.currency} - - - ); - - const renderTransactionSection = ({ item: date }) => ( - - {date} - item.id.toString()} - scrollEnabled={false} - ItemSeparatorComponent={() => } - /> - - ); - return ( @@ -330,17 +280,7 @@ const HomeScreen = () => { See All - {transactions.length > 0 ? ( - date} - scrollEnabled={false} - ItemSeparatorComponent={() => } - /> - ) : ( - No transactions yet. - )} + )} @@ -472,54 +412,6 @@ const styles = StyleSheet.create({ color: COLORS.textSecondary, textAlign: 'center', }, - transactionsList: { - marginTop: 16, - }, - transactionItem: { - flexDirection: 'row', - alignItems: 'center', - paddingVertical: 12, - }, - transactionIcon: { - width: 44, - height: 44, - borderRadius: 22, - backgroundColor: COLORS.background, - alignItems: 'center', - justifyContent: 'center', - marginRight: 16, - }, - transactionDetails: { - flex: 1, - }, - transactionTitle: { - fontSize: 16, - fontWeight: '600', - color: COLORS.textPrimary, - marginBottom: 2, - }, - transactionDate: { - fontSize: 13, - color: COLORS.textSecondary, - }, - transactionAmount: { - fontSize: 16, - fontWeight: '700', - }, - transactionDateHeader: { - fontSize: 14, - fontWeight: '600', - color: COLORS.textSecondary, - backgroundColor: COLORS.white, - paddingTop: 16, - paddingBottom: 8, - paddingHorizontal: 4, - }, - separator: { - height: 1, - backgroundColor: COLORS.gray[200], - marginLeft: 60, // Align with transaction details, skipping the icon - }, metricsGrid: { flexDirection: 'row', justifyContent: 'space-between',