From ef7c127cd54024dab77e7523eccfc6d2b9df2b43 Mon Sep 17 00:00:00 2001 From: Bryce Date: Thu, 12 Dec 2024 08:20:57 -0800 Subject: [PATCH] Makes tooltip, also makes date ranges work the way Ben asked for --- src/clj/auto_ap/ssr/components/inputs.clj | 8 +++++++- src/clj/auto_ap/ssr/utils.clj | 15 +++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/clj/auto_ap/ssr/components/inputs.clj b/src/clj/auto_ap/ssr/components/inputs.clj index 175b96cf..1e3b0049 100644 --- a/src/clj/auto_ap/ssr/components/inputs.clj +++ b/src/clj/auto_ap/ssr/components/inputs.clj @@ -336,6 +336,7 @@ (defn date-input- [{:keys [size] :as params}] [:div.shrink {:x-data (hx/json {:value (:value params) + :tippy nil :dp nil}) "@change-date.camel" "$dispatch('change')" } @@ -344,9 +345,14 @@ (update :class (fnil hh/add-class "") default-input-classes) (assoc :x-model "value") (assoc "x-tooltip.on.focus" "{content: ()=>$refs.tooltip.innerHTML, theme: 'light', onMount(i) { htmx.process(i.popper); }, allowHTML: true, interactive:true}") + + (assoc :x-init "$nextTick(() => tippy = $el.__x_tippy); ") (assoc :type "text") + (assoc "autocomplete" "off") (assoc "@change" "value = $event.target.value;") + + (assoc "@keydown.escape" "tippy.hide(); " ) #_(assoc "hx-on" (hiccup/raw "changeDate: htmx.trigger(this, \"change\") ")) (update :class #(str % (use-size size) " w-full")) (dissoc :size))] @@ -365,7 +371,7 @@ (assoc "@htmx:before-history-save" "destroyDatepicker(dp)") (assoc "@htmx:before-cleanup-element" "destroyDatepicker(dp)") (assoc "x-destroy" "destroyDatepicker(dp)") - (assoc "@change-date.camel" "value = dp.getDate(\"mm/dd/yyyy\"); ") + (assoc "@change-date.camel" "value = dp.getDate(\"mm/dd/yyyy\");") (update :class #(str % (use-size size) " w-full")) (dissoc :size :name :x-model :x-modelable))]]]]) diff --git a/src/clj/auto_ap/ssr/utils.clj b/src/clj/auto_ap/ssr/utils.clj index 0a2b8b4d..d7f8a8b7 100644 --- a/src/clj/auto_ap/ssr/utils.clj +++ b/src/clj/auto_ap/ssr/utils.clj @@ -255,19 +255,22 @@ (if date-range-value (-> (condp = date-range-value "week" - (let [last-monday (coerce/to-date-time (atime/last-monday))] + (let [last-monday (atime/as-local-time (coerce/to-date-time (atime/last-monday)))] (assoc m start-date-key (time/plus last-monday (time/days -7)) - end-date-key last-monday)) + end-date-key (time/plus last-monday (time/days -1)))) "month" - (assoc m - start-date-key (time/plus (time/now) (time/months -1)) - end-date-key nil) + (let [end-of-month (atime/as-local-time (coerce/to-date-time (time/plus (time/first-day-of-the-month (atime/local-today)) (time/days -1))))] + (assoc m + start-date-key (time/first-day-of-the-month end-of-month) + end-date-key end-of-month)) "year" (assoc m - start-date-key (time/plus (time/now) (time/years -1)) + start-date-key (atime/as-local-time (time/date-time (time/year (atime/local-today)) + 1 + 1)) end-date-key nil) "all"