Merge pull request #7184 from logseq/enhance/ios-folder-picker

enhance: graph select and create on iOS
This commit is contained in:
Tienson Qin
2022-11-08 23:10:25 +08:00
committed by GitHub
48 changed files with 801 additions and 660 deletions

View File

@@ -42,6 +42,7 @@
[frontend.handler.web.nfs :as nfs-handler]
[frontend.mobile.core :as mobile]
[frontend.mobile.util :as mobile-util]
[frontend.mobile.graph-picker :as graph-picker]
[frontend.modules.instrumentation.posthog :as posthog]
[frontend.modules.outliner.file :as outliner-file]
[frontend.modules.shortcut.core :as st]
@@ -173,10 +174,39 @@
"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 dir-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)))))))))
(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!
@@ -538,7 +568,9 @@
(defmethod handle :file-watcher/changed [[_ ^js event]]
(let [type (.-event event)
payload (-> event
(js->clj :keywordize-keys true))]
(js->clj :keywordize-keys true)
(update :path (fn [path]
(when (string? path) (capacitor-fs/remove-private-part path)))))]
(fs-watcher/handle-changed! type payload)
(when (file-sync-handler/enable-sync?)
(sync/file-watch-handler type payload))))
@@ -567,6 +599,24 @@
(state/close-modal!)
(nfs-handler/refresh! (state/get-current-repo) refresh-cb)))]]))
(defmethod handle :sync/create-remote-graph [[_ current-repo]]
(let [graph-name (js/decodeURI (util/node-path.basename current-repo))]
(async/go
(async/<! (sync/<sync-stop))
(state/set-state! [:ui/loading? :graph/create-remote?] true)
(when-let [GraphUUID (get (async/<! (file-sync-handler/create-graph graph-name)) 2)]
(async/<! (sync/<sync-start))
(state/set-state! [:ui/loading? :graph/create-remote?] false)
;; update existing repo
(state/set-repos! (map (fn [r]
(if (= (:url r) current-repo)
(assoc r
:GraphUUID GraphUUID
:GraphName graph-name
:remote? true)
r))
(state/get-repos)))))))
(defmethod handle :graph/re-index [[_]]
;; Ensure the graph only has ONE window instance
(repo-handler/re-index!
@@ -738,6 +788,16 @@
:warning
false))
(defmethod handle :graph/setup-a-repo [[_ opts]]
(let [opts' (merge {:picked-root-fn #(state/close-modal!)
:native-icloud? (not (string/blank? (state/get-icloud-container-root-url)))
:logged? (user-handler/logged-in?)} opts)]
(if (mobile-util/native-ios?)
(state/set-modal!
#(graph-picker/graph-picker-cp opts')
{:label "graph-setup"})
(page-handler/ls-dir-files! st/refresh! opts'))))
(defmethod handle :file/alter [[_ repo path content]]
(p/let [_ (file-handler/alter-file repo path content {:from-disk? true})]
(ui-handler/re-render-root!)))