Display accounts balances
This commit is contained in:
5
moneymgr_web/src/widgets/AmountWidget.tsx
Normal file
5
moneymgr_web/src/widgets/AmountWidget.tsx
Normal file
@ -0,0 +1,5 @@
|
||||
export function AmountWidget(p: { amount: number }): React.ReactElement {
|
||||
return (
|
||||
<span style={{ color: p.amount < 0 ? "red" : "green" }}>{p.amount} €</span>
|
||||
);
|
||||
}
|
@ -13,6 +13,7 @@ import { useLocation } from "react-router-dom";
|
||||
import { useAccounts } from "../hooks/AccountsListProvider";
|
||||
import { AccountWidget } from "./AccountWidget";
|
||||
import { RouterLink } from "./RouterLink";
|
||||
import { AmountWidget } from "./AmountWidget";
|
||||
|
||||
export function MoneyNavList(): React.ReactElement {
|
||||
const accounts = useAccounts();
|
||||
@ -61,6 +62,7 @@ export function MoneyNavList(): React.ReactElement {
|
||||
<NavLink
|
||||
key={a.id}
|
||||
label={a.name}
|
||||
secondaryLabel={<AmountWidget amount={a.balance} />}
|
||||
uri={`/account/${a.id}`}
|
||||
icon={<AccountWidget account={a} />}
|
||||
/>
|
||||
@ -72,14 +74,15 @@ export function MoneyNavList(): React.ReactElement {
|
||||
function NavLink(p: {
|
||||
icon: React.ReactElement;
|
||||
uri: string;
|
||||
label: string;
|
||||
label: string | React.ReactElement;
|
||||
secondaryLabel?: string | React.ReactElement;
|
||||
}): React.ReactElement {
|
||||
const location = useLocation();
|
||||
return (
|
||||
<RouterLink to={p.uri}>
|
||||
<ListItemButton selected={p.uri === location.pathname}>
|
||||
<ListItemIcon>{p.icon}</ListItemIcon>
|
||||
<ListItemText primary={p.label} />
|
||||
<ListItemText primary={p.label} secondary={p.secondaryLabel} />
|
||||
</ListItemButton>
|
||||
</RouterLink>
|
||||
);
|
||||
|
Reference in New Issue
Block a user