Browse Source

fix: don't create another today's journal when updating page title's format

Tienson Qin 3 years ago
parent
commit
76d1888c1b
2 changed files with 12 additions and 0 deletions
  1. 10 0
      src/main/frontend/db/model.cljs
  2. 2 0
      src/main/frontend/handler/page.cljs

+ 10 - 0
src/main/frontend/db/model.cljs

@@ -797,6 +797,16 @@
         (reverse)
         (take n))))))
 
+(defn journal-day-exists?
+  [graph day]
+  (d/q
+    '[:find ?p .
+      :in $ ?day
+      :where
+      [?p :block/journal-day ?day]]
+    (conn/get-conn graph)
+    day))
+
 ;; get pages that this page referenced
 (defn get-page-referenced-pages
   [repo page]

+ 2 - 0
src/main/frontend/handler/page.cljs

@@ -715,6 +715,8 @@
                   file-content (when file-exists?
                                  (fs/read-file repo-dir file-path))]
             (when (and (db/page-empty? repo today-page)
+                       (not (model/journal-day-exists? repo
+                                                       (date/journal-title->int (date/today))))
                        (or (not file-exists?)
                            (and file-exists? (string/blank? file-content))))
               (create! title {:redirect? false