1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00

Sync notifications and troubleshooting guides (#998)

* Add help articles

* Broadcast sync messages as notifications

* Lint fixes

* more lint fixes

* Remove redundant code
This commit is contained in:
Zach Gollwitzer 2024-07-18 14:39:38 -04:00 committed by GitHub
parent b200b71284
commit fa08f027c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 256 additions and 97 deletions

View file

@ -2,8 +2,6 @@ class Account < ApplicationRecord
include Syncable
include Monetizable
broadcasts_refreshes
validates :name, :balance, :currency, presence: true
belongs_to :family

View file

@ -48,13 +48,35 @@ class Account::Sync < ApplicationRecord
def start!
update! status: "syncing", last_ran_at: Time.now
broadcast_start
end
def complete!
update! status: "completed"
broadcast_result type: "notice", message: "Sync complete"
end
def fail!(error)
update! status: "failed", error: error.message
broadcast_result type: "alert", message: error.message
end
def broadcast_start
broadcast_append_to(
[ account.family, :notifications ],
target: "notification-tray",
partial: "shared/notification",
locals: { id: id, type: "processing", message: "Syncing account balances" }
)
end
def broadcast_result(type:, message:)
broadcast_remove_to account.family, :notifications, target: id # Remove persistent syncing notification
broadcast_append_to(
[ account.family, :notifications ],
target: "notification-tray",
partial: "shared/notification",
locals: { type: type, message: message }
)
end
end

View file

@ -1,5 +1,5 @@
class Current < ActiveSupport::CurrentAttributes
attribute :user
delegate :family, to: :user
delegate :family, to: :user, allow_nil: true
end

View file

@ -0,0 +1,54 @@
class Help::Article
attr_reader :frontmatter, :content
def initialize(frontmatter:, content:)
@frontmatter = frontmatter
@content = content
end
def title
frontmatter["title"]
end
def html
render_markdown(content)
end
class << self
def root_path
Rails.root.join("docs", "help")
end
def find(slug)
Dir.glob(File.join(root_path, "*.md")).each do |file_path|
file_content = File.read(file_path)
frontmatter, markdown_content = parse_frontmatter(file_content)
return new(frontmatter:, content: markdown_content) if frontmatter["slug"] == slug
end
nil
end
private
def parse_frontmatter(content)
if content =~ /\A---(.+?)---/m
frontmatter = YAML.safe_load($1)
markdown_content = content[($~.end(0))..-1].strip
else
frontmatter = {}
markdown_content = content
end
[ frontmatter, markdown_content ]
end
end
private
def render_markdown(content)
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
markdown.render(content)
end
end