diff --git a/web/src/pages/PrepareTransactionsPage/TransactionTable.module.css b/web/src/pages/PrepareTransactionsPage/TransactionTable.module.css deleted file mode 100644 index 7125128..0000000 --- a/web/src/pages/PrepareTransactionsPage/TransactionTable.module.css +++ /dev/null @@ -1,7 +0,0 @@ -.transactionTable tbody tr { - cursor: pointer; -} - -.disabled td { - color: var(--bulma-text-light); -} \ No newline at end of file diff --git a/web/src/pages/PrepareTransactionsPage/TransactionsTable.module.css b/web/src/pages/PrepareTransactionsPage/TransactionsTable.module.css new file mode 100644 index 0000000..5c4f66e --- /dev/null +++ b/web/src/pages/PrepareTransactionsPage/TransactionsTable.module.css @@ -0,0 +1,19 @@ +.transactionTable { + tbody tr { + cursor: pointer; + } + + td { + .date { + white-space: nowrap; + } + + .amount { + font-family: monospace; + } + } + + .disabled td { + color: var(--bulma-text-light); + } +} diff --git a/web/src/pages/PrepareTransactionsPage/TransactionsTable.tsx b/web/src/pages/PrepareTransactionsPage/TransactionsTable.tsx index 31cd02e..464f683 100644 --- a/web/src/pages/PrepareTransactionsPage/TransactionsTable.tsx +++ b/web/src/pages/PrepareTransactionsPage/TransactionsTable.tsx @@ -1,6 +1,6 @@ -import { useCallback } from "react"; +import { useCallback, useMemo } from "react"; import type { Transaction } from "../../types/api"; -import styles from "./TransactionTable.module.css"; +import styles from "./TransactionsTable.module.css"; export type TransactionsTableProps = { transactions: Transaction[]; @@ -10,6 +10,22 @@ export type TransactionsTableProps = { readonly?: boolean; } +const transactionEmoji = (transaction: Transaction): string => { + if (transaction.kind === 'transfer') { + return '➡️' + }; + + return transaction.amount > 0 ? '⬇️' : '⬆️'; +}; + +const transactionType = (transaction: Transaction): string => { + if (transaction.kind === 'transfer') { + return 'Transfer' + }; + + return transaction.amount > 0 ? 'Inflow' : 'Outflow'; +}; + export default function TransactionsTable({ transactions, deselected, deselect, select, readonly }: TransactionsTableProps) { const changeSelection = useCallback((index: number) => { @@ -26,16 +42,16 @@ export default function TransactionsTable({ transactions, deselected, deselect, } }, [deselected, deselect, select]); + const reversedTransactions = useMemo(() => transactions.slice().reverse(), [transactions]); const renderRow = useCallback((transaction: Transaction, index: number) => ( changeSelection(index)} className={`${!readonly && deselected.includes(index) ? styles.disabled : ""}`}> - {transaction.kind} - {transaction.date} + {transactionEmoji(transaction)} + {transaction.date} + {transaction.amount} + {transaction.id ? {transaction.title} : transaction.title} {transaction.from} - {transaction.to} - {transaction.amount} - {transaction.title} - {transaction.id} + {transaction.to} ), [changeSelection]); @@ -43,19 +59,17 @@ export default function TransactionsTable({ transactions, deselected, deselect,
- - - + + - - - - + + + - {transactions.map(renderRow)} + {reversedTransactions.map(renderRow)}
Kind
DateFromTo AmountTitleIDTitleFromTo