Skip to content

Commit 0bee93e

Browse files
committed
Update +page.svelte
1 parent 431a5fd commit 0bee93e

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

frontend/src/routes/+page.svelte

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
} from "../../wailsjs/go/main/App";
2727
2828
interface Transaction {
29-
id: number;
29+
id?: number;
3030
type: "expense" | "revenue";
3131
desc: string;
3232
cat: string;
@@ -131,10 +131,10 @@
131131
let totalExp = $derived(expenses.reduce((s, r) => s + r.val, 0));
132132
let totalRev = $derived(revenues.reduce((s, r) => s + r.val, 0));
133133
let balance = $derived(totalRev - totalExp);
134-
let last4 = $derived([...records].sort((a, b) => b.id - a.id).slice(0, 4));
134+
let last4 = $derived([...records].sort((a, b) => (b.id ?? 0) - (a.id ?? 0)).slice(0, 4));
135135
let ledgerSorted = $derived(
136136
[...filtered].sort(
137-
(a, b) => b.date.localeCompare(a.date) || b.id - a.id,
137+
(a, b) => b.date.localeCompare(a.date) || (b.id ?? 0) - (a.id ?? 0),
138138
),
139139
);
140140
@@ -430,7 +430,7 @@
430430
// ── Backend calls ─────────────────────────────────────────
431431
async function loadRecords() {
432432
try {
433-
records = await GetTransactions(dateFrom, dateTo);
433+
records = (await GetTransactions(dateFrom, dateTo)) as Transaction[];
434434
} catch (e) {
435435
console.error("get_transactions failed:", e);
436436
}
@@ -474,10 +474,10 @@
474474
const date = isExp ? eDate : rDate;
475475
const account_id = isExp
476476
? eAccountId === ""
477-
? null
477+
? undefined
478478
: eAccountId
479479
: rAccountId === ""
480-
? null
480+
? undefined
481481
: rAccountId;
482482
if (!desc || isNaN(val) || val <= 0 || !date || !cat) return;
483483
@@ -510,7 +510,7 @@
510510
const desc = eDesc.trim();
511511
const cat = eCat.trim();
512512
const n = parseInt(eInstallN);
513-
const account_id = eAccountId === "" ? null : eAccountId;
513+
const account_id = eAccountId === "" ? undefined : eAccountId;
514514
if (
515515
!desc ||
516516
isNaN(val) ||
@@ -565,7 +565,7 @@
565565
}
566566
567567
function startEdit(r: Transaction) {
568-
editingId = r.id;
568+
editingId = r.id ?? null;
569569
editType = r.type;
570570
editVal = String(r.val);
571571
editDesc = r.desc;
@@ -597,7 +597,7 @@
597597
cat: editCat.trim(),
598598
val,
599599
date: editDate,
600-
account_id: editAccountId === "" ? null : editAccountId,
600+
account_id: editAccountId === "" ? undefined : editAccountId,
601601
});
602602
editingId = null;
603603
await loadRecords();
@@ -975,9 +975,7 @@
975975
bind:value={eCat}
976976
/>
977977
<datalist id="exp-cats-list">
978-
{#each expCategories as c}<option
979-
value={c}
980-
/>{/each}
978+
{#each expCategories as c}<option value={c}></option>{/each}
981979
</datalist>
982980
</div>
983981
<input class="ii t" type="date" bind:value={eDate} />
@@ -1043,9 +1041,7 @@
10431041
bind:value={rCat}
10441042
/>
10451043
<datalist id="rev-cats-list">
1046-
{#each revCategories as c}<option
1047-
value={c}
1048-
/>{/each}
1044+
{#each revCategories as c}<option value={c}></option>{/each}
10491045
</datalist>
10501046
</div>
10511047
<input class="ii t" type="date" bind:value={rDate} />
@@ -1964,15 +1960,6 @@
19641960
.var-val.dn {
19651961
color: var(--red);
19661962
}
1967-
.var-title {
1968-
font-family: "Caveat Brush", cursive;
1969-
font-size: 13px;
1970-
letter-spacing: 0.12em;
1971-
text-transform: uppercase;
1972-
color: var(--ink-faint);
1973-
margin-bottom: 10px;
1974-
}
1975-
19761963
/* ── DOUBLE RULE ── */
19771964
.drule {
19781965
border: none;

0 commit comments

Comments
 (0)