Load real scheduled transactions.

This commit is contained in:
2026-10-25 15:34:34 +01:00
parent 0d1b7d1338
commit 455096fa37
7 changed files with 72 additions and 57 deletions
@@ -0,0 +1,8 @@
import type { PageServerLoad } from './$types';
import { listScheduledTransactions } from '#lib/data/scheduled-transactions.ts';
export const load: PageServerLoad = async ({ fetch }) => {
return {
scheduledTransactions: listScheduledTransactions(fetch)
};
};
@@ -1,74 +1,35 @@
<script lang="ts" module>
type ScheduledTransaction = {
checked: boolean;
id: number;
name: string;
description: string;
account: string;
amount: number;
};
import type { ScheduledTransaction } from '#lib/models/scheduled-transaction.ts';
import { renderAmount } from '#lib/render/amount.ts';
const columns: Column<ScheduledTransaction>[] = [
{ key: 'checked' },
{ key: 'id', label: '#' },
{ key: 'name', label: 'Name', ratio: 1 },
{ key: 'account', label: 'Account' },
{ key: 'amount', label: 'Amount' }
{ key: 'amount_cents', label: 'Amount' }
];
</script>
<script lang="ts">
import Checkbox from '#lib/components/checkbox.svelte';
import Table, { type Column } from '#lib/components/table.svelte';
import type { PageProps } from './$types';
const data: ScheduledTransaction[] = $state([
{
checked: true,
id: 1,
name: 'Some transaction',
description: 'Some description',
account: 'Some account',
amount: 100
},
{
checked: false,
id: 2,
name: 'Another transaction',
description: 'Another description',
account: 'Another account',
amount: 200
},
{
checked: false,
id: 3,
name: 'Yet another transaction',
description: 'Yet another description, but longer than the others',
account: 'Yet another account',
amount: 300
}
]);
let { data }: PageProps = $props();
</script>
<svelte:head>
<title>Scheduled transactions | Expenses</title>
</svelte:head>
<Table {columns} {data} style={({ row }) => (row?.checked ? ['highlight'] : [])}>
{#snippet header({ key, label })}
{#if key === 'checked'}
<Checkbox
onchange={(e) => data.forEach((row) => (row.checked = e.currentTarget.checked))}
checked={data.every((row) => row.checked)}
/>
{:else}
{label}
{/if}
{/snippet}
{#snippet cell({ key, value, row })}
{#if key === 'checked'}
<Checkbox bind:checked={row.checked} />
{:else}
{value}
{/if}
{/snippet}
</Table>
{#await data.scheduledTransactions then scheduledTransactions}
<Table {columns} data={scheduledTransactions}>
{#snippet cell({ key, value, row })}
{#if key === 'account'}
{value.name}
{:else if key === 'amount_cents'}
{renderAmount(value, row.direction)}
{:else}
{value}
{/if}
{/snippet}
</Table>
{/await}