Tienson Qin 8 месяцев назад
Родитель
Сommit
5d6f5ad8dd

+ 3 - 2
deps/db/src/logseq/db/frontend/property.cljs

@@ -667,8 +667,9 @@
 
 (defn get-closed-property-values
   [db property-id]
-  (when-let [property (d/entity db property-id)]
-    (:property/closed-values property)))
+  (when db
+    (when-let [property (d/entity db property-id)]
+      (:property/closed-values property))))
 
 (defn closed-value-content
   "Gets content/value of a given closed value ent/map. Works for all closed value types"

+ 26 - 25
src/main/frontend/handler/page.cljs

@@ -332,31 +332,32 @@
       (state/set-today! (date/today))
       (when (or (config/db-based-graph? repo)
                 (config/local-file-based-graph? repo))
-        (let [title (date/today)
-              today-page (util/page-name-sanity-lc title)
-              format (state/get-preferred-format repo)
-              db-based? (config/db-based-graph? repo)
-              create-f (fn []
-                         (p/do!
-                          (<create! title {:redirect? false
-                                           :split-namespace? false
-                                           :today-journal? true})
-                          (when-not db-based? (state/pub-event! [:journal/insert-template today-page]))
-                          (ui-handler/re-render-root!)
-                          (plugin-handler/hook-plugin-app :today-journal-created {:title today-page})))]
-          (when-not (db/get-page today-page)
-            (if db-based?
-              (create-f)
-              (p/let [file-name (date/journal-title->default title)
-                      file-rpath (str (config/get-journals-directory) "/" file-name "."
-                                      (config/get-file-extension format))
-                      repo-dir (config/get-repo-dir repo)
-                      file-exists? (fs/file-exists? repo-dir file-rpath)
-                      file-content (when file-exists?
-                                     (fs/read-file repo-dir file-rpath))]
-                (when (or (not file-exists?)
-                          (and file-exists? (string/blank? file-content)))
-                  (create-f))))))))))
+        (if-let [title (date/today)]
+          (let [today-page (util/page-name-sanity-lc title)
+                format (state/get-preferred-format repo)
+                db-based? (config/db-based-graph? repo)
+                create-f (fn []
+                           (p/do!
+                            (<create! title {:redirect? false
+                                             :split-namespace? false
+                                             :today-journal? true})
+                            (when-not db-based? (state/pub-event! [:journal/insert-template today-page]))
+                            (ui-handler/re-render-root!)
+                            (plugin-handler/hook-plugin-app :today-journal-created {:title today-page})))]
+            (when-not (db/get-page today-page)
+              (if db-based?
+                (create-f)
+                (p/let [file-name (date/journal-title->default title)
+                        file-rpath (str (config/get-journals-directory) "/" file-name "."
+                                        (config/get-file-extension format))
+                        repo-dir (config/get-repo-dir repo)
+                        file-exists? (fs/file-exists? repo-dir file-rpath)
+                        file-content (when file-exists?
+                                       (fs/read-file repo-dir file-rpath))]
+                  (when (or (not file-exists?)
+                            (and file-exists? (string/blank? file-content)))
+                    (create-f))))))
+          (notification/show! "Failed to parse date to journal name." :error))))))
 
 (defn open-today-in-sidebar
   []

+ 1 - 1
src/main/frontend/modules/outliner/pipeline.cljs

@@ -36,7 +36,7 @@
         (let [ids (map (fn [id] (:db/id (db/entity [:block/uuid id]))) deleted-block-uuids)]
           (state/sidebar-remove-deleted-block! ids)))
 
-      (let [conn (db/get-db repo false)]
+      (when-let [conn (db/get-db repo false)]
         (cond
           initial-pages?
           (do

+ 70 - 67
src/main/frontend/quick_capture.cljs

@@ -6,6 +6,7 @@
             [frontend.date :as date]
             [frontend.db :as db]
             [frontend.handler.editor :as editor-handler]
+            [frontend.handler.notification :as notification]
             [frontend.handler.page :as page-handler]
             [frontend.state :as state]
             [frontend.util :as util]
@@ -19,80 +20,82 @@
         (re-matches #"^https://x\.com/.*?/status/.*?$" url))))
 
 (defn quick-capture [args]
-  (let [{:keys [url title content page append]} (bean/->clj args)
-        title (or title "")
-        url (or url "")
-        insert-today? (get-in (state/get-config)
-                              [:quick-capture-options :insert-today?]
-                              false)
-        redirect-page? (get-in (state/get-config)
-                               [:quick-capture-options :redirect-page?]
-                               false)
-        today-page (string/lower-case (date/today))
-        current-page (state/get-current-page) ;; empty when in journals page
-        default-page (get-in (state/get-config)
-                             [:quick-capture-options :default-page])
-        page (cond
-               (and (state/enable-journals?)
-                    (or (= page "TODAY")
-                        (and (string/blank? page) insert-today?)))
-               today-page
+  (if-let [today (date/today)]
+    (let [{:keys [url title content page append]} (bean/->clj args)
+          title (or title "")
+          url (or url "")
+          insert-today? (get-in (state/get-config)
+                                [:quick-capture-options :insert-today?]
+                                false)
+          redirect-page? (get-in (state/get-config)
+                                 [:quick-capture-options :redirect-page?]
+                                 false)
+          today-page (string/lower-case today)
+          current-page (state/get-current-page) ;; empty when in journals page
+          default-page (get-in (state/get-config)
+                               [:quick-capture-options :default-page])
+          page (cond
+                 (and (state/enable-journals?)
+                      (or (= page "TODAY")
+                          (and (string/blank? page) insert-today?)))
+                 today-page
 
-               (not-empty page)
-               page
+                 (not-empty page)
+                 page
 
-               (not-empty default-page)
-               default-page
+                 (not-empty default-page)
+                 default-page
 
-               (not-empty current-page)
-               current-page
+                 (not-empty current-page)
+                 current-page
 
-               :else
-               (if (state/enable-journals?) ;; default to "quick capture" page if journals are not enabled
-                 today-page
-                 "quick capture"))
-        format (db/get-page-format page)
-        time (date/get-current-time)
-        text (or (and content (not-empty (string/trim content))) "")
-        link (cond
-               (string/blank? url)
-               title
+                 :else
+                 (if (state/enable-journals?) ;; default to "quick capture" page if journals are not enabled
+                   today-page
+                   "quick capture"))
+          format (db/get-page-format page)
+          time (date/get-current-time)
+          text (or (and content (not-empty (string/trim content))) "")
+          link (cond
+                 (string/blank? url)
+                 title
 
-               (boolean (text-util/get-matched-video url))
-               (str title " {{video " url "}}")
+                 (boolean (text-util/get-matched-video url))
+                 (str title " {{video " url "}}")
 
-               (is-tweet-link url)
-               (util/format "{{twitter %s}}" url)
+                 (is-tweet-link url)
+                 (util/format "{{twitter %s}}" url)
 
-               (= title url)
-               (config/link-format format nil url)
+                 (= title url)
+                 (config/link-format format nil url)
 
-               :else
-               (config/link-format format title url))
-        template (get-in (state/get-config)
-                         [:quick-capture-templates :text]
-                         "**{time}** [[quick capture]]: {text} {url}")
-        date-ref-name (date/today)
-        content (-> template
-                    (string/replace "{time}" time)
-                    (string/replace "{date}" date-ref-name)
-                    (string/replace "{url}" link)
-                    (string/replace "{text}" text))
-        edit-content (state/get-edit-content)
-        edit-content-blank? (string/blank? edit-content)
-        edit-content-include-capture? (and (not-empty edit-content)
-                                           (string/includes? edit-content "[[quick capture]]"))]
-    (if (and (state/editing?) (not append) (not edit-content-include-capture?))
-      (if edit-content-blank?
-        (editor-handler/insert content)
-        (editor-handler/insert (str "\n" content)))
+                 :else
+                 (config/link-format format title url))
+          template (get-in (state/get-config)
+                           [:quick-capture-templates :text]
+                           "**{time}** [[quick capture]]: {text} {url}")
+          date-ref-name (date/today)
+          content (-> template
+                      (string/replace "{time}" time)
+                      (string/replace "{date}" date-ref-name)
+                      (string/replace "{url}" link)
+                      (string/replace "{text}" text))
+          edit-content (state/get-edit-content)
+          edit-content-blank? (string/blank? edit-content)
+          edit-content-include-capture? (and (not-empty edit-content)
+                                             (string/includes? edit-content "[[quick capture]]"))]
+      (if (and (state/editing?) (not append) (not edit-content-include-capture?))
+        (if edit-content-blank?
+          (editor-handler/insert content)
+          (editor-handler/insert (str "\n" content)))
 
-      (p/do!
-        (editor-handler/escape-editing)
-        (when (not= page (state/get-current-page))
-          (page-handler/<create! page {:redirect? redirect-page?}))
+        (p/do!
+         (editor-handler/escape-editing)
+         (when (not= page (state/get-current-page))
+           (page-handler/<create! page {:redirect? redirect-page?}))
         ;; Or else this will clear the newly inserted content
-        (js/setTimeout #(editor-handler/api-insert-new-block! content {:page page
-                                                                       :edit-block? true
-                                                                       :replace-empty-target? true})
-                       100)))))
+         (js/setTimeout #(editor-handler/api-insert-new-block! content {:page page
+                                                                        :edit-block? true
+                                                                        :replace-empty-target? true})
+                        100))))
+    (notification/show! "Failed to parse date to journal name." :error)))