Skip to content

Commit

Permalink
Publish refresh to overview page when a BankTransaction gets modified
Browse files Browse the repository at this point in the history
  • Loading branch information
murdho committed Mar 25, 2024
1 parent a139ac0 commit dc47893
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/bank_transaction.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/models/bank_transaction/categorizable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions app/views/overview/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%= turbo_stream_from :overview %>

<div class="min-w-full">
<div class="flex justify-between items-center">
<h1 class="font-bold text-4xl">Overview</h1>
Expand Down

0 comments on commit dc47893

Please sign in to comment.