-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] ♻️ (typescript) convert TransactionListWithBalances.jsx to .tsx #3876
Changes from all commits
4503e61
e1ec317
9e79753
7deeae3
328ae64
03cd67c
e7bcb1e
0451d1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ import { Button } from '../../common/Button2'; | |
import { Text } from '../../common/Text'; | ||
import { View } from '../../common/View'; | ||
import { MobilePageHeader, Page } from '../../Page'; | ||
import { type SheetFields, type SheetNames } from '../../spreadsheet/index'; | ||
import { MobileBackButton } from '../MobileBackButton'; | ||
import { AddTransactionButton } from '../transactions/AddTransactionButton'; | ||
import { TransactionListWithBalances } from '../transactions/TransactionListWithBalances'; | ||
|
@@ -247,9 +248,9 @@ function TransactionListWithPreviews({ | |
const dispatch = useDispatch(); | ||
const navigate = useNavigate(); | ||
|
||
const onRefresh = useCallback(() => { | ||
const onRefresh = useCallback(async () => { | ||
if (accountId) { | ||
dispatch(syncAndDownload(accountId)); | ||
await dispatch(syncAndDownload(accountId)); | ||
} | ||
}, [accountId, dispatch]); | ||
|
||
|
@@ -314,16 +315,20 @@ function TransactionListWithPreviews({ | |
); | ||
|
||
const transactionsToDisplay = !isSearching | ||
? previewTransactions.concat(transactions) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original code was resulting in a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is intentional. We should instead update |
||
: transactions; | ||
? [...previewTransactions, ...transactions] | ||
: [...transactions]; | ||
|
||
return ( | ||
<TransactionListWithBalances | ||
isLoading={isLoading} | ||
transactions={transactionsToDisplay} | ||
balance={balanceQueries.balance} | ||
balanceCleared={balanceQueries.cleared} | ||
balanceUncleared={balanceQueries.uncleared} | ||
balance={balanceQueries.balance.name as SheetFields<SheetNames>} | ||
balanceCleared={ | ||
(balanceQueries.cleared?.name as SheetFields<SheetNames>) ?? undefined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will change the behavior. This is ignoring the |
||
} | ||
balanceUncleared={ | ||
(balanceQueries.uncleared?.name as SheetFields<SheetNames>) ?? undefined | ||
} | ||
onLoadMore={loadMoreTransactions} | ||
searchPlaceholder={`Search ${accountName}`} | ||
onSearch={onSearch} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,20 +2,29 @@ import React, { useState } from 'react'; | |||||
|
||||||
import { t } from 'i18next'; | ||||||
|
||||||
import { type TransactionEntity } from 'loot-core/types/models'; | ||||||
|
||||||
import { SelectedProvider, useSelected } from '../../../hooks/useSelected'; | ||||||
import { SvgSearchAlternate } from '../../../icons/v2'; | ||||||
import { styles, theme } from '../../../style'; | ||||||
import { InputWithContent } from '../../common/InputWithContent'; | ||||||
import { Label } from '../../common/Label'; | ||||||
import { View } from '../../common/View'; | ||||||
import { CellValue, CellValueText } from '../../spreadsheet/CellValue'; | ||||||
import { type SheetFields, type SheetNames } from '../../spreadsheet/index'; | ||||||
import { useSheetValue } from '../../spreadsheet/useSheetValue'; | ||||||
import { PullToRefresh } from '../PullToRefresh'; | ||||||
|
||||||
import { TransactionList } from './TransactionList'; | ||||||
|
||||||
function TransactionSearchInput({ placeholder, onSearch }) { | ||||||
const [text, setText] = useState(''); | ||||||
function TransactionSearchInput({ | ||||||
placeholder, | ||||||
onSearch, | ||||||
}: { | ||||||
placeholder: string; | ||||||
onSearch: (searchText: string) => void; | ||||||
}) { | ||||||
const [text, setText] = useState<string>(''); | ||||||
|
||||||
return ( | ||||||
<View | ||||||
|
@@ -57,6 +66,19 @@ function TransactionSearchInput({ placeholder, onSearch }) { | |||||
); | ||||||
} | ||||||
|
||||||
type TransactionListWithBalancesProps = { | ||||||
isLoading: boolean | undefined; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
transactions: TransactionEntity[]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
balance: SheetFields<SheetNames>; | ||||||
balanceCleared: SheetFields<SheetNames> | undefined; | ||||||
balanceUncleared: SheetFields<SheetNames> | undefined; | ||||||
searchPlaceholder: string; | ||||||
onSearch: (searchText: string) => void; | ||||||
onLoadMore: (() => void) | undefined; | ||||||
onOpenTransaction: (transaction: TransactionEntity) => void; | ||||||
onRefresh: () => Promise<void>; | ||||||
}; | ||||||
|
||||||
export function TransactionListWithBalances({ | ||||||
isLoading, | ||||||
transactions, | ||||||
|
@@ -68,51 +90,61 @@ export function TransactionListWithBalances({ | |||||
onLoadMore, | ||||||
onOpenTransaction, | ||||||
onRefresh, | ||||||
}) { | ||||||
const selectedInst = useSelected('transactions', transactions); | ||||||
}: TransactionListWithBalancesProps) { | ||||||
const selectedInst = useSelected('transactions', transactions, []); | ||||||
|
||||||
return ( | ||||||
<SelectedProvider instance={selectedInst}> | ||||||
<View | ||||||
style={{ | ||||||
flexShrink: 0, | ||||||
marginTop: 10, | ||||||
}} | ||||||
> | ||||||
<> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only change here is I wrapped the two children in a |
||||||
<View | ||||||
style={{ | ||||||
flexDirection: 'row', | ||||||
justifyContent: 'space-evenly', | ||||||
flexShrink: 0, | ||||||
marginTop: 10, | ||||||
}} | ||||||
> | ||||||
{balanceCleared && balanceUncleared ? ( | ||||||
<BalanceWithCleared | ||||||
balance={balance} | ||||||
balanceCleared={balanceCleared} | ||||||
balanceUncleared={balanceUncleared} | ||||||
/> | ||||||
) : ( | ||||||
<Balance balance={balance} /> | ||||||
)} | ||||||
<View | ||||||
style={{ | ||||||
flexDirection: 'row', | ||||||
justifyContent: 'space-evenly', | ||||||
}} | ||||||
> | ||||||
{balanceCleared && balanceUncleared ? ( | ||||||
<BalanceWithCleared | ||||||
balance={balance} | ||||||
balanceCleared={balanceCleared} | ||||||
balanceUncleared={balanceUncleared} | ||||||
/> | ||||||
) : ( | ||||||
<Balance balance={balance} /> | ||||||
)} | ||||||
</View> | ||||||
<TransactionSearchInput | ||||||
placeholder={searchPlaceholder} | ||||||
onSearch={onSearch} | ||||||
/> | ||||||
</View> | ||||||
<TransactionSearchInput | ||||||
placeholder={searchPlaceholder} | ||||||
onSearch={onSearch} | ||||||
/> | ||||||
</View> | ||||||
<PullToRefresh isPullable={!!onRefresh} onRefresh={onRefresh}> | ||||||
<TransactionList | ||||||
isLoading={isLoading} | ||||||
transactions={transactions} | ||||||
onLoadMore={onLoadMore} | ||||||
onOpenTransaction={onOpenTransaction} | ||||||
/> | ||||||
</PullToRefresh> | ||||||
<PullToRefresh isPullable={!!onRefresh} onRefresh={onRefresh}> | ||||||
<TransactionList | ||||||
isLoading={isLoading} | ||||||
transactions={transactions} | ||||||
onLoadMore={onLoadMore} | ||||||
onOpenTransaction={onOpenTransaction} | ||||||
/> | ||||||
</PullToRefresh> | ||||||
</> | ||||||
</SelectedProvider> | ||||||
); | ||||||
} | ||||||
|
||||||
function BalanceWithCleared({ balanceUncleared, balanceCleared, balance }) { | ||||||
function BalanceWithCleared({ | ||||||
balanceUncleared, | ||||||
balanceCleared, | ||||||
balance, | ||||||
}: { | ||||||
balanceUncleared: SheetFields<SheetNames>; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make a |
||||||
balanceCleared: SheetFields<SheetNames>; | ||||||
balance: SheetFields<SheetNames>; | ||||||
}) { | ||||||
const unclearedAmount = useSheetValue(balanceUncleared); | ||||||
|
||||||
return ( | ||||||
|
@@ -170,7 +202,7 @@ function BalanceWithCleared({ balanceUncleared, balanceCleared, balance }) { | |||||
); | ||||||
} | ||||||
|
||||||
function Balance({ balance }) { | ||||||
function Balance({ balance }: { balance: SheetFields<SheetNames> }) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make a |
||||||
return ( | ||||||
<View style={{ flexBasis: '33%' }}> | ||||||
<Label title={t('Balance')} style={{ textAlign: 'center' }} /> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
category: Maintenance | ||
authors: [cindywu] | ||
--- | ||
|
||
Convert TransactionListWithBalances.jsx to .tsx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to be async?