From 4d8d692dfc4cb7dc97cde6d84a5e8fe35d72beeb Mon Sep 17 00:00:00 2001 From: Per Magnus Petersen Date: Sat, 14 Feb 2026 14:15:32 +0100 Subject: [PATCH] Hide Tomorrow tab when no data is available Co-Authored-By: Claude Opus 4.6 --- src/clj/pmagnus/elprice/web/routes/ui.clj | 28 +++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/clj/pmagnus/elprice/web/routes/ui.clj b/src/clj/pmagnus/elprice/web/routes/ui.clj index e6a85ee..a872d2e 100644 --- a/src/clj/pmagnus/elprice/web/routes/ui.clj +++ b/src/clj/pmagnus/elprice/web/routes/ui.clj @@ -79,7 +79,7 @@ (def ^:private tab-inactive (str tab-base "border-gray-200 bg-gray-100 text-gray-500 hover:text-gray-700 cursor-pointer")) -(defn- tabs [active-tab] +(defn- tabs [active-tab has-tomorrow?] (let [today (java.time.LocalDate/now dk-zone) tomorrow (.plusDays today 1)] [:div {:class "flex gap-1 mt-4"} @@ -88,19 +88,23 @@ :hx-target "#price-panel" :hx-swap "innerHTML"} (str "Today " (.format today date-fmt))] - [:button {:class (if (= active-tab :tomorrow) tab-active tab-inactive) - :hx-get "/prices/tomorrow" - :hx-target "#price-panel" - :hx-swap "innerHTML"} - (str "Tomorrow " (.format tomorrow date-fmt))]])) + (when has-tomorrow? + [:button {:class (if (= active-tab :tomorrow) tab-active tab-inactive) + :hx-get "/prices/tomorrow" + :hx-target "#price-panel" + :hx-swap "innerHTML"} + (str "Tomorrow " (.format tomorrow date-fmt))])])) -(defn- price-content [tab prices] +(defn- price-content [tab prices has-tomorrow?] [:div - (tabs tab) + (tabs tab has-tomorrow?) [:div {:id "price-content" :class "border-2 border-blue-400 rounded-b-lg rounded-tr-lg p-4 bg-white"} (price-table prices)]]) +(defn- has-tomorrow? [query-fn] + (seq (prices/get-tomorrow-prices query-fn))) + (defn home [query-fn request] (prices/fetch-and-save! query-fn) (page {:lang "en"} @@ -112,20 +116,20 @@ [:p {:class "mt-1 text-sm text-gray-500"} "Day-ahead spot prices for DK1 (øre/kWh)"] [:div {:id "price-panel"} - (price-content :today (prices/get-today-prices query-fn))])) + (price-content :today (prices/get-today-prices query-fn) (has-tomorrow? query-fn))])) (defn prices-today [query-fn request] (fragment - (price-content :today (prices/get-today-prices query-fn)))) + (price-content :today (prices/get-today-prices query-fn) (has-tomorrow? query-fn)))) (defn prices-tomorrow [query-fn request] (fragment - (price-content :tomorrow (prices/get-tomorrow-prices query-fn)))) + (price-content :tomorrow (prices/get-tomorrow-prices query-fn) (has-tomorrow? query-fn)))) (defn fetch-prices [query-fn request] (prices/fetch-and-save! query-fn) (fragment - (price-content :today (prices/get-today-prices query-fn)))) + (price-content :today (prices/get-today-prices query-fn) (has-tomorrow? query-fn)))) ;; Routes (defn ui-routes [{:keys [query-fn]}]