mirror of
https://github.com/logseq/logseq.git
synced 2026-06-01 19:01:22 +00:00
chore: add picker back for both Android and PC
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
[frontend.handler.notification :as notification]
|
||||
[frontend.handler.repo :as repo-handler]
|
||||
[frontend.handler.user :as user-handler]
|
||||
[frontend.handler.page :as page-handler]
|
||||
[frontend.handler.web.nfs :as web-nfs]
|
||||
[frontend.mobile.util :as mobile-util]
|
||||
[frontend.state :as state]
|
||||
@@ -514,6 +515,58 @@
|
||||
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))
|
||||
|
||||
{: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]
|
||||
|
||||
|
||||
@@ -180,34 +180,38 @@
|
||||
:warning))))
|
||||
|
||||
(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.")
|
||||
(if (mobile-util/native-ios?)
|
||||
(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)]
|
||||
(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))))))))))
|
||||
;; Create graph directory under Logseq document folder (local)
|
||||
(when-let [root (state/get-local-container-root-url)]
|
||||
(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)))))))))
|
||||
(state/set-modal!
|
||||
(file-sync/pick-dest-to-sync-panel graph)
|
||||
{:center? true})))
|
||||
|
||||
(defmethod handle :graph/pick-page-histories [[_ graph-uuid page-name]]
|
||||
(state/set-modal!
|
||||
|
||||
Reference in New Issue
Block a user