Skip to content

Commit d362ab7

Browse files
committed
transaction: only get payee suggestions once
Also refactor posting list to use Svelte #each directly. The reactivity bug that forced us to implement this differently seems to be gone.
1 parent c0bd34f commit d362ab7

3 files changed

Lines changed: 31 additions & 31 deletions

File tree

frontend/src/entry-forms/Posting.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
}: Props = $props();
3333
3434
let amount_number = $derived(posting.amount.replace(/[^\-?0-9.]/g, ""));
35-
let amountSuggestions = $derived(
35+
let amount_suggestions = $derived(
3636
$currencies.map((c) => `${amount_number} ${c}`),
3737
);
3838
@@ -98,7 +98,7 @@
9898
/>
9999
<AutocompleteInput
100100
placeholder={_("Amount")}
101-
suggestions={amountSuggestions}
101+
suggestions={amount_suggestions}
102102
bind:value={
103103
() => posting.amount,
104104
(amount: string) => {

frontend/src/entry-forms/Transaction.svelte

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
let payee = $derived(entry.payee);
2828
let narration = $derived(entry.get_narration_tags_links());
2929
30+
let payee_accounts = $derived(
31+
$payees.includes(payee)
32+
? fetch_payee_accounts($ledger_mtime, payee)
33+
: undefined,
34+
);
35+
3036
// Autofill complete transactions.
3137
async function autocomplete_select_payee() {
3238
if (entry.narration || entry.postings.some((p) => !p.is_empty())) {
@@ -119,31 +125,25 @@
119125
<div class="flex-row hide-on-desktop">
120126
<span class="label">{_("Postings")}:</span>
121127
</div>
122-
{#each entry.postings, index}
123-
<!-- Using the indexed access (instead of `as posting` in the each) seems to track
124-
the reactivity differently and avoids cursor jumping on the posting inputs. -->
125-
{@const posting = entry.postings[index]}
126-
{#if posting != null}
127-
<PostingSvelte
128-
bind:posting={
129-
() => posting,
130-
(posting: Posting) => {
131-
entry = entry.set("postings", entry.postings.with(index, posting));
132-
}
128+
<!-- eslint-disable-next-line svelte/require-each-key -->
129+
{#each entry.postings as posting, index}
130+
<PostingSvelte
131+
bind:posting={
132+
() => posting,
133+
(posting: Posting) => {
134+
entry = entry.set("postings", entry.postings.with(index, posting));
133135
}
134-
{index}
135-
suggestions={$payees.includes(payee)
136-
? fetch_payee_accounts($ledger_mtime, payee).data
137-
: undefined}
138-
date={entry.date}
139-
move={({ from, to }: { from: number; to: number }) => {
140-
entry = entry.set("postings", move(entry.postings, from, to));
141-
}}
142-
remove={() => {
143-
entry = entry.set("postings", entry.postings.toSpliced(index, 1));
144-
}}
145-
/>
146-
{/if}
136+
}
137+
{index}
138+
suggestions={payee_accounts?.data}
139+
date={entry.date}
140+
move={({ from, to }: { from: number; to: number }) => {
141+
entry = entry.set("postings", move(entry.postings, from, to));
142+
}}
143+
remove={() => {
144+
entry = entry.set("postings", entry.postings.toSpliced(index, 1));
145+
}}
146+
/>
147147
{/each}
148148

149149
<style>

src/fava/translations/messages.pot

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,19 @@ msgstr ""
123123
msgid "Amount"
124124
msgstr ""
125125

126-
#: frontend/src/entry-forms/Transaction.svelte:77
127-
#: frontend/src/entry-forms/Transaction.svelte:79
126+
#: frontend/src/entry-forms/Transaction.svelte:83
127+
#: frontend/src/entry-forms/Transaction.svelte:85
128128
#: frontend/src/reports/journal/JournalHeaders.svelte:51
129129
msgid "Payee"
130130
msgstr ""
131131

132-
#: frontend/src/entry-forms/Transaction.svelte:90
133-
#: frontend/src/entry-forms/Transaction.svelte:92
132+
#: frontend/src/entry-forms/Transaction.svelte:96
133+
#: frontend/src/entry-forms/Transaction.svelte:98
134134
#: frontend/src/reports/journal/JournalHeaders.svelte:51
135135
msgid "Narration"
136136
msgstr ""
137137

138-
#: frontend/src/entry-forms/Transaction.svelte:120
138+
#: frontend/src/entry-forms/Transaction.svelte:126
139139
#: frontend/src/reports/journal/JournalFilters.svelte:44
140140
msgid "Postings"
141141
msgstr ""

0 commit comments

Comments
 (0)