enhance: add alerts before both refresh and re-index

pull/2793/head
Tienson Qin 2021-09-07 23:23:07 +08:00
parent d94ce5e78b
commit ce511e1b84
4 changed files with 46 additions and 14 deletions

View File

@ -230,13 +230,30 @@
(not= current-repo config/local-repo)
(nfs-handler/supported?))
[:a {:class "block px-4 py-2 text-sm transition ease-in-out duration-150 cursor menu-link"
:on-click #(nfs-handler/refresh! (state/get-current-repo) refresh-cb)}
:on-click (fn []
(state/pub-event!
[:modal/show
[:div {:style {:max-width 700}}
[:p "Refresh detects and processes files modified on your disk and diverged from the actual Logseq page content. Continue?"]
(ui/button
"Yes"
:on-click (fn []
(state/close-modal!)
(nfs-handler/refresh! (state/get-current-repo) refresh-cb)))]]))}
(t :sync-from-local-files)]))
[:a {:class "block px-4 py-2 text-sm transition ease-in-out duration-150 cursor menu-link"
:on-click (fn []
(repo-handler/re-index!
nfs-handler/rebuild-index!
page-handler/create-today-journal!))}
(state/pub-event!
[:modal/show
[:div {:style {:max-width 700}}
[:p "Re-index will discard the current graph, and then processes all the files again as they are currently stored on disk. You will lose unsaved changes and it might take a while. Continue?"]
(ui/button
"Yes"
:on-click (fn []
(state/close-modal!)
(repo-handler/re-index!
nfs-handler/rebuild-index!
page-handler/create-today-journal!)))]]))}
(t :re-index)]]}
(seq switch-repos)
(assoc :links-header [:div.font-medium.text-sm.opacity-70.px-4.py-2

View File

@ -48,7 +48,7 @@
get-page-referenced-blocks get-page-referenced-pages get-page-unlinked-references get-page-referenced-blocks-no-cache
get-all-pages get-pages get-pages-relation get-pages-that-mentioned-page get-public-pages get-tag-pages
journal-page? local-native-fs? mark-repo-as-cloned! page-alias-set page-blocks-transform pull-block
set-file-last-modified-at! transact-files-db! get-modified-pages page-empty? page-empty-or-dummy? get-alias-source-page
set-file-last-modified-at! transact-files-db! page-empty? page-empty-or-dummy? get-alias-source-page
set-file-content! has-children? get-namespace-pages get-all-namespace-relation]
[frontend.db.react

View File

@ -147,15 +147,6 @@
[?page :block/name]]
(conn/get-conn repo)))
(defn get-modified-pages
[repo]
(-> (d/q
'[:find ?page-name
:where
[?page :block/original-name ?page-name]]
(conn/get-conn repo))
(db-utils/seq-flatten)))
(defn get-page-alias
[repo page-name]
(when-let [conn (and repo (conn/get-conn repo))]
@ -1378,3 +1369,15 @@
'[:db/id :block/name :block/original-name
{:block/file [:db/id :file/path]}]
ids))))))
(defn get-latest-changed-pages
[repo]
(->>
(d/q
'[:find [(pull ?page [:block/name :block/file :block/updated-at]) ...]
:where
[?page :block/name]]
(conn/get-conn repo))
(filter :block/file)
(sort-by :block/updated-at >)
(take 200)))

View File

@ -10,6 +10,7 @@
[clojure.string :as string]
[frontend.config :as config]
[frontend.db :as db]
[frontend.db.model :as model]
[frontend.format :as format]
[frontend.fs :as fs]
[frontend.fs.nfs :as nfs]
@ -347,3 +348,14 @@
new-result (rewrite/assoc-in result ks v)]
(let [new-content (str new-result)]
(set-file-content! repo path new-content))))))
;; TODO:
;; (defn compare-latest-pages
;; []
;; (when-let [repo (state/get-current-repo)]
;; (doseq [{:block/keys [file name]} (db/get-latest-changed-pages repo)]
;; (when-let [path (:file/path (db/pull (:db/id file)))]
;; (p/let [content (load-file repo path)]
;; (when (not= (string/trim content) (string/trim (or (db/get-file repo path) "")))
;; ;; notify
;; ))))))