Don't refresh page when transaction details are edited #1479

Merged
zachgoll merged 2 commits from 1415-bug-editing-any-part-of-a-date-causes-a-page-reload-before-another-edit-can-be-done into main 2024-11-21 00:01:52 +08:00
4 changed files with 21 additions and 14 deletions

View File

@@ -22,6 +22,10 @@ module Syncable
raise NotImplementedError, "Subclasses must implement the `sync_data` method"
end
def post_sync
# no-op, syncable can optionally provide implementation
end
def sync_error
latest_sync.error
end

View File

@@ -32,6 +32,10 @@ class Family < ApplicationRecord
end
end
def post_sync
broadcast_refresh
end
def syncing?
super || accounts.manual.any?(&:syncing?) || plaid_items.any?(&:syncing?)
end

View File

@@ -42,6 +42,10 @@ class PlaidItem < ApplicationRecord
end
end
def post_sync
family.broadcast_refresh
end
def destroy_later
update!(scheduled_for_deletion: true)
DestroyJob.perform_later(self)

View File

@@ -8,32 +8,27 @@ class Sync < ApplicationRecord
def perform
start!
syncable.sync_data(start_date: start_date)
complete!
rescue StandardError => error
fail! error
raise error if Rails.env.development?
begin
syncable.sync_data(start_date: start_date)
complete!
rescue StandardError => error
fail! error
raise error if Rails.env.development?
ensure
syncable.post_sync
end
end
private
def family
syncable.is_a?(Family) ? syncable : syncable.family
end
def start!
update! status: :syncing
end
def complete!
update! status: :completed, last_ran_at: Time.current
family.broadcast_refresh
end
def fail!(error)
update! status: :failed, error: error.message, last_ran_at: Time.current
family.broadcast_refresh
end
end