diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index bbd8409dad6..5ed5d042b69 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -1143,7 +1143,7 @@ show-page? page-name) (let [parents-atom (atom parents) - component [:div.block-parents.flex-row.flex + component [:div.block-parents.flex-row.flex-1 (when show-page? [:a {:href (rfe/href :page {:name page-name})} (or (:page/original-name page) diff --git a/src/main/frontend/components/external.cljs b/src/main/frontend/components/external.cljs index c5f4efbf546..41cc64f180b 100644 --- a/src/main/frontend/components/external.cljs +++ b/src/main/frontend/components/external.cljs @@ -27,8 +27,8 @@ (set! (.-onload reader) (fn [e] (let [text (.. e -target -result)] - (external-handler/import-from-roam-json! text) - (reset! *importing? false)))) + (external-handler/import-from-roam-json! text + #(reset! *importing? false))))) (.readAsText reader file))) (notification/show! "Please choose a JSON file." :error))))}] diff --git a/src/main/frontend/external/roam.cljs b/src/main/frontend/external/roam.cljs index 543f3de787d..97c2578f9f0 100644 --- a/src/main/frontend/external/roam.cljs +++ b/src/main/frontend/external/roam.cljs @@ -21,7 +21,7 @@ ;; TODO: 5. Roam attributes -> properties ;; TODO: 6. hiccup -(defonce uid-pattern #"\(\(([a-zA-Z0-9_\\-]{10})\)\)") +(defonce uid-pattern #"\(\(([a-zA-Z0-9_\\-]{6,24})\)\)") (defonce macro-pattern #"\{\{([^{}]+)\}\}") (defn uid-transform @@ -55,7 +55,9 @@ (map last) (distinct) (set))] - (reset! all-refed-uids uids)))) + (reset! all-refed-uids uids) + (doseq [uid uids] + (swap! uid->uuid assoc uid (medley/random-uuid)))))) (defn transform [text] @@ -65,7 +67,6 @@ (uid-transform) (macro-transform))) -;; #"(([a-zA-Z0-9_\\-]{9}))" (declare children->text) (defn child->text [{:keys [uid string children] :as child} level] diff --git a/src/main/frontend/handler/external.cljs b/src/main/frontend/handler/external.cljs index 69851577850..496312d5fab 100644 --- a/src/main/frontend/handler/external.cljs +++ b/src/main/frontend/handler/external.cljs @@ -2,6 +2,7 @@ (:require [frontend.external :as external] [frontend.handler.file :as file-handler] [frontend.handler.notification :as notification] + [frontend.handler.common :as common-handler] [frontend.state :as state] [frontend.date :as date] [frontend.config :as config] @@ -9,37 +10,45 @@ [frontend.db :as db])) (defn index-files! - [repo files error-files] - (doseq [file files] - (let [title (:title file) - journal? (date/valid-journal-title? title)] - (try - (when-let [text (:text file)] - (let [path (str (if journal? - config/default-journals-directory - config/default-pages-directory) - "/" - (if journal? - (date/journal-title->default title) - (string/replace title "/" "-")) - ".md")] - (file-handler/alter-file repo path text {}) - (when journal? - (let [page-name (string/lower-case title)] - (db/transact! repo - [{:page/name page-name - :page/journal? true - :page/journal-day (date/journal-title->int title)}]))))) - (catch js/Error e - (swap! error-files conj file)))))) + [repo files git-add-cb] + (let [titles (->> files + (map :title) + (map :text) + (remove nil?)) + files (map (fn [file] + (let [title (:title file) + journal? (date/valid-journal-title? title)] + (when-let [text (:text file)] + (let [path (str (if journal? + config/default-journals-directory + config/default-pages-directory) + "/" + (if journal? + (date/journal-title->default title) + (string/replace title "/" "-")) + ".md")] + [path text])))) + files)] + (file-handler/alter-files repo files {:add-history? false + :update-status? false + :reset? true + :git-add-cb git-add-cb}) + (let [journal-pages-tx (let [titles (filter date/valid-journal-title? titles)] + (map + (fn [title] + (let [page-name (string/lower-case title)] + {:page/name page-name + :page/journal? true + :page/journal-day (date/journal-title->int title)})) + titles))] + (when (seq journal-pages-tx) + (db/transact! repo journal-pages-tx))))) -;; TODO: compute the dependencies -;; TODO: Should it merge the roam daily notes with the month journals (defn import-from-roam-json! - [data] + [data finished-ok-handler] (when-let [repo (state/get-current-repo)] - (let [files (external/to-markdown-files :roam data {}) - error-files (atom #{})] - (index-files! repo files error-files) - (when (seq @error-files) - (index-files! repo @error-files (atom nil)))))) + (let [files (external/to-markdown-files :roam data {})] + (index-files! repo files + (fn [] + (common-handler/check-changed-files-status) + (finished-ok-handler)))))) diff --git a/src/main/frontend/handler/file.cljs b/src/main/frontend/handler/file.cljs index 69cd516694c..47a7834b2ed 100644 --- a/src/main/frontend/handler/file.cljs +++ b/src/main/frontend/handler/file.cljs @@ -111,7 +111,8 @@ [repo path content {:keys [reset? re-render-root? add-history? update-status?] :or {reset? true re-render-root? false - add-history? true}}] + add-history? true + update-status? false}}] (let [original-content (db/get-file-no-sub repo path)] (if reset? (db/reset-file! repo path content) @@ -119,7 +120,7 @@ (util/p-handle (fs/write-file (util/get-repo-dir repo) path content) (fn [_] - (git-handler/git-add repo path) + (git-handler/git-add repo path update-status?) (when (= path (str config/app-name "/" config/config-file)) (restore-config! repo true)) (when (= path (str config/app-name "/" config/custom-css-file)) @@ -132,26 +133,46 @@ (js/console.error error))))) (defn alter-files - [repo files] - (let [files-tx (mapv (fn [[path content]] - (let [original-content (db/get-file-no-sub repo path)] - [path original-content content])) files)] - (-> (p/all - (doall - (map - (fn [[path content]] - (db/set-file-content! repo path content) - (util/p-handle - (fs/write-file (util/get-repo-dir repo) path content) - (fn [_] - (git-handler/git-add repo path)) - (fn [error] - (println "Write file failed, path: " path ", content: " content) - (js/console.error error)))) - files))) - (p/then (fn [_result] - (ui-handler/re-render-file!) - (history/add-history! repo files-tx)))))) + ([repo files] + (alter-files repo files {})) + ([repo files {:keys [add-history? update-status? git-add-cb reset?] + :or {add-history? true + update-status? true + reset? false}}] + (let [files-tx (mapv (fn [[path content]] + (let [original-content (db/get-file-no-sub repo path)] + [path original-content content])) files)] + (-> (p/all + (doall + (map + (fn [[path content]] + (if reset? + (db/reset-file! repo path content) + (db/set-file-content! repo path content)) + (util/p-handle + (fs/write-file (util/get-repo-dir repo) path content) + (fn [_]) + (fn [error] + (println "Write file failed, path: " path ", content: " content) + (js/console.error error)))) + files))) + (p/then (fn [_result] + (-> + (p/all + (doall + (map + (fn [[path content]] + (git-handler/git-add repo path update-status?)) + files))) + (p/then (fn [_] + (when git-add-cb + (git-add-cb)))) + (p/catch (fn [error] + (println "Git add failed") + (js/console.error error)))) + (ui-handler/re-render-file!) + (when add-history? + (history/add-history! repo files-tx)))))))) (defn remove-file! [repo file] diff --git a/src/main/frontend/handler/git.cljs b/src/main/frontend/handler/git.cljs index 87b2566ab73..00d87ff3f63 100644 --- a/src/main/frontend/handler/git.cljs +++ b/src/main/frontend/handler/git.cljs @@ -47,13 +47,12 @@ ([repo-url file] (git-add repo-url file true)) ([repo-url file update-status?] - (-> (p/let [_result (git/add repo-url file)] + (-> (p/let [result (git/add repo-url file)] (when update-status? (common-handler/check-changed-files-status))) (p/catch (fn [error] (println "git add '" file "' failed: " error) (js/console.error error)))))) - (defn get-latest-commit ([repo-url handler] (get-latest-commit repo-url handler 1))