From 66e5ef64fd5c5dab3503fb7bd6edae6a834af5a7 Mon Sep 17 00:00:00 2001 From: Sli Date: Tue, 17 Dec 2024 00:45:51 +0100 Subject: [PATCH] Don't use API to update amount after a refilling query --- .../bundled/counter/counter-click-index.ts | 21 +++++++------------ counter/templates/counter/counter_click.jinja | 2 +- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/counter/static/bundled/counter/counter-click-index.ts b/counter/static/bundled/counter/counter-click-index.ts index 044d14de..b8de64be 100644 --- a/counter/static/bundled/counter/counter-click-index.ts +++ b/counter/static/bundled/counter/counter-click-index.ts @@ -1,5 +1,4 @@ import { exportToHtml } from "#core:utils/globals"; -import { customerGetCustomer } from "#openapi"; interface CounterConfig { csrfToken: string; @@ -33,19 +32,13 @@ exportToHtml("loadCounter", (config: CounterConfig) => { return total / 100; }, - async updateBalance() { - this.customerBalance = ( - await customerGetCustomer({ - path: { - // biome-ignore lint/style/useNamingConvention: api is in snake_case - customer_id: config.customerId, - }, - }) - ).data.amount; - }, - - async onRefillingSuccess() { - await this.updateBalance(); + onRefillingSuccess(event: CustomEvent) { + if (event.type !== "htmx:after-request" || event.detail.failed) { + return; + } + this.customerBalance += Number.parseFloat( + (event.detail.target.querySelector("#id_amount") as HTMLInputElement).value, + ); document.getElementById("selling-accordion").click(); }, diff --git a/counter/templates/counter/counter_click.jinja b/counter/templates/counter/counter_click.jinja index f9821bf1..cb62be31 100644 --- a/counter/templates/counter/counter_click.jinja +++ b/counter/templates/counter/counter_click.jinja @@ -103,7 +103,7 @@ {% if refilling_fragment %}
{% trans %}Refilling{% endtrans %}
{{ refilling_fragment }}