fix: prompt to create a Logseq sync graph or normal graph on iOS

Previously, users can create a graph everywhere including the iCloud
folder, which is both confusing and can cause unexpected data
conflicts.

Another enhancement:
After the user confirms the "Use Logseq Sync for this new graph?"
prompt, a remote graph will be created and start to sync automatically.

https://www.loom.com/share/69059969747c4b798a4c712c45e442d7
This commit is contained in:
Tienson Qin
2022-11-02 13:18:11 +08:00
parent 2dfac3d774
commit 7ddfa66004
11 changed files with 92 additions and 36 deletions

View File

@@ -572,6 +572,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!