Debian Codegraph @

frontend/src/reports/commodities/CommodityTable.svelte

raw
1 <script lang="ts">
2 import { day } from "../../format";
3 import { _ } from "../../i18n";
4 import { NumberColumn, Sorter } from "../../sort";
5 import SortHeader from "../../sort/SortHeader.svelte";
6 import { ctx } from "../../stores/format";
7
8 type T = [Date, number];
9 interface Props {
10 prices: readonly T[];
11 quote: string;
12 }
13
14 let { prices, quote }: Props = $props();
15
16 const columns = [
17 new NumberColumn<T>(_("Date"), (d) => d[0].valueOf()),
18 new NumberColumn<T>(_("Price"), (d) => d[1]),
19 ] as const;
20 let sorter = $state(new Sorter(columns[0], "desc"));
21
22 let sorted_prices = $derived(sorter.sort(prices));
23 </script>
24
25 <table>
26 <thead>
27 <tr>
28 {#each columns as column}
29 <SortHeader bind:sorter {column} />
30 {/each}
31 </tr>
32 </thead>
33 <tbody>
34 {#each sorted_prices as [date, value] (date)}
35 <tr>
36 <td>{day(date)}</td>
37 <td class="num">{$ctx.amount(value, quote)}</td>
38 </tr>
39 {/each}
40 </tbody>
41 </table>