|
|
@@ -3,9 +3,7 @@
|
|
|
application"
|
|
|
(:require [frontend.state :as state]
|
|
|
[frontend.colors :as colors]
|
|
|
- [datascript.core :as d]
|
|
|
[frontend.db :as db]
|
|
|
- [frontend.db.conn :as conn]
|
|
|
[rum.core :as rum]
|
|
|
[frontend.handler.route :as route-handler]
|
|
|
[frontend.page :as page]
|
|
|
@@ -22,7 +20,14 @@
|
|
|
[frontend.components.whiteboard :as whiteboard]
|
|
|
[frontend.modules.shortcut.core :as shortcut]
|
|
|
[frontend.handler.events :as events]
|
|
|
- [frontend.handler.command-palette :as command-palette]))
|
|
|
+ [frontend.handler.command-palette :as command-palette]
|
|
|
+ [frontend.persist-db.browser :as db-browser]
|
|
|
+ [promesa.core :as p]
|
|
|
+ [frontend.handler.repo :as repo-handler]
|
|
|
+ [datascript.core :as d]
|
|
|
+ [frontend.handler.ui :as ui-handler]
|
|
|
+ [frontend.storage :as storage]
|
|
|
+ [frontend.db.persist :as db-persist]))
|
|
|
|
|
|
;; The publishing site should be as thin as possible.
|
|
|
;; Both files and git libraries can be removed.
|
|
|
@@ -51,15 +56,29 @@
|
|
|
(defn restore-from-transit-str!
|
|
|
[]
|
|
|
;; Client sets repo name (and graph type) based on what was written in app state
|
|
|
- (let [repo-name (-> @state/state :config keys first)]
|
|
|
- (state/set-current-repo! repo-name)
|
|
|
+ (when-let [data js/window.logseq_db]
|
|
|
+ (let [repo (-> @state/state :config keys first)]
|
|
|
+ (state/set-current-repo! repo)
|
|
|
+ (p/do!
|
|
|
+ (p/let [cached-data-length (storage/get :db-cached-str-length)]
|
|
|
+ (when (nil? cached-data-length)
|
|
|
+ (storage/set :db-cached-str-length (count data)))
|
|
|
+ (when (and cached-data-length (not= cached-data-length (count data)))
|
|
|
+ ;; delete old graph after re-published
|
|
|
+ (db-persist/delete-graph! repo)))
|
|
|
+
|
|
|
+ (repo-handler/restore-and-setup-repo! repo)
|
|
|
|
|
|
- (when-let [data js/window.logseq_db]
|
|
|
- (let [data (unescape-html data)
|
|
|
- db-conn (d/create-conn (conn/get-schema (state/get-current-repo)))
|
|
|
- _ (swap! db/conns assoc (str "logseq-db/" repo-name) db-conn)
|
|
|
- db (db/string->db data)]
|
|
|
- (reset! db-conn db)))))
|
|
|
+ (when-not (db/entity :db/transacted?)
|
|
|
+ (let [data (unescape-html data)
|
|
|
+ db (db/string->db data)
|
|
|
+ datoms (d/datoms db :eavt)]
|
|
|
+ (db/transact! repo
|
|
|
+ (conj (vec datoms)
|
|
|
+ {:db/ident :db/transacted? :db/transacted? true})
|
|
|
+ {:init-db? true
|
|
|
+ :new-graph? true})))
|
|
|
+ (ui-handler/re-render-root!)))))
|
|
|
|
|
|
(defn restore-state!
|
|
|
[]
|
|
|
@@ -99,10 +118,12 @@
|
|
|
(restore-state!)
|
|
|
(when-let [radix-color (state/get-color-accent)]
|
|
|
(colors/set-radix radix-color))
|
|
|
- (restore-from-transit-str!)
|
|
|
(shortcut/refresh!)
|
|
|
(events/run!)
|
|
|
- (start))
|
|
|
+ (p/do!
|
|
|
+ (db-browser/start-db-worker!)
|
|
|
+ (start)
|
|
|
+ (restore-from-transit-str!)))
|
|
|
|
|
|
(defn stop []
|
|
|
;; stop is called before any code is reloaded
|