Merge remote-tracking branch 'upstream/master' into whiteboards

This commit is contained in:
Peng Xiao
2022-10-08 17:26:45 +08:00
48 changed files with 1176 additions and 315 deletions

View File

@@ -122,6 +122,8 @@
(defmethod handle :graph/refresh [_]
(repo-handler/refresh-repos!))
;; FIXME: awful multi-arty function.
;; Should use a `-impl` function instead of the awful `skip-ios-check?` param with nested callback.
(defn- graph-switch
([graph]
(graph-switch graph false))
@@ -142,6 +144,7 @@
(repo-handler/refresh-repos!)
(file-sync-restart!)))))
;; Parameters for the `persist-db` function, to show the notification messages
(def persist-db-noti-m
{:before #(notification/show!
(ui/loading (t :graph/persist))
@@ -152,7 +155,8 @@
(defn- graph-switch-on-persisted
"Logic for keeping db sync when switching graphs
Only works for electron"
Only works for electron
graph: the target graph to switch to"
[graph {:keys [persist?]}]
(let [current-repo (state/get-current-repo)]
(p/do!
@@ -321,13 +325,16 @@
(p/let [content (when content (encrypt/decrypt content))]
(state/set-modal! #(git-component/file-specific-version path hash content))))
(defmethod handle :graph/ready [[_ repo]]
;; Hook on a graph is ready to be shown to the user.
;; It's different from :graph/resotred, as :graph/restored is for window reloaded
(defmethod handle :graph/ready
[[_ repo]]
(when (config/local-db? repo)
(p/let [dir (config/get-repo-dir repo)
dir-exists? (fs/dir-exists? dir)]
(p/let [dir (config/get-repo-dir repo)
dir-exists? (fs/dir-exists? dir)]
(when-not dir-exists?
(state/pub-event! [:graph/dir-gone dir]))))
(search-handler/rebuild-indices-when-stale! repo)
;; FIXME: an ugly implementation for redirecting to page on new window is restored
(repo-handler/graph-ready! repo))
(defmethod handle :notification/show [[_ {:keys [content status clear?]}]]
@@ -417,7 +424,7 @@
(set! (.. right-sidebar-node -style -paddingBottom) "150px")))))
(defn update-file-path [deprecated-repo current-repo deprecated-app-id current-app-id]
(let [files (db-model/get-files-v2 deprecated-repo)
(let [files (db-model/get-files-entity deprecated-repo)
conn (conn/get-db deprecated-repo false)
tx (mapv (fn [[id path]]
(let [new-path (string/replace path deprecated-app-id current-app-id)]
@@ -563,15 +570,26 @@
(state/close-modal!)
(nfs-handler/refresh! (state/get-current-repo) refresh-cb)))]]))
(defmethod handle :graph/ask-for-re-index [[_ *multiple-windows?]]
(defmethod handle :graph/re-index [[_]]
;; Ensure the graph only has ONE window instance
(repo-handler/re-index!
nfs-handler/rebuild-index!
#(do (page-handler/create-today-journal!)
(file-sync-restart!))))
(defmethod handle :graph/ask-for-re-index [[_ *multiple-windows? ui]]
;; *multiple-windows? - if the graph is opened in multiple windows, boolean atom
;; ui - custom message to show on asking for re-index
(if (and (util/atom? *multiple-windows?) @*multiple-windows?)
(handle
[:modal/show
[:div
(when (not (nil? ui)) ui)
[:p (t :re-index-multiple-windows-warning)]]])
(handle
[:modal/show
[:div {:style {:max-width 700}}
(when (not (nil? ui)) ui)
[:p (t :re-index-discard-unsaved-changes-warning)]
(ui/button
(t :yes)
@@ -580,9 +598,7 @@
:large? true
:on-click (fn []
(state/close-modal!)
(repo-handler/re-index!
nfs-handler/rebuild-index!
page-handler/create-today-journal!)))]])))
(state/pub-event! [:graph/re-index])))]])))
;; encryption
(defmethod handle :modal/encryption-setup-dialog [[_ repo-url close-fn]]