Browse Source

feat: add shortcut mod-c mod-r to re-index the graph

Tienson Qin 4 years ago
parent
commit
ba8055f748

+ 1 - 8
src/main/frontend/components/repo.cljs

@@ -64,14 +64,7 @@
                                       "Sync with the local directory"
                                       "Clone again and re-index the db")
                              :on-click (fn []
-                                         (if local?
-                                           (nfs-handler/rebuild-index! url
-                                                                       repo-handler/create-today-journal!)
-                                           (repo-handler/rebuild-index! url))
-                                         (js/setTimeout
-                                          (fn []
-                                            (route-handler/redirect! {:to :home}))
-                                          500))}
+                                         (repo-handler/re-index! nfs-handler/rebuild-index!))}
                  "Re-index"]
                 [:a.control.ml-4 {:title "Clone again and re-index the db"
                                   :on-click (fn []

+ 3 - 0
src/main/frontend/db_schema.cljs

@@ -61,6 +61,9 @@
    ;; referenced pages
    :block/ref-pages {:db/valueType   :db.type/ref
                      :db/cardinality :db.cardinality/many}
+   ;; referenced pages inherited from the parents
+   :block/path-ref-pages {:db/valueType   :db.type/ref
+                          :db/cardinality :db.cardinality/many}
 
    ;; Referenced pages
    ;; Notice: it's only for org mode, :tag1:tag2:

+ 12 - 0
src/main/frontend/handler/repo.cljs

@@ -650,6 +650,18 @@
         (p/catch (fn [error]
                    (prn "Delete repo failed, error: " error))))))
 
+(defn re-index!
+  [nfs-rebuild-index!]
+  (when-let [repo (state/get-current-repo)]
+    (let [local? (config/local-db? repo)]
+      (if local?
+        (nfs-rebuild-index! repo create-today-journal!)
+        (rebuild-index! repo))
+      (js/setTimeout
+       (fn []
+         (route-handler/redirect! {:to :home}))
+       500))))
+
 (defn git-commit-and-push!
   [commit-message]
   (when-let [repo (state/get-current-repo)]

+ 7 - 0
src/main/frontend/keyboards.cljs

@@ -5,6 +5,8 @@
             [frontend.handler.route :as route-handler]
             [frontend.handler.search :as search-handler]
             [frontend.handler.config :as config-handler]
+            [frontend.handler.repo :as repo-handler]
+            [frontend.handler.web.nfs :as nfs-handler]
             [frontend.state :as state]
             [frontend.search :as search]
             [frontend.util :as util]
@@ -30,6 +32,8 @@
 
 (def shortcut state/get-shortcut)
 
+(def re-index! #(repo-handler/re-index! nfs-handler/rebuild-index!))
+
 (defonce chords
   {
    ;; non-editing mode
@@ -75,6 +79,9 @@
    (or (shortcut :editor/prev) "up") (fn [state e] (editor-handler/open-block! false))
 
    (or (shortcut :search/re-index) "mod+c mod+s") [search-handler/rebuild-indices! true]
+
+   (or (shortcut :graph/re-index) "mod+c mod+r") [re-index! true]
+
    (or (shortcut :ui/toggle-brackets) "mod+c mod+b") [config-handler/toggle-ui-show-brackets! true]})
 
 (defonce bind! (gobj/get mousetrap "bind"))