From dc478939b81c300116018ab1105e72b931f8147a Mon Sep 17 00:00:00 2001 From: Murdho Savila Date: Mon, 25 Mar 2024 19:19:32 +0200 Subject: [PATCH] Publish refresh to overview page when a BankTransaction gets modified --- app/models/bank_transaction.rb | 2 ++ app/models/bank_transaction/categorizable.rb | 4 ++++ app/views/overview/index.html.erb | 2 ++ 3 files changed, 8 insertions(+) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index c4d754d..0659aa5 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -1,6 +1,8 @@ class BankTransaction < ApplicationRecord include Categorizable, Monetizable + broadcasts_refreshes_to -> { :overview } + belongs_to :statement belongs_to :category, optional: true belongs_to :rule, optional: true diff --git a/app/models/bank_transaction/categorizable.rb b/app/models/bank_transaction/categorizable.rb index 8207726..032e743 100644 --- a/app/models/bank_transaction/categorizable.rb +++ b/app/models/bank_transaction/categorizable.rb @@ -15,6 +15,10 @@ def categorize_all updated_at = STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW') FROM (#{BankTransaction::MatchingCategories.with_category_id.to_sql}) AS matching_categories SQL + + # FIXME: this is a hacky way to broadcast refresh, should be replaced + # with something proper (or maybe get rid of the #update_all above?) + BankTransaction.last.broadcast_refresh_to :overview end end end diff --git a/app/views/overview/index.html.erb b/app/views/overview/index.html.erb index 4c61d46..94c43c2 100644 --- a/app/views/overview/index.html.erb +++ b/app/views/overview/index.html.erb @@ -1,3 +1,5 @@ +<%= turbo_stream_from :overview %> +

Overview