diff --git a/src/main/frontend/components/property/value.cljs b/src/main/frontend/components/property/value.cljs index bcd8bd4e8..3d3c7d59b 100644 --- a/src/main/frontend/components/property/value.cljs +++ b/src/main/frontend/components/property/value.cljs @@ -14,7 +14,8 @@ [frontend.util :as util] [goog.dom :as gdom] [medley.core :as medley] - [rum.core :as rum])) + [rum.core :as rum] + [frontend.date :as date])) (defn exit-edit-property [] @@ -46,18 +47,25 @@ (rum/defc date-picker [block property value] - (let [value' (when-not (string/blank? value) + (let [title (when (uuid? value) + (:block/original-name (db/entity [:block/uuid value]))) + value (if title + (js/Date. (date/journal-title->long title)) + value) + value' (when-not (string/blank? value) (tc/to-local-date value)) - text (if value' - (str value') - "Pick a date") open-modal! (fn [] (state/set-modal! #(ui/datepicker value' {:on-change (fn [_e date] - (let [repo (state/get-current-repo)] - (property-handler/set-block-property! repo (:block/uuid block) - (:block/name property) - date) + (let [repo (state/get-current-repo) + journal (date/js-date->journal-title date)] + (when-not (db/entity [:block/name (util/page-name-sanity-lc journal)]) + (page-handler/create! journal {:redirect? false + :create-first-block? false})) + (when-let [page (db/entity [:block/name (util/page-name-sanity-lc journal)])] + (property-handler/set-block-property! repo (:block/uuid block) + (:block/name property) + (:block/uuid page))) (exit-edit-property) (state/close-modal!)))})))] [:a @@ -68,7 +76,7 @@ (open-modal!)))} [:span.inline-flex.items-center (ui/icon "calendar") - [:span.ml-1 text]]])) + [:span.ml-1 (or title "Pick a date")]]])) (defn- select-page [block property opts] diff --git a/src/main/frontend/date.cljs b/src/main/frontend/date.cljs index 62643c3a0..46df6ab90 100644 --- a/src/main/frontend/date.cljs +++ b/src/main/frontend/date.cljs @@ -215,6 +215,10 @@ (defn parse-iso [string] (tf/parse iso-parser string)) +(defn js-date->journal-title + [date] + (journal-name (tc/to-local-date date))) + (comment (def default-formatter (tf/formatter "MMM do, yyyy")) (def zh-formatter (tf/formatter "YYYY年MM月dd日")) @@ -229,4 +233,4 @@ :LemonRenewsAt "2024-04-11T07:28:00.000000Z", :LemonEndsAt nil, :LemonStatus "active"}] - (->> info :LemonRenewsAt (tf/parse iso-parser) (< (js/Date.))))) + (->> info :LemonRenewsAt (tf/parse iso-parser) (< (js/Date.))))) diff --git a/src/main/frontend/handler/db_based/property.cljs b/src/main/frontend/handler/db_based/property.cljs index 607ac5575..94e65abe4 100644 --- a/src/main/frontend/handler/db_based/property.cljs +++ b/src/main/frontend/handler/db_based/property.cljs @@ -15,11 +15,6 @@ ;; TODO: ;; Validate && list fixes for non-validated values when updating property schema -(defn- date-str? - [value] - (when-let [d (js/Date. value)] - (not= (str d) "Invalid Date"))) - (defn- logseq-page? [id] (and (uuid? id) @@ -41,8 +36,8 @@ {:default string? ; refs/tags will not be extracted :number number? :date [:fn - {:error/message "should be a date"} - date-str?] + {:error/message "should be a journal date"} + logseq-page?] :checkbox boolean? :url [:fn {:error/message "should be a URL"} @@ -77,7 +72,6 @@ (parse-double v-str) :number (util/uuid-string? v-str) :object (gp-util/url? v-str) :url - (date-str? v-str) :date (contains? #{"true" "false"} (string/lower-case v-str)) :boolean :else :default) (catch :default _e @@ -107,7 +101,7 @@ (uuid v-str) :date - (js/Date. v-str) ; inst + v-str ; uuid :url v-str)))