Browse Source

Merge branch 'master' into fix/priority-style-issues

Charlie 5 years ago
parent
commit
883e3a2ab3

+ 10 - 10
src/main/frontend/components/svg.cljs

@@ -119,7 +119,7 @@
 
 (def plus-circle
   [:svg.addButton
-   {:viewbox "0 0 20 20"}
+   {:viewBox "0 0 20 20"}
    [:circle.circle {:fill "#dce0e2", :r "9", :cy "10.5", :cx "10.5"}]
    [:line
     {:stroke-width "1"
@@ -150,24 +150,24 @@
 
 (def folder (hero-icon "M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"))
 (def folder-sm (hero-icon "M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" {:height "16" :width "16"}))
-(def pages-sm [:svg {:viewbox "0 0 20 20", :fill "currentColor", :height "16", :width "16"}
+(def pages-sm [:svg {:viewBox "0 0 20 20", :fill "currentColor", :height "16", :width "16"}
                [:path {:d "M9 2a2 2 0 00-2 2v8a2 2 0 002 2h6a2 2 0 002-2V6.414A2 2 0 0016.414 5L14 2.586A2 2 0 0012.586 2H9z"}]
                [:path {:d "M3 8a2 2 0 012-2v10h8a2 2 0 01-2 2H5a2 2 0 01-2-2V8z"}]])
-(def repos-sm [:svg {:viewbox "0 0 20 20", :fill "currentColor", :height "16", :width "16"}
+(def repos-sm [:svg {:viewBox "0 0 20 20", :fill "currentColor", :height "16", :width "16"}
                [:path {:d "M3 12v3c0 1.657 3.134 3 7 3s7-1.343 7-3v-3c0 1.657-3.134 3-7 3s-7-1.343-7-3z"}]
                [:path {:d "M3 7v3c0 1.657 3.134 3 7 3s7-1.343 7-3V7c0 1.657-3.134 3-7 3S3 8.657 3 7z"}]
                [:path {:d "M17 5c0 1.657-3.134 3-7 3S3 6.657 3 5s3.134-3 7-3 7 1.343 7 3z"}]])
-(def settings-sm [:svg {:viewbox "0 0 20 20", :fill "currentColor", :height "20", :width "20"}
+(def settings-sm [:svg {:viewBox "0 0 20 20", :fill "currentColor", :height "20", :width "20"}
                   [:path {:fill-rule "evenodd", :d "M11.49 3.17c-.38-1.56-2.6-1.56-2.98 0a1.532 1.532 0 01-2.286.948c-1.372-.836-2.942.734-2.106 2.106.54.886.061 2.042-.947 2.287-1.561.379-1.561 2.6 0 2.978a1.532 1.532 0 01.947 2.287c-.836 1.372.734 2.942 2.106 2.106a1.532 1.532 0 012.287.947c.379 1.561 2.6 1.561 2.978 0a1.533 1.533 0 012.287-.947c1.372.836 2.942-.734 2.106-2.106a1.533 1.533 0 01.947-2.287c1.561-.379 1.561-2.6 0-2.978a1.532 1.532 0 01-.947-2.287c.836-1.372-.734-2.942-2.106-2.106a1.532 1.532 0 01-2.287-.947zM10 13a3 3 0 100-6 3 3 0 000 6z", :clip-rule "evenodd"}]])
-(def calendar-sm [:svg {:viewbox "0 0 20 20", :fill "currentColor", :height "16", :width "16"}
+(def calendar-sm [:svg {:viewBox "0 0 20 20", :fill "currentColor", :height "16", :width "16"}
                   [:path {:fill-rule "evenodd", :d "M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z", :clip-rule "evenodd"}]])
-(def import-sm [:svg {:viewbox "0 0 20 20", :fill "currentColor", :height "16", :width "16"}
+(def import-sm [:svg {:viewBox "0 0 20 20", :fill "currentColor", :height "16", :width "16"}
                 [:path {:fill-rule "evenodd", :d "M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM6.293 6.707a1 1 0 010-1.414l3-3a1 1 0 011.414 0l3 3a1 1 0 01-1.414 1.414L11 5.414V13a1 1 0 11-2 0V5.414L7.707 6.707a1 1 0 01-1.414 0z", :clip-rule "evenodd"}]])
-(def logout-sm [:svg {:viewbox "0 0 20 20", :fill "currentColor", :height "18", :width "18"}
+(def logout-sm [:svg {:viewBox "0 0 20 20", :fill "currentColor", :height "18", :width "18"}
                 [:path {:fill-rule "evenodd", :d "M3 3a1 1 0 00-1 1v12a1 1 0 102 0V4a1 1 0 00-1-1zm10.293 9.293a1 1 0 001.414 1.414l3-3a1 1 0 000-1.414l-3-3a1 1 0 10-1.414 1.414L14.586 9H7a1 1 0 100 2h7.586l-1.293 1.293z", :clip-rule "evenodd"}]])
-(def trash-sm [:svg {:viewbox "0 0 20 20", :fill "currentColor", :height "16", :width "16"}
+(def trash-sm [:svg {:viewBox "0 0 20 20", :fill "currentColor", :height "16", :width "16"}
                [:path {:fill-rule "evenodd", :d "M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z", :clip-rule "evenodd"}]])
-(def sort-asc-sm [:svg {:viewbox "0 0 16 16", :fill "currentColor"}
+(def sort-asc-sm [:svg {:viewBox "0 0 16 16", :fill "currentColor"}
                   [:path {:d "M3 3a1 1 0 000 2h11a1 1 0 100-2H3zM3 7a1 1 0 000 2h5a1 1 0 000-2H3zM3 11a1 1 0 100 2h4a1 1 0 100-2H3zM13 16a1 1 0 102 0v-5.586l1.293 1.293a1 1 0 001.414-1.414l-3-3a1 1 0 00-1.414 0l-3 3a1 1 0 101.414 1.414L13 10.414V16z"}]])
 (defn vertical-dots
   [options]
@@ -421,7 +421,7 @@
      :stroke-linecap "round"}]])
 
 (def page
-  [:svg.h-5.w-4 {:viewbox "0 0 24 24", :fill "none", :xmlns "http://www.w3.org/2000/svg"}
+  [:svg.h-5.w-4 {:viewBox "0 0 24 24", :fill "none", :xmlns "http://www.w3.org/2000/svg"}
    [:path {:d "M2 0.5H6.78272L13.5 7.69708V18C13.5 18.8284 12.8284 19.5 12 19.5H2C1.17157 19.5 0.5 18.8284 0.5 18V2C0.5 1.17157 1.17157 0.5 2 0.5Z", :fill "var(--ls-active-primary-color)"}]
    [:path {:d "M7 5.5V0L14 7.5H9C7.89543 7.5 7 6.60457 7 5.5Z", :fill "var(--ls-active-secondary-color)"}]])
 

+ 11 - 7
src/main/frontend/external/roam.cljs

@@ -92,13 +92,17 @@
 (defn ->file
   [page-data]
   (let [{:keys [create-time title children edit-time]} page-data
-        initial-level 2]
-    {:title title
-     :created-at create-time
-     :last-modified-at edit-time
-     :text (when-let [text (children->text children initial-level)]
-             (let [front-matter (util/format "---\ntitle: %s\n---\n\n" title)]
-               (str front-matter (transform text))))}))
+        initial-level 2
+        text (when (seq children)
+               (when-let [text (children->text children initial-level)]
+                 (let [front-matter (util/format "---\ntitle: %s\n---\n\n" title)]
+                   (str front-matter (transform text)))))]
+    (when (and (not (string/blank? title))
+               text)
+      {:title title
+       :created-at create-time
+       :last-modified-at edit-time
+       :text text})))
 
 (defn ->files
   [edn-data]

+ 5 - 0
src/main/frontend/handler/editor.cljs

@@ -645,6 +645,11 @@
                                blocks-container-id (and blocks-container-id
                                                         (util/uuid-string? blocks-container-id)
                                                         (medley/uuid blocks-container-id))]
+
+                           ; WORKAROUND: The block won't refresh itself even if the content is empty.
+                           (when edit-self?
+                             (gobj/set input "value" ""))
+
                            (when ok-handler
                              (ok-handler
                               (if edit-self? (first blocks) (last blocks))))

+ 14 - 7
src/main/frontend/handler/external.cljs

@@ -1,13 +1,16 @@
 (ns frontend.handler.external
   (:require [frontend.external :as external]
             [frontend.handler.file :as file-handler]
+            [frontend.handler.repo :as repo-handler]
             [frontend.handler.common :as common-handler]
             [frontend.state :as state]
             [frontend.date :as date]
             [frontend.config :as config]
             [clojure.string :as string]
+            [promesa.core :as p]
             [frontend.db :as db]))
 
+(defonce debug-files (atom nil))
 (defn index-files!
   [repo files git-add-cb]
   (let [titles (->> files
@@ -26,13 +29,17 @@
                                            (date/journal-title->default title)
                                            (string/replace title "/" "-"))
                                          ".md")]
-                           [path text]))))
-                   files)]
-    ;; TODO: git add is quite slow
-    (file-handler/alter-files repo files {:add-history? false
-                                          :update-status? false
-                                          :reset? true
-                                          :git-add-cb git-add-cb})
+                           {:file/path path
+                            :file/content text}))))
+                   files)
+        files (remove nil? files)
+        _ (reset! debug-files files)]
+    (repo-handler/parse-files-and-load-to-db! repo files nil)
+    (let [files (map (fn [{:file/keys [path content]}] [path content]) files)]
+      (file-handler/alter-files repo files {:add-history? false
+                                            :update-db? false
+                                            :update-status? false
+                                            :git-add-cb git-add-cb}))
     (let [journal-pages-tx (let [titles (filter date/valid-journal-title? titles)]
                              (map
                               (fn [title]

+ 8 - 6
src/main/frontend/handler/file.cljs

@@ -162,16 +162,18 @@
                                    :path-params {:path path}}))))))
 
 (defn alter-files
-  [repo files {:keys [add-history? update-status? git-add-cb reset?]
+  [repo files {:keys [add-history? update-status? git-add-cb reset? update-db?]
                :or {add-history? true
                     update-status? true
-                    reset? false}
+                    reset? false
+                    update-db? true}
                :as opts}]
   ;; update db
-  (doseq [[path content] files]
-    (if reset?
-      (db/reset-file! repo path content)
-      (db/set-file-content! repo path content)))
+  (when update-db?
+    (doseq [[path content] files]
+      (if reset?
+        (db/reset-file! repo path content)
+        (db/set-file-content! repo path content))))
 
   (when-let [chan (state/get-file-write-chan)]
     (async/put! chan [repo files opts])))

+ 8 - 5
src/main/frontend/handler/repo.cljs

@@ -145,7 +145,9 @@
   (state/set-today! (date/today))
   (when-let [repo (state/get-current-repo)]
     (when (or (db/cloned? repo)
-              (config/local-db? repo))
+              (and (config/local-db? repo)
+                   ;; config file exists
+                   (db/get-file (str config/app-name "/" config/config-file))))
       (let [today-page (string/lower-case (date/today))]
         (when (empty? (db/get-page-blocks-no-cache repo today-page))
           (create-today-journal-if-not-exists repo))))))
@@ -158,7 +160,7 @@
   (create-contents-file repo-url)
   (create-custom-theme repo-url))
 
-(defn- parse-files-and-load-to-db!
+(defn parse-files-and-load-to-db!
   [repo-url files {:keys [first-clone? delete-files delete-blocks re-render? re-render-opts] :as opts
                    :or {re-render? true}}]
   (state/set-loading-files! false)
@@ -184,7 +186,8 @@
     (state/set-importing-to-db! false)))
 
 (defn load-repo-to-db!
-  [repo-url {:keys [first-clone? diffs nfs-files]}]
+  [repo-url {:keys [first-clone? diffs nfs-files]
+             :as opts}]
   (spec/validate :repos/url repo-url)
   (let [load-contents (fn [files option]
                         (file-handler/load-files-contents!
@@ -193,10 +196,10 @@
                          (fn [files-contents]
                            (parse-files-and-load-to-db! repo-url files-contents option))))]
     (cond
-      (and (not (seq diffs)) (seq nfs-files))
+      (and (not (seq diffs)) nfs-files)
       (parse-files-and-load-to-db! repo-url nfs-files {:first-clone? true})
 
-      first-clone?
+      (and first-clone? (not nfs-files))
       (->
        (p/let [files (file-handler/load-files repo-url)]
          (load-contents files {:first-clone? first-clone?}))

+ 63 - 62
src/main/frontend/handler/web/nfs.cljs

@@ -167,69 +167,70 @@
           handle-path (str config/local-handle-prefix dir-name)
           path-handles (atom {})]
       (state/set-graph-syncing? true)
-      (p/let [handle (idb/get-item handle-path)]
-        (when handle
-          (p/let [_ (when handle (utils/verifyPermission handle true))
-                  files-result (utils/getFiles handle true
-                                               (fn [path handle]
-                                                 (swap! path-handles assoc path handle)))
-                  new-files (-> (->db-files dir-name files-result)
-                                remove-ignore-files)
-                  _ (let [file-paths (set (map :file/path new-files))]
-                      (swap! path-handles (fn [handles]
-                                            (->> handles
-                                                 (filter (fn [[path _handle]]
-                                                           (contains? file-paths
-                                                                      (string/replace-first path (str dir-name "/") ""))))
-                                                 (into {})))))
-                  _ (set-files! @path-handles)
-                  get-file-f (fn [path files] (some #(when (= (:file/path %) path) %) files))
-                  {:keys [added modified deleted] :as diffs} (compute-diffs old-files new-files)
+      (->
+       (p/let [handle (idb/get-item handle-path)]
+         (when handle
+           (p/let [_ (when handle (utils/verifyPermission handle true))
+                   files-result (utils/getFiles handle true
+                                                (fn [path handle]
+                                                  (swap! path-handles assoc path handle)))
+                   new-files (-> (->db-files dir-name files-result)
+                                 remove-ignore-files)
+                   _ (let [file-paths (set (map :file/path new-files))]
+                       (swap! path-handles (fn [handles]
+                                             (->> handles
+                                                  (filter (fn [[path _handle]]
+                                                            (contains? file-paths
+                                                                       (string/replace-first path (str dir-name "/") ""))))
+                                                  (into {})))))
+                   _ (set-files! @path-handles)
+                   get-file-f (fn [path files] (some #(when (= (:file/path %) path) %) files))
+                   {:keys [added modified deleted] :as diffs} (compute-diffs old-files new-files)
                   ;; Use the same labels as isomorphic-git
-                  rename-f (fn [typ col] (mapv (fn [file] {:type typ :path file}) col))
-                  _ (when (seq deleted)
-                      (let [deleted (doall
-                                     (-> (map (fn [path] (if (= "/" (first path))
-                                                           path
-                                                           (str "/" path))) deleted)
-                                         (distinct)))]
-                        (p/all (map (fn [path]
-                                      (let [handle-path (str handle-path path)]
-                                        (idb/remove-item! handle-path)
-                                        (fs/remove-nfs-file-handle! handle-path))) deleted))))
-                  added-or-modified (set (concat added modified))
-                  _ (when (seq added-or-modified)
-                      (p/all (map (fn [path]
-                                    (when-let [handle (get @path-handles path)]
-                                      (idb/set-item! (str handle-path path) handle))) added-or-modified)))]
-            (-> (p/all (map (fn [path]
-                              (when-let [file (get-file-f path new-files)]
-                                (p/let [content (.text (:file/file file))]
-                                  (assoc file :file/content content)))) added-or-modified))
-                (p/then (fn [result]
-                          (let [files (map #(dissoc % :file/file :file/handle) result)
-                                non-modified? (fn [file]
-                                                (let [content (:file/content file)
-                                                      old-content (:file/content (get-file-f (:file/path file) old-files))]
-                                                  (= content old-content)))
-                                non-modified-files (->> (filter non-modified? files)
-                                                        (map :file/path))
-                                modified-files (remove non-modified? files)
-                                modified (set/difference (set modified) (set non-modified-files))
-                                diffs (concat
-                                       (rename-f "remove" deleted)
-                                       (rename-f "add" added)
-                                       (rename-f "modify" modified))]
-                            (when (or (and (seq diffs) (seq modified-files))
-                                      (seq diffs) ; delete
-)
-                              (repo-handler/load-repo-to-db! repo
-                                                             {:diffs diffs
-                                                              :nfs-files modified-files})))))
-                (p/catch (fn [error]
-                           (log/error :nfs/load-files-error error)))
-                (p/finally (fn [_]
-                             (state/set-graph-syncing? false))))))))))
+                   rename-f (fn [typ col] (mapv (fn [file] {:type typ :path file}) col))
+                   _ (when (seq deleted)
+                       (let [deleted (doall
+                                      (-> (map (fn [path] (if (= "/" (first path))
+                                                            path
+                                                            (str "/" path))) deleted)
+                                          (distinct)))]
+                         (p/all (map (fn [path]
+                                       (let [handle-path (str handle-path path)]
+                                         (idb/remove-item! handle-path)
+                                         (fs/remove-nfs-file-handle! handle-path))) deleted))))
+                   added-or-modified (set (concat added modified))
+                   _ (when (seq added-or-modified)
+                       (p/all (map (fn [path]
+                                     (when-let [handle (get @path-handles path)]
+                                       (idb/set-item! (str handle-path path) handle))) added-or-modified)))]
+             (-> (p/all (map (fn [path]
+                               (when-let [file (get-file-f path new-files)]
+                                 (p/let [content (.text (:file/file file))]
+                                   (assoc file :file/content content)))) added-or-modified))
+                 (p/then (fn [result]
+                           (let [files (map #(dissoc % :file/file :file/handle) result)
+                                 non-modified? (fn [file]
+                                                 (let [content (:file/content file)
+                                                       old-content (:file/content (get-file-f (:file/path file) old-files))]
+                                                   (= content old-content)))
+                                 non-modified-files (->> (filter non-modified? files)
+                                                         (map :file/path))
+                                 modified-files (remove non-modified? files)
+                                 modified (set/difference (set modified) (set non-modified-files))
+                                 diffs (concat
+                                        (rename-f "remove" deleted)
+                                        (rename-f "add" added)
+                                        (rename-f "modify" modified))]
+                             (when (or (and (seq diffs) (seq modified-files))
+                                       (seq diffs) ; delete
+                                       )
+                               (repo-handler/load-repo-to-db! repo
+                                                              {:diffs diffs
+                                                               :nfs-files modified-files})))))))))
+       (p/catch (fn [error]
+                  (log/error :nfs/load-files-error error)))
+       (p/finally (fn [_]
+                    (state/set-graph-syncing? false)))))))
 
 (defn refresh!
   [repo ok-handler]

+ 4 - 4
yarn.lock

@@ -2574,10 +2574,10 @@ [email protected]:
   resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
   integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=
 
-ini@^1.3.4, ini@^1.3.5:
-  version "1.3.7"
-  resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.7.tgz#a09363e1911972ea16d7a8851005d84cf09a9a84"
-  integrity sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ==
+ini@^1.3.4:
+  version "1.3.8"
+  resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
+  integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==
 
 interpret@^1.4.0:
   version "1.4.0"