Hide Tomorrow tab when no data is available
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -79,7 +79,7 @@
|
|||||||
(def ^:private tab-inactive
|
(def ^:private tab-inactive
|
||||||
(str tab-base "border-gray-200 bg-gray-100 text-gray-500 hover:text-gray-700 cursor-pointer"))
|
(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)
|
(let [today (java.time.LocalDate/now dk-zone)
|
||||||
tomorrow (.plusDays today 1)]
|
tomorrow (.plusDays today 1)]
|
||||||
[:div {:class "flex gap-1 mt-4"}
|
[:div {:class "flex gap-1 mt-4"}
|
||||||
@@ -88,19 +88,23 @@
|
|||||||
:hx-target "#price-panel"
|
:hx-target "#price-panel"
|
||||||
:hx-swap "innerHTML"}
|
:hx-swap "innerHTML"}
|
||||||
(str "Today " (.format today date-fmt))]
|
(str "Today " (.format today date-fmt))]
|
||||||
|
(when has-tomorrow?
|
||||||
[:button {:class (if (= active-tab :tomorrow) tab-active tab-inactive)
|
[:button {:class (if (= active-tab :tomorrow) tab-active tab-inactive)
|
||||||
:hx-get "/prices/tomorrow"
|
:hx-get "/prices/tomorrow"
|
||||||
:hx-target "#price-panel"
|
:hx-target "#price-panel"
|
||||||
:hx-swap "innerHTML"}
|
:hx-swap "innerHTML"}
|
||||||
(str "Tomorrow " (.format tomorrow date-fmt))]]))
|
(str "Tomorrow " (.format tomorrow date-fmt))])]))
|
||||||
|
|
||||||
(defn- price-content [tab prices]
|
(defn- price-content [tab prices has-tomorrow?]
|
||||||
[:div
|
[:div
|
||||||
(tabs tab)
|
(tabs tab has-tomorrow?)
|
||||||
[:div {:id "price-content"
|
[:div {:id "price-content"
|
||||||
:class "border-2 border-blue-400 rounded-b-lg rounded-tr-lg p-4 bg-white"}
|
:class "border-2 border-blue-400 rounded-b-lg rounded-tr-lg p-4 bg-white"}
|
||||||
(price-table prices)]])
|
(price-table prices)]])
|
||||||
|
|
||||||
|
(defn- has-tomorrow? [query-fn]
|
||||||
|
(seq (prices/get-tomorrow-prices query-fn)))
|
||||||
|
|
||||||
(defn home [query-fn request]
|
(defn home [query-fn request]
|
||||||
(prices/fetch-and-save! query-fn)
|
(prices/fetch-and-save! query-fn)
|
||||||
(page {:lang "en"}
|
(page {:lang "en"}
|
||||||
@@ -112,20 +116,20 @@
|
|||||||
[:p {:class "mt-1 text-sm text-gray-500"}
|
[:p {:class "mt-1 text-sm text-gray-500"}
|
||||||
"Day-ahead spot prices for DK1 (øre/kWh)"]
|
"Day-ahead spot prices for DK1 (øre/kWh)"]
|
||||||
[:div {:id "price-panel"}
|
[: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]
|
(defn prices-today [query-fn request]
|
||||||
(fragment
|
(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]
|
(defn prices-tomorrow [query-fn request]
|
||||||
(fragment
|
(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]
|
(defn fetch-prices [query-fn request]
|
||||||
(prices/fetch-and-save! query-fn)
|
(prices/fetch-and-save! query-fn)
|
||||||
(fragment
|
(fragment
|
||||||
(price-content :today (prices/get-today-prices query-fn))))
|
(price-content :today (prices/get-today-prices query-fn) (has-tomorrow? query-fn))))
|
||||||
|
|
||||||
;; Routes
|
;; Routes
|
||||||
(defn ui-routes [{:keys [query-fn]}]
|
(defn ui-routes [{:keys [query-fn]}]
|
||||||
|
|||||||
Reference in New Issue
Block a user