Refresh balance assertions list on update
This commit is contained in:
parent
83ca78436c
commit
02bac57b2b
@ -63,6 +63,7 @@
|
||||
<script setup lang="ts">
|
||||
import dayjs from 'dayjs';
|
||||
import { XCircleIcon } from '@heroicons/vue/24/solid';
|
||||
import { emit } from '@tauri-apps/api/event';
|
||||
import { getCurrentWindow } from '@tauri-apps/api/window';
|
||||
import { ref } from 'vue';
|
||||
|
||||
@ -102,11 +103,12 @@
|
||||
const session = await db.load();
|
||||
|
||||
if (assertion.id === null) {
|
||||
await session.execute(
|
||||
const result = await session.execute(
|
||||
`INSERT INTO balance_assertions (dt, description, account, quantity, commodity)
|
||||
VALUES ($1, $2, $3, $4, $5)`,
|
||||
[dayjs(assertion.dt).format(DT_FORMAT), assertion.description, assertion.account, quantity, amount_abs.commodity]
|
||||
);
|
||||
assertion.id = result.lastInsertId!;
|
||||
} else {
|
||||
await session.execute(
|
||||
`UPDATE balance_assertions
|
||||
@ -116,8 +118,7 @@
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Send event
|
||||
|
||||
await emit('balance-assertion-updated', {id: assertion.id});
|
||||
await getCurrentWindow().close();
|
||||
}
|
||||
|
||||
@ -135,8 +136,7 @@
|
||||
[assertion.id]
|
||||
);
|
||||
|
||||
// TODO: Send event
|
||||
|
||||
await emit('balance-assertion-updated', {id: assertion.id});
|
||||
await getCurrentWindow().close();
|
||||
}
|
||||
</script>
|
||||
|
@ -320,6 +320,7 @@
|
||||
|
||||
await dbTransaction.commit();
|
||||
|
||||
await emit('transaction-updated', {id: transaction.id});
|
||||
await getCurrentWindow().close();
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,8 @@
|
||||
import { CheckIcon, PencilIcon, XMarkIcon } from '@heroicons/vue/24/outline';
|
||||
import { PlusIcon } from '@heroicons/vue/16/solid';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { ref } from 'vue';
|
||||
import { UnlistenFn, listen } from '@tauri-apps/api/event';
|
||||
import { onUnmounted, ref } from 'vue';
|
||||
|
||||
import { db } from '../db.ts';
|
||||
import { pp } from '../display.ts';
|
||||
@ -97,4 +98,17 @@
|
||||
}
|
||||
|
||||
load();
|
||||
|
||||
// Refresh balance assertions list when assertion updated
|
||||
let unlistenAssertionUpdated: UnlistenFn | null = null;
|
||||
(async () => {
|
||||
// Cannot await at top level without <Suspense> therefore do this in an async function
|
||||
unlistenAssertionUpdated = await listen('balance-assertion-updated', async (_event) => { await load(); });
|
||||
})();
|
||||
|
||||
onUnmounted(() => {
|
||||
if (unlistenAssertionUpdated !== null) {
|
||||
unlistenAssertionUpdated();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user