fix: allow users to give the remote graph a different local name

This commit is contained in:
Tienson Qin
2022-11-07 19:51:54 +08:00
parent 9652846be5
commit 222ce20946
2 changed files with 23 additions and 64 deletions

View File

@@ -515,59 +515,6 @@
synced-file-graph? queuing?)
[:div.head-ctls (sync-now)])]}))])))
(rum/defc pick-local-graph-for-sync [graph]
[:div.cp__file-sync-related-normal-modal
[:div.flex.justify-center.pb-4 [:span.icon-wrap (ui/icon "cloud-download")]]
[:h1.mb-5.text-2xl.text-center.font-bold (util/format "Sync graph \"%s\" to local"
(:GraphName graph))]
(ui/button
"Open a local directory"
:class "block w-full py-4 mt-4"
:on-click #(do
(state/close-modal!)
(fs-sync/<sync-stop)
(->
(page-handler/ls-dir-files!
(fn [{:keys [url]}]
(file-sync-handler/init-remote-graph url graph)
(js/setTimeout (fn [] (repo-handler/refresh-repos!)) 200))
{:sync-from-remote? true
:empty-dir?-or-pred
(fn [ret]
(let [empty-dir? (nil? (second ret))]
(if-let [root (first ret)]
;; verify directory
(-> (if empty-dir?
(p/resolved nil)
(if (util/electron?)
(ipc/ipc :readGraphTxIdInfo root)
(fs-util/read-graphs-txid-info root)))
(p/then (fn [^js info]
(when (and (not empty-dir?)
(or (nil? info)
(nil? (second info))
(not= (second info) (:GraphUUID graph))))
(if (js/confirm "This directory is not empty, are you sure to sync the remote graph to it? Make sure to back up the directory first.")
(p/resolved nil)
(throw (js/Error. nil)))))))
;; cancel pick a directory
(throw (js/Error. nil)))))})
(p/catch (fn [])))))
[:div.text-xs.opacity-50.px-1.flex-row.flex.items-center.p-2
(ui/icon "alert-circle")
[:span.ml-1 " An empty directory or an existing remote graph!"]]])
(defn pick-dest-to-sync-panel [graph]
(fn []
(pick-local-graph-for-sync graph)))
(rum/defc page-history-list
[graph-uuid page-entity set-list-ready? set-page]

View File

@@ -179,23 +179,35 @@
"Please wait seconds until all changes are saved for the current graph."
:warning))))
(defmethod handle :graph/pull-down-remote-graph [[_ graph]]
(when-let [graph-name (:GraphName graph)]
(defmethod handle :graph/pull-down-remote-graph [[_ graph dir-name]]
(when-let [graph-name (or dir-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)))))))))
(let [graph-path (graph-picker/validate-graph-dirname root graph-name)]
(->
(p/let [exists? (fs/dir-exists? graph-path)]
(let [overwrite? (if exists?
(js/confirm (str "There's already a directory with the name \"" graph-name "\", do you want to overwrite it? Make sure to backup it first if you're not sure about it."))
true)]
(if overwrite?
(p/let [_ (fs/mkdir-if-not-exists graph-path)]
(nfs-handler/ls-dir-files-with-path!
graph-path
{:ok-handler (fn []
(file-sync-handler/init-remote-graph graph-path graph)
(js/setTimeout (fn [] (repo-handler/refresh-repos!)) 200))}))
(let [graph-name (-> (js/prompt "Please specify a new directory name to download the graph:")
str
string/trim)]
(when-not (string/blank? graph-name)
(state/pub-event! [:graph/pull-down-remote-graph graph graph-name]))))))
(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!