From d7c4772ad8716ea5dbadd141c6ceccb333f006f3 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Thu, 12 Mar 2026 09:01:16 -0500 Subject: [PATCH] Only show subsonic filter when subsonic products exist for caliber --- lib/ammoprices/catalog.ex | 6 ++++++ lib/ammoprices_web/live/caliber_live/show.ex | 4 +++- .../live/caliber_live/show_test.exs | 18 ++++++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/ammoprices/catalog.ex b/lib/ammoprices/catalog.ex index 93105d7..3d2002d 100644 --- a/lib/ammoprices/catalog.ex +++ b/lib/ammoprices/catalog.ex @@ -103,6 +103,12 @@ defmodule Ammoprices.Catalog do |> Repo.all() end + def has_subsonic_products?(caliber_id) do + Product + |> where([p], p.caliber_id == ^caliber_id and p.subsonic == true) + |> Repo.exists?() + end + def distinct_casings_for_caliber(caliber_id) do Product |> where([p], p.caliber_id == ^caliber_id) diff --git a/lib/ammoprices_web/live/caliber_live/show.ex b/lib/ammoprices_web/live/caliber_live/show.ex index 0ffe7b9..7c207d0 100644 --- a/lib/ammoprices_web/live/caliber_live/show.ex +++ b/lib/ammoprices_web/live/caliber_live/show.ex @@ -119,7 +119,8 @@ defmodule AmmopricesWeb.CaliberLive.Show do assign(socket, available_casings: Catalog.distinct_casings_for_caliber(caliber_id), - available_grain_weights: Catalog.distinct_grain_weights_for_caliber(caliber_id) + available_grain_weights: Catalog.distinct_grain_weights_for_caliber(caliber_id), + has_subsonic_products: Catalog.has_subsonic_products?(caliber_id) ) end @@ -310,6 +311,7 @@ defmodule AmmopricesWeb.CaliberLive.Show do <%!-- Subsonic toggle --%>