mirror of
https://github.com/logseq/logseq.git
synced 2026-05-23 12:14:06 +00:00
fix: set date property value after creating journal page
This commit is contained in:
@@ -313,6 +313,22 @@
|
||||
(when done-choice
|
||||
(db-property/property-value-content done-choice))]])]))
|
||||
|
||||
(defn- <resolve-journal-page-for-date
|
||||
([^js d]
|
||||
(<resolve-journal-page-for-date d
|
||||
state/get-current-repo
|
||||
db-async/<get-block
|
||||
page-handler/<create!
|
||||
date/js-date->journal-title))
|
||||
([^js d get-current-repo-f get-block-f create-page-f journal-title-f]
|
||||
(p/let [journal (journal-title-f d)
|
||||
page (get-block-f (get-current-repo-f) journal {:children? false})
|
||||
journal-page (when (:block/journal-day page)
|
||||
page)]
|
||||
(if journal-page
|
||||
journal-page
|
||||
(create-page-f journal {:redirect? false})))))
|
||||
|
||||
(rum/defcs calendar-inner < rum/reactive db-mixins/query
|
||||
(rum/local (str "calendar-inner-" (js/Date.now)) ::identity)
|
||||
{:init (fn [state]
|
||||
@@ -353,13 +369,8 @@
|
||||
select-handler!
|
||||
(fn [^js d]
|
||||
(when d
|
||||
(p/let [journal (date/js-date->journal-title d)
|
||||
page (db-async/<get-block (state/get-current-repo) journal {:children? false})
|
||||
journal-page (when (:block/journal-day page)
|
||||
page)]
|
||||
(p/let [journal-page (<resolve-journal-page-for-date d)]
|
||||
(p/do!
|
||||
(when-not journal-page
|
||||
(page-handler/<create! journal {:redirect? false}))
|
||||
(when (fn? on-change)
|
||||
(let [value (if datetime? (tc/to-long d) journal-page)]
|
||||
(on-change value)))
|
||||
|
||||
49
src/test/frontend/components/property/value_test.cljs
Normal file
49
src/test/frontend/components/property/value_test.cljs
Normal file
@@ -0,0 +1,49 @@
|
||||
(ns frontend.components.property.value-test
|
||||
(:require [cljs.test :refer [async deftest is]]
|
||||
[frontend.components.property.value :as property-value]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(deftest resolve-journal-page-for-date-returns-existing-page-test
|
||||
(async done
|
||||
(let [existing-page {:db/id 100
|
||||
:block/journal-day 20250102}
|
||||
created?* (atom false)]
|
||||
(-> (#'property-value/<resolve-journal-page-for-date
|
||||
(js/Date. "2025-01-02T00:00:00Z")
|
||||
(constantly "test-repo")
|
||||
(fn [_repo _title _opts]
|
||||
(p/resolved existing-page))
|
||||
(fn [_title _opts]
|
||||
(reset! created?* true)
|
||||
(p/resolved {:db/id 999
|
||||
:block/journal-day 20250102}))
|
||||
(constantly "Jan 2nd, 2025"))
|
||||
(p/then (fn [page]
|
||||
(is (= existing-page page))
|
||||
(is (false? @created?*))
|
||||
(done)))
|
||||
(p/catch (fn [error]
|
||||
(is false (str error))
|
||||
(done)))))))
|
||||
|
||||
(deftest resolve-journal-page-for-date-creates-page-when-missing-test
|
||||
(async done
|
||||
(let [created-page {:db/id 200
|
||||
:block/journal-day 20250102}
|
||||
created-calls* (atom [])]
|
||||
(-> (#'property-value/<resolve-journal-page-for-date
|
||||
(js/Date. "2025-01-02T00:00:00Z")
|
||||
(constantly "test-repo")
|
||||
(fn [_repo _title _opts]
|
||||
(p/resolved nil))
|
||||
(fn [title opts]
|
||||
(swap! created-calls* conj [title opts])
|
||||
(p/resolved created-page))
|
||||
(constantly "Jan 2nd, 2025"))
|
||||
(p/then (fn [page]
|
||||
(is (= created-page page))
|
||||
(is (= [["Jan 2nd, 2025" {:redirect? false}]] @created-calls*))
|
||||
(done)))
|
||||
(p/catch (fn [error]
|
||||
(is false (str error))
|
||||
(done)))))))
|
||||
Reference in New Issue
Block a user