From 4faa037c20ca4c282d22d8e93bfa2b308b595d2a Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 21 Sep 2023 14:25:12 -0300 Subject: tx group by date --- .../src/components/Transactions/views.tsx | 59 ++++++++++++++-------- 1 file changed, 39 insertions(+), 20 deletions(-) (limited to 'packages/demobank-ui/src/components/Transactions/views.tsx') diff --git a/packages/demobank-ui/src/components/Transactions/views.tsx b/packages/demobank-ui/src/components/Transactions/views.tsx index 6303037a1..b11888320 100644 --- a/packages/demobank-ui/src/components/Transactions/views.tsx +++ b/packages/demobank-ui/src/components/Transactions/views.tsx @@ -14,10 +14,10 @@ GNU Taler; see the file COPYING. If not, see */ -import { h, VNode } from "preact"; +import { Fragment, h, VNode } from "preact"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { State } from "./index.js"; -import { format } from "date-fns"; +import { format, isToday } from "date-fns"; import { Amounts } from "@gnu-taler/taler-util"; export function LoadingUriView({ error }: State.LoadingUriError): VNode { @@ -32,6 +32,16 @@ export function LoadingUriView({ error }: State.LoadingUriError): VNode { export function ReadyView({ transactions }: State.Ready): VNode { const { i18n } = useTranslationContext(); + const txByDate = transactions.reduce((prev, cur) => { + const d = cur.when.t_ms === "never" + ? "" + : format(cur.when.t_ms, "dd/MM/yyyy") + if (!prev[d]) { + prev[d] = [] + } + prev[d].push(cur) + return prev + }, {} as Record) return (
@@ -50,25 +60,34 @@ export function ReadyView({ transactions }: State.Ready): VNode { - {transactions.map((item, idx) => { - return ( - - -
{item.when.t_ms === "never" - ? "" - : format(item.when.t_ms, "dd/MM/yyyy HH:mm:ss")}
- - {item.negative ? "-" : ""} - {item.amount ? ( - `${Amounts.stringifyValue(item.amount)} ${item.amount.currency - }` - ) : ( - <{i18n.str`invalid value`}> - )} - {item.counterpart} - {item.subject} + {Object.entries(txByDate).map(([date, txs], idx) => { + return + + + {date} + - ); + {txs.map(item => { + return ( + +
{item.when.t_ms === "never" + ? "" + : format(item.when.t_ms, "HH:mm:ss")}
+ + + {item.negative ? "-" : ""} + {item.amount ? ( + `${Amounts.stringifyValue(item.amount)} ${item.amount.currency + }` + ) : ( + <{i18n.str`invalid value`}> + )} + {item.counterpart} + {item.subject} + ) + })} +
})} -- cgit v1.2.3