| 1 |
<script lang="ts"> |
| 2 |
import type { Event } from "../../entries"; |
| 3 |
import { _ } from "../../i18n"; |
| 4 |
import { DateColumn, Sorter, StringColumn } from "../../sort"; |
| 5 |
import SortHeader from "../../sort/SortHeader.svelte"; |
| 6 |
|
| 7 |
interface Props { |
| 8 |
events: Event[]; |
| 9 |
} |
| 10 |
|
| 11 |
let { events }: Props = $props(); |
| 12 |
|
| 13 |
const columns = [ |
| 14 |
new DateColumn<Event>(_("Date")), |
| 15 |
new StringColumn<Event>(_("Description"), (d) => d.description), |
| 16 |
] as const; |
| 17 |
let sorter = $state(new Sorter(columns[0], "desc")); |
| 18 |
|
| 19 |
let sorted_events = $derived(sorter.sort(events)); |
| 20 |
</script> |
| 21 |
|
| 22 |
<table> |
| 23 |
<thead> |
| 24 |
<tr> |
| 25 |
{#each columns as column} |
| 26 |
<SortHeader bind:sorter {column} /> |
| 27 |
{/each} |
| 28 |
</tr> |
| 29 |
</thead> |
| 30 |
<tbody> |
| 31 |
{#each sorted_events as event} |
| 32 |
<tr> |
| 33 |
<td>{event.date}</td> |
| 34 |
<td>{event.description}</td> |
| 35 |
</tr> |
| 36 |
{/each} |
| 37 |
</tbody> |
| 38 |
</table> |