Add Today/Tomorrow tabs for price display

HTMX-powered tabs switch between today's and tomorrow's prices without
full page reload. Today tab is active by default.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-14 13:42:52 +01:00
co-authored by Claude Opus 4.6
parent 4fc2f82fbb
commit 9e78275c83
+44 -10
View File
@@ -69,12 +69,35 @@
(hour-block hour quarters))] (hour-block hour quarters))]
[:p {:class "mt-2 text-sm text-gray-400"} "Not available yet"])]) [:p {:class "mt-2 text-sm text-gray-400"} "Not available yet"])])
(defn- price-tables [query-fn] (def ^:private tab-base
(let [today (prices/get-today-prices query-fn) "px-4 py-2 font-medium text-sm rounded-t-lg border-2 border-b-0 ")
tomorrow (prices/get-tomorrow-prices query-fn)]
[:div {:id "price-tables"} (def ^:private tab-active
(price-table "Today — DK1" today) (str tab-base "border-blue-400 bg-white text-gray-900"))
(price-table "Tomorrow — DK1" tomorrow)]))
(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]
[:div {:class "flex gap-1 mt-4"}
[:button {:class (if (= active-tab :today) tab-active tab-inactive)
:hx-get "/prices/today"
:hx-target "#price-content"
:hx-swap "innerHTML"}
"Today"]
[:button {:class (if (= active-tab :tomorrow) tab-active tab-inactive)
:hx-get "/prices/tomorrow"
:hx-target "#price-content"
:hx-swap "innerHTML"}
"Tomorrow"]])
(defn- price-content [tab prices]
(let [title (if (= tab :today) "Today — DK1" "Tomorrow — DK1")]
[:div
(tabs tab)
[:div {:id "price-content"
:class "border-2 border-blue-400 rounded-b-lg rounded-tr-lg p-4 bg-white"}
(price-table title prices)]]))
(defn home [query-fn request] (defn home [query-fn request]
(page {:lang "en"} (page {:lang "en"}
@@ -85,23 +108,34 @@
[:button {:class "mt-4 rounded-lg bg-blue-600 px-4 py-2 text-white font-medium [:button {:class "mt-4 rounded-lg bg-blue-600 px-4 py-2 text-white font-medium
active:bg-blue-700 transition-colors" active:bg-blue-700 transition-colors"
:hx-post "/prices/fetch" :hx-post "/prices/fetch"
:hx-target "#price-tables" :hx-target "#price-panel"
:hx-swap "outerHTML" :hx-swap "innerHTML"
:hx-indicator "#fetch-spinner"} :hx-indicator "#fetch-spinner"}
"Refresh Prices"] "Refresh Prices"]
[:span {:id "fetch-spinner" [:span {:id "fetch-spinner"
:class "ml-2 htmx-indicator text-sm text-gray-400"} :class "ml-2 htmx-indicator text-sm text-gray-400"}
"Loading..."] "Loading..."]
(price-tables query-fn))) [:div {:id "price-panel"}
(price-content :today (prices/get-today-prices query-fn))]))
(defn prices-today [query-fn request]
(fragment
(price-table "Today — DK1" (prices/get-today-prices query-fn))))
(defn prices-tomorrow [query-fn request]
(fragment
(price-table "Tomorrow — DK1" (prices/get-tomorrow-prices 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-tables query-fn))) (price-content :today (prices/get-today-prices query-fn))))
;; Routes ;; Routes
(defn ui-routes [{:keys [query-fn]}] (defn ui-routes [{:keys [query-fn]}]
[["/" {:get (partial home query-fn)}] [["/" {:get (partial home query-fn)}]
["/prices/today" {:get (partial prices-today query-fn)}]
["/prices/tomorrow" {:get (partial prices-tomorrow query-fn)}]
["/prices/fetch" {:post (partial fetch-prices query-fn)}]]) ["/prices/fetch" {:post (partial fetch-prices query-fn)}]])
(def route-data (def route-data