add used filtering to ammo index page

This commit is contained in:
2022-11-07 00:47:22 -05:00
parent 9e386f1631
commit cc31958bbe
18 changed files with 91 additions and 68 deletions

View File

@ -9,7 +9,7 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
@impl true
def mount(_params, _session, socket) do
{:ok, socket |> display_ammo_groups()}
{:ok, socket |> assign(show_used: false) |> display_ammo_groups()}
end
@impl true
@ -72,8 +72,17 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
{:noreply, socket |> display_ammo_groups()}
end
defp display_ammo_groups(%{assigns: %{current_user: current_user}} = socket) do
ammo_groups = Ammo.list_ammo_groups(current_user) |> Repo.preload([:ammo_type, :container])
@impl true
def handle_event("toggle_show_used", _, %{assigns: %{show_used: show_used}} = socket) do
{:noreply, socket |> assign(:show_used, !show_used) |> display_ammo_groups()}
end
defp display_ammo_groups(
%{assigns: %{current_user: current_user, show_used: show_used}} = socket
) do
ammo_groups =
Ammo.list_ammo_groups(current_user, show_used) |> Repo.preload([:ammo_type, :container])
ammo_types_count = Ammo.get_ammo_types_count!(current_user)
containers_count = Containers.get_containers_count!(current_user)

View File

@ -46,6 +46,14 @@
<% end %>
<%= unless @ammo_groups |> Enum.empty?() do %>
<div class="flex flex-col justify-center items-center">
<.toggle_button action="toggle_show_used" value={@show_used}>
<span class="title text-lg text-primary-600">
<%= gettext("Show used") %>
</span>
</.toggle_button>
</div>
<.live_component
module={CanneryWeb.Components.TableComponent}
id="ammo_groups_index_table"