From 99780ebf60de17b35d1e90a992efe75ac49899db Mon Sep 17 00:00:00 2001 From: Per Magnus Petersen Date: Sat, 14 Feb 2026 14:10:25 +0100 Subject: [PATCH] Show date on Today/Tomorrow tabs and remove table headings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/clj/pmagnus/elprice/web/routes/ui.clj | 44 ++++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/clj/pmagnus/elprice/web/routes/ui.clj b/src/clj/pmagnus/elprice/web/routes/ui.clj index 6b4c449..e6a85ee 100644 --- a/src/clj/pmagnus/elprice/web/routes/ui.clj +++ b/src/clj/pmagnus/elprice/web/routes/ui.clj @@ -9,10 +9,12 @@ [reitit.ring.middleware.muuntaja :as muuntaja] [reitit.ring.middleware.parameters :as parameters]) (:import - [java.time LocalDateTime] + [java.time LocalDateTime ZoneId] [java.time.format DateTimeFormatter])) +(def ^:private dk-zone (ZoneId/of "Europe/Copenhagen")) (def ^:private hour-fmt (DateTimeFormatter/ofPattern "HH:00")) +(def ^:private date-fmt (DateTimeFormatter/ofPattern "yyyy-MM-dd")) (defn- ->ldt [time-dk] (cond @@ -60,9 +62,8 @@ [:span (format "%02d:%02d" hour (.getMinute (->ldt (:time_dk q))))] [:span {:class "font-mono"} (format-ore (:price_dkk q))]])]])) -(defn- price-table [title prices] - [:div {:class "mt-6"} - [:h2 {:class "text-lg font-semibold text-gray-900 mb-2"} title] +(defn- price-table [prices] + [:div (if (seq prices) [:div (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")) (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-panel" - :hx-swap "innerHTML"} - "Today"] - [:button {:class (if (= active-tab :tomorrow) tab-active tab-inactive) - :hx-get "/prices/tomorrow" - :hx-target "#price-panel" - :hx-swap "innerHTML"} - "Tomorrow"]]) + (let [today (java.time.LocalDate/now dk-zone) + tomorrow (.plusDays today 1)] + [:div {:class "flex gap-1 mt-4"} + [:button {:class (if (= active-tab :today) tab-active tab-inactive) + :hx-get "/prices/today" + :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))]])) (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)]])) + [: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 prices)]]) (defn home [query-fn request] (prices/fetch-and-save! query-fn)