1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 05:09:38 +02:00
Maybe/app/models/account/sync_complete_event.rb
Zach Gollwitzer 10ce2c8e23
Some checks are pending
Publish Docker image / ci (push) Waiting to run
Publish Docker image / Build docker image (push) Blocked by required conditions
Balance sheet cache layer, non-blocking sync UI (#2356)
* Balance sheet cache layer with cache-busting

* Update family cache timestamps during Sync

* Less blocking sync loaders

* Consolidate family data caching key logic

* Fix turbo stream broadcasts

* Remove dev delay

* Add back account group sorting
2025-06-10 18:20:06 -04:00

63 lines
1.8 KiB
Ruby

class Account::SyncCompleteEvent
attr_reader :account
Error = Class.new(StandardError)
def initialize(account)
@account = account
end
def broadcast
# Replace account row in accounts list
account.broadcast_replace_to(
account.family,
target: "account_#{account.id}",
partial: "accounts/account",
locals: { account: account }
)
# Replace the groups this account belongs to in both desktop and mobile sidebars
sidebar_targets.each do |(tab, mobile_flag)|
account.broadcast_replace_to(
account.family,
target: account_group.dom_id(tab: tab, mobile: mobile_flag),
partial: "accounts/accountable_group",
locals: { account_group: account_group, open: true, all_tab: tab == :all, mobile: mobile_flag }
)
end
# If this is a manual, unlinked account (i.e. not part of a Plaid Item),
# trigger the family sync complete broadcast so net worth graph is updated
unless account.linked?
account.family.broadcast_sync_complete
end
# Refresh entire account page (only applies if currently viewing this account)
account.broadcast_refresh
end
private
# Returns an array of [tab, mobile?] tuples that should receive an update.
# We broadcast to both the classification-specific tab and the "all" tab,
# for desktop (mobile: false) and mobile (mobile: true) variants.
def sidebar_targets
return [] unless account_group.present?
[
[ account_group.classification.to_sym, false ],
[ :all, false ],
[ account_group.classification.to_sym, true ],
[ :all, true ]
]
end
def account_group
family_balance_sheet.account_groups.find do |group|
group.accounts.any? { |a| a.id == account.id }
end
end
def family_balance_sheet
account.family.balance_sheet
end
end