add selectable ammo types
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -10,11 +10,11 @@ defmodule CanneryWeb.RangeLive.Index do
|
||||
|
||||
@impl true
|
||||
def mount(%{"search" => search}, _session, socket) do
|
||||
{:ok, socket |> assign(search: search) |> display_shot_groups()}
|
||||
{:ok, socket |> assign(type: :all, search: search) |> display_shot_groups()}
|
||||
end
|
||||
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok, socket |> assign(search: nil) |> display_shot_groups()}
|
||||
{:ok, socket |> assign(type: :all, search: nil) |> display_shot_groups()}
|
||||
end
|
||||
|
||||
@impl true
|
||||
@ -102,9 +102,27 @@ defmodule CanneryWeb.RangeLive.Index do
|
||||
{:noreply, socket |> push_patch(to: Routes.range_index_path(Endpoint, :search, search_term))}
|
||||
end
|
||||
|
||||
def handle_event("change_type", %{"ammo_type" => %{"type" => "rifle"}}, socket) do
|
||||
{:noreply, socket |> assign(:type, :rifle) |> display_shot_groups()}
|
||||
end
|
||||
|
||||
def handle_event("change_type", %{"ammo_type" => %{"type" => "shotgun"}}, socket) do
|
||||
{:noreply, socket |> assign(:type, :shotgun) |> display_shot_groups()}
|
||||
end
|
||||
|
||||
def handle_event("change_type", %{"ammo_type" => %{"type" => "pistol"}}, socket) do
|
||||
{:noreply, socket |> assign(:type, :pistol) |> display_shot_groups()}
|
||||
end
|
||||
|
||||
def handle_event("change_type", %{"ammo_type" => %{"type" => _all}}, socket) do
|
||||
{:noreply, socket |> assign(:type, :all) |> display_shot_groups()}
|
||||
end
|
||||
|
||||
@spec display_shot_groups(Socket.t()) :: Socket.t()
|
||||
defp display_shot_groups(%{assigns: %{search: search, current_user: current_user}} = socket) do
|
||||
shot_groups = ActivityLog.list_shot_groups(search, current_user)
|
||||
defp display_shot_groups(
|
||||
%{assigns: %{type: type, search: search, current_user: current_user}} = socket
|
||||
) do
|
||||
shot_groups = ActivityLog.list_shot_groups(search, type, current_user)
|
||||
ammo_groups = Ammo.list_staged_ammo_groups(current_user)
|
||||
chart_data = shot_groups |> get_chart_data_for_shot_group()
|
||||
original_counts = ammo_groups |> Ammo.get_original_counts(current_user)
|
||||
|
Reference in New Issue
Block a user