Skip to content

Commit

Permalink
Allow deselecting category on overview page
Browse files Browse the repository at this point in the history
  • Loading branch information
murdho committed Mar 10, 2024
1 parent af76a98 commit eeaf4e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
10 changes: 5 additions & 5 deletions app/controllers/overview_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class OverviewController < ApplicationController
helper_method :selected_category_id

def index
@bank_transactions_for_overview = BankTransaction.for_overview
@bank_transactions_for_details = BankTransaction.for_details(detail_category_id)
@bank_transactions_for_details = BankTransaction.for_details(selected_category_id)
end

private

def detail_category_id
params[:detail_category_id]
def selected_category_id
params[:selected_category_id]
end
end
22 changes: 13 additions & 9 deletions app/views/overview/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<%# content_for :head do %>
<%#= turbo_refreshes_with(method: :morph, scroll: :preserve) %>
<%# end %>

<div class="min-w-full">
<h1 class="font-bold text-4xl">Overview</h1>
<div class="w-full">
Expand Down Expand Up @@ -29,11 +25,10 @@
<tbody class="divide-y divide-gray-200">
<% transactions.each do |transaction| %>
<tr>
<td class="whitespace-nowrap py-2 pl-4 pr-3 text-sm text-gray-900"><%= transaction.category_name || "—" %></td>
<td class="whitespace-nowrap px-2 py-2 text-sm text-gray-500 text-right">
<%= link_to transaction.count, { detail_category_id: transaction.category_id }, "data-turbo-action": :replace %>
<%#= transaction.count %>
<td class="whitespace-nowrap py-2 pl-4 pr-3 text-sm text-gray-900">
<%= link_to (transaction.category_name || "—"), { selected_category_id: transaction.category_id }, "data-turbo-action": :replace %>
</td>
<td class="whitespace-nowrap px-2 py-2 text-sm text-gray-500 text-right"><%= transaction.count %></td>
<td class="whitespace-nowrap px-2 py-2 text-sm text-gray-500 text-right"><%= transaction.currency %></td>
<td class="whitespace-nowrap px-2 py-2 text-sm text-gray-500 text-right"><%= money transaction.as_money(:incoming_cents) %></td>
<td class="whitespace-nowrap px-2 py-2 text-sm text-gray-500 text-right"><%= money transaction.as_money(:outgoing_cents) %></td>
Expand All @@ -50,7 +45,16 @@

<div class="w-1/2">
<% if (bank_transactions_for_month = @bank_transactions_for_details[month]) %>
<h2 class="font-bold text-2xl mt-16 mb-4"><%= bank_transactions_for_month.first.category_name || "Uncategorized" %></h2>
<h2 class="font-bold text-2xl mt-16 mb-4">
<% if selected_category_id.present? %>
<%= bank_transactions_for_month.first.category_name %>
<span class="cursor-pointer float-end">
<%= link_to "⨯", { selected_category_id: nil }, "data-turbo-action": :replace %>
</span>
<% else %>
Uncategorized
<% end %>
</h2>

<div class="ring-1 ring-gray-300 rounded-lg overflow-scroll">
<table class="min-w-full divide-y divide-gray-300">
Expand Down

0 comments on commit eeaf4e5

Please sign in to comment.