From efea7bfc01cef9b88a85fc06683b1a8a032d83c1 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Mon, 12 May 2025 15:01:39 -0400 Subject: [PATCH] 30 day syncs by default --- app/models/concerns/syncable.rb | 2 +- app/models/sync.rb | 9 ++++++++- app/views/accounts/index.html.erb | 20 +++++++++++--------- app/views/accounts/show/_header.html.erb | 17 +++-------------- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/app/models/concerns/syncable.rb b/app/models/concerns/syncable.rb index 4214daa0..e33c1ac9 100644 --- a/app/models/concerns/syncable.rb +++ b/app/models/concerns/syncable.rb @@ -10,7 +10,7 @@ module Syncable end def sync_later(parent_sync: nil, window_start_date: nil, window_end_date: nil) - new_sync = syncs.create!(parent: parent_sync, window_start_date: window_start_date, window_end_date: window_end_date) + new_sync = syncs.create_with_defaults!(parent: parent_sync) SyncJob.perform_later(new_sync) end diff --git a/app/models/sync.rb b/app/models/sync.rb index f9648726..325b5730 100644 --- a/app/models/sync.rb +++ b/app/models/sync.rb @@ -31,7 +31,14 @@ class Sync < ApplicationRecord end end - def perform(window_start_date: nil, window_end_date: nil) + class << self + # By default, we sync the "visible" window of data (user sees 30 day graphs by default) + def create_with_defaults!(parent: nil) + create!(parent: parent, window_start_date: 30.days.ago.to_date) + end + end + + def perform start! begin diff --git a/app/views/accounts/index.html.erb b/app/views/accounts/index.html.erb index 4893e44c..5c99a4f2 100644 --- a/app/views/accounts/index.html.erb +++ b/app/views/accounts/index.html.erb @@ -2,15 +2,17 @@

<%= t(".accounts") %>

- <%= render ButtonComponent.new( - text: "Sync all", - href: sync_all_accounts_path, - method: :post, - variant: "outline", - disabled: Current.family.syncing?, - icon: "refresh-cw", - class: "" - ) %> + <% if Rails.env.development? %> + <%= render ButtonComponent.new( + text: "Sync all", + href: sync_all_accounts_path, + method: :post, + variant: "outline", + disabled: Current.family.syncing?, + icon: "refresh-cw", + class: "" + ) %> + <% end %> <%= render LinkComponent.new( text: "New account", diff --git a/app/views/accounts/show/_header.html.erb b/app/views/accounts/show/_header.html.erb index 4c60e832..b64408ce 100644 --- a/app/views/accounts/show/_header.html.erb +++ b/app/views/accounts/show/_header.html.erb @@ -20,26 +20,15 @@ <% end %>
- <% if account.plaid_account_id.present? %> - <% if Rails.env.development? %> - <%= icon( + <% if Rails.env.development? %> + <%= icon( "refresh-cw", as_button: true, size: "sm", - href: sync_plaid_item_path(account.plaid_account.plaid_item), + href: account.linked? ? sync_plaid_item_path(account.plaid_account.plaid_item) : sync_account_path(account), disabled: account.syncing?, frame: :_top ) %> - <% end %> - <% else %> - <%= icon( - "refresh-cw", - as_button: true, - size: "sm", - href: sync_account_path(account), - disabled: account.syncing?, - frame: :_top - ) %> <% end %> <%= render "accounts/show/menu", account: account %>