add used filtering to ammo index page
This commit is contained in:
@ -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)
|
||||
|
||||
|
@ -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"
|
||||
|
Reference in New Issue
Block a user