enhance: create dir automatically when pulling down remote graphs

pull/7184/head
Tienson Qin 2022-11-07 18:19:07 +08:00
parent 2d201c2494
commit 9652846be5
3 changed files with 33 additions and 29 deletions

View File

@ -52,7 +52,7 @@
:let [only-cloud? (and remote? (nil? url))]]
[:div.flex.justify-between.mb-4.items-center {:key (or url GraphUUID)}
(normalized-graph-label repo #(if only-cloud?
(state/pub-event! [:graph/pick-dest-to-sync repo])
(state/pub-event! [:graph/pull-down-remote-graph repo])
(state/pub-event! [:graph/switch url])))
[:div.controls
@ -158,7 +158,7 @@
(if (gobj/get e "shiftKey")
(state/pub-event! [:graph/open-new-window url])
(if-not local?
(state/pub-event! [:graph/pick-dest-to-sync graph])
(state/pub-event! [:graph/pull-down-remote-graph graph])
(state/pub-event! [:graph/switch url]))))}})))
switch-repos)
refresh-link (let [nfs-repo? (config/local-db? current-repo)]

View File

@ -179,10 +179,23 @@
"Please wait seconds until all changes are saved for the current graph."
:warning))))
(defmethod handle :graph/pick-dest-to-sync [[_ graph]]
(state/set-modal!
(file-sync/pick-dest-to-sync-panel graph)
{:center? true}))
(defmethod handle :graph/pull-down-remote-graph [[_ graph]]
(when-let [graph-name (:GraphName graph)]
(let [graph-name (util/safe-sanitize-file-name graph-name)]
(if (string/blank? graph-name)
(notification/show! "Illegal graph folder name.")
;; Create graph directory under Logseq document folder (local)
(when-let [root (state/get-local-container-root-url)]
(-> (graph-picker/validate-graph-dirname root graph-name)
(p/then (fn [graph-path]
(-> (fs/mkdir-if-not-exists graph-path)
(p/then
(fn []
(nfs-handler/ls-dir-files-with-path! graph-path))))))
(p/catch (fn [^js e]
(notification/show! (str e) :error)
(js/console.error e)))))))))
(defmethod handle :graph/pick-page-histories [[_ graph-uuid page-name]]
(state/set-modal!

View File

@ -16,10 +16,7 @@
(defn validate-graph-dirname
[root dirname]
;; TODO: how to handle existing graph name directory?
;; TODO: temporarily just load the existing folder
(p/resolved (util/node-path.join root dirname)))
(util/node-path.join root dirname))
(rum/defc toggle-item
[{:keys [on? title on-toggle]}]
@ -56,27 +53,21 @@
(when-let [root (if icloud-sync-on?
(state/get-icloud-container-root-url)
(state/get-local-container-root-url))]
(-> (validate-graph-dirname root graph-name)
(p/then (fn [graph-path]
(-> (let [graph-path (validate-graph-dirname root graph-name)]
(-> (fs/mkdir-if-not-exists graph-path)
(p/then
(fn []
(web-nfs/ls-dir-files-with-path!
graph-path (merge
{:logseq-sync-on
logseq-sync-on?
:ok-handler
{:ok-handler
(fn []
(when logseq-sync-on?
(state/pub-event! [:sync/create-remote-graph (state/get-current-repo)])))}
opts))
(notification/show! (str "Create graph: " graph-name) :success))))))
(notification/show! (str "Create graph: " graph-name) :success)))))
(p/catch (fn [^js e]
(notification/show! (str e) :error)
(js/console.error e)))
(p/finally
#()))))))]
(js/console.error e))))))))]
(rum/use-effect!
(fn []