-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
297 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import moment from 'moment'; | ||
import React, { useCallback, useRef } from 'react'; | ||
import { ListRenderItemInfo, RefreshControl } from 'react-native'; | ||
import { useTheme } from 'styled-components/native'; | ||
import Divider from '../../../components/Divider'; | ||
import Money from '../../../components/Money'; | ||
import Text from '../../../components/Text'; | ||
import { Transaction } from '../../../services/pluggy'; | ||
import { | ||
ListHeaderContainer, | ||
ListSeparatorContainer, | ||
ListSeparatorDate, | ||
StyledFlatList, | ||
StyledTransactionListItem, | ||
} from './styles'; | ||
|
||
export interface TransactionListProps { | ||
transactions: Transaction[]; | ||
reducedValue: number; | ||
isLoading?: boolean; | ||
onRefresh?: () => void; | ||
} | ||
|
||
const TransactionList: React.FC<TransactionListProps> = ({ | ||
transactions, | ||
reducedValue, | ||
isLoading, | ||
onRefresh, | ||
}) => { | ||
const theme = useTheme(); | ||
|
||
const ItemDividerPreviousDateRef = useRef(moment(0)); | ||
|
||
const renderHeaderComponent = useCallback(() => { | ||
return ( | ||
<ListHeaderContainer> | ||
<Text variant="light" color="textLight"> | ||
{transactions.length} transações | ||
</Text> | ||
<Money variant="heading" value={reducedValue} /> | ||
</ListHeaderContainer> | ||
); | ||
}, [transactions, reducedValue]); | ||
|
||
const renderListItemSeparator = useCallback((transaction: Transaction, index: number) => { | ||
const date = moment(transaction.date).startOf('day'); | ||
|
||
const component = | ||
index === 0 || date.isBefore(ItemDividerPreviousDateRef.current, 'day') ? ( | ||
<ListSeparatorContainer> | ||
<ListSeparatorDate> | ||
<Text variant="title" color="textLight"> | ||
{date.format('DD')} | ||
</Text> | ||
<Text variant="light" color="textLight"> | ||
{date.format('MMM')} | ||
</Text> | ||
</ListSeparatorDate> | ||
<Divider /> | ||
</ListSeparatorContainer> | ||
) : ( | ||
<></> | ||
); | ||
|
||
ItemDividerPreviousDateRef.current = date; | ||
|
||
return component; | ||
}, []); | ||
|
||
const renderItem = useCallback( | ||
({ item, index }: ListRenderItemInfo<Transaction>) => { | ||
return ( | ||
<> | ||
{renderListItemSeparator(item, index)} | ||
<StyledTransactionListItem key={index} item={item} /> | ||
</> | ||
); | ||
}, | ||
[renderListItemSeparator], | ||
); | ||
|
||
return ( | ||
<StyledFlatList | ||
refreshControl={ | ||
<RefreshControl | ||
refreshing={isLoading || false} | ||
onRefresh={onRefresh} | ||
colors={[theme.colors.primary]} | ||
/> | ||
} | ||
data={transactions} | ||
renderItem={renderItem} | ||
keyExtractor={(item) => item.id} | ||
ListHeaderComponent={renderHeaderComponent} | ||
/> | ||
); | ||
}; | ||
|
||
export default React.memo(TransactionList); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { FlatList, FlatListProps } from 'react-native'; | ||
import styled from 'styled-components/native'; | ||
import FlexContainer from '../../../components/FlexContainer'; | ||
import TransactionListItem from '../../../components/TransactionListItem'; | ||
import { Transaction } from '../../../services/pluggy'; | ||
|
||
export const StyledFlatList = styled( | ||
FlatList as new (props: FlatListProps<Transaction>) => FlatList<Transaction>, | ||
).attrs(() => ({ | ||
contentContainerStyle: { | ||
padding: 24, | ||
}, | ||
}))` | ||
flex: 1; | ||
background-color: ${({ theme }) => theme.colors.backgroundWhite}; | ||
`; | ||
|
||
export const ListHeaderContainer = styled(FlexContainer).attrs({ gap: 4 })` | ||
margin-bottom: 12px; | ||
`; | ||
|
||
export const ListSeparatorContainer = styled.View` | ||
flex-direction: row; | ||
align-items: center; | ||
margin: 12px 0; | ||
`; | ||
|
||
export const ListSeparatorDate = styled.View` | ||
align-items: center; | ||
margin-right: 12px; | ||
`; | ||
|
||
export const StyledTransactionListItem = styled(TransactionListItem)` | ||
padding: 12px 0; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, { useState } from 'react'; | ||
import { TabBar, TabBarProps, TabView } from 'react-native-tab-view'; | ||
import { useTheme } from 'styled-components/native'; | ||
import Text from '../../../components/Text'; | ||
import { TabLazyPlaceholder } from './styles'; | ||
|
||
type TransactionTabsRouteKey = 'default' | 'incomes' | 'expenses'; | ||
|
||
export type TransactionTabsRoute = { | ||
key: TransactionTabsRouteKey; | ||
title: string; | ||
}; | ||
|
||
export interface TransactionTabsProps { | ||
renderScene: (props: { route: TransactionTabsRoute }) => React.ReactNode; | ||
} | ||
|
||
const TransactionTabs: React.FC<TransactionTabsProps> = ({ renderScene }) => { | ||
const theme = useTheme(); | ||
|
||
const [index, setIndex] = useState(0); | ||
|
||
const routes: TransactionTabsRoute[] = [ | ||
{ key: 'default', title: 'Tudo' }, | ||
{ key: 'incomes', title: 'Entradas' }, | ||
{ key: 'expenses', title: 'Saídas' }, | ||
]; | ||
|
||
const renderTabBar = (props: TabBarProps<TransactionTabsRoute>) => ( | ||
<TabBar | ||
{...props} | ||
pressColor={theme.colors.primary} | ||
style={{ backgroundColor: theme.colors.primary }} | ||
indicatorStyle={{ backgroundColor: theme.colors.secondary, height: 3 }} | ||
renderLabel={({ route, color }) => ( | ||
<Text variant="default-bold" style={{ color }}> | ||
{route.title} | ||
</Text> | ||
)} | ||
/> | ||
); | ||
|
||
return ( | ||
<TabView | ||
navigationState={{ index, routes }} | ||
renderScene={renderScene} | ||
onIndexChange={setIndex} | ||
renderTabBar={renderTabBar} | ||
lazy={({ route }) => route.key !== 'default'} | ||
renderLazyPlaceholder={() => <TabLazyPlaceholder />} | ||
/> | ||
); | ||
}; | ||
|
||
export default TransactionTabs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import styled from 'styled-components/native'; | ||
|
||
export const TabLazyPlaceholder = styled.View` | ||
flex: 1; | ||
background-color: ${({ theme }) => theme.colors.backgroundWhite}; | ||
`; |
Oops, something went wrong.