Show date on Today/Tomorrow tabs and remove table headings

Tabs now display the date (e.g. "Today 2026-02-14"). Removed redundant
"Today — DK1" / "Tomorrow — DK1" headings from the price tables.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-14 14:10:25 +01:00
co-authored by Claude Opus 4.6
parent 4ef693168c
commit 99780ebf60
+10 -8
View File
@@ -9,10 +9,12 @@
[reitit.ring.middleware.muuntaja :as muuntaja] [reitit.ring.middleware.muuntaja :as muuntaja]
[reitit.ring.middleware.parameters :as parameters]) [reitit.ring.middleware.parameters :as parameters])
(:import (:import
[java.time LocalDateTime] [java.time LocalDateTime ZoneId]
[java.time.format DateTimeFormatter])) [java.time.format DateTimeFormatter]))
(def ^:private dk-zone (ZoneId/of "Europe/Copenhagen"))
(def ^:private hour-fmt (DateTimeFormatter/ofPattern "HH:00")) (def ^:private hour-fmt (DateTimeFormatter/ofPattern "HH:00"))
(def ^:private date-fmt (DateTimeFormatter/ofPattern "yyyy-MM-dd"))
(defn- ->ldt [time-dk] (defn- ->ldt [time-dk]
(cond (cond
@@ -60,9 +62,8 @@
[:span (format "%02d:%02d" hour (.getMinute (->ldt (:time_dk q))))] [:span (format "%02d:%02d" hour (.getMinute (->ldt (:time_dk q))))]
[:span {:class "font-mono"} (format-ore (:price_dkk q))]])]])) [:span {:class "font-mono"} (format-ore (:price_dkk q))]])]]))
(defn- price-table [title prices] (defn- price-table [prices]
[:div {:class "mt-6"} [:div
[:h2 {:class "text-lg font-semibold text-gray-900 mb-2"} title]
(if (seq prices) (if (seq prices)
[:div [:div
(for [[hour quarters] (group-by-hour prices)] (for [[hour quarters] (group-by-hour prices)]
@@ -79,25 +80,26 @@
(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]
(let [today (java.time.LocalDate/now dk-zone)
tomorrow (.plusDays today 1)]
[:div {:class "flex gap-1 mt-4"} [:div {:class "flex gap-1 mt-4"}
[:button {:class (if (= active-tab :today) tab-active tab-inactive) [:button {:class (if (= active-tab :today) tab-active tab-inactive)
:hx-get "/prices/today" :hx-get "/prices/today"
:hx-target "#price-panel" :hx-target "#price-panel"
:hx-swap "innerHTML"} :hx-swap "innerHTML"}
"Today"] (str "Today " (.format today date-fmt))]
[: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"}
"Tomorrow"]]) (str "Tomorrow " (.format tomorrow date-fmt))]]))
(defn- price-content [tab prices] (defn- price-content [tab prices]
(let [title (if (= tab :today) "Today — DK1" "Tomorrow — DK1")]
[:div [:div
(tabs tab) (tabs tab)
[: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 title prices)]])) (price-table prices)]])
(defn home [query-fn request] (defn home [query-fn request]
(prices/fetch-and-save! query-fn) (prices/fetch-and-save! query-fn)