|
|
@@ -16,6 +16,7 @@
|
|
|
[frontend.handler.common.file :as file-common-handler]
|
|
|
[frontend.handler.route :as route-handler]
|
|
|
[frontend.handler.ui :as ui-handler]
|
|
|
+ [frontend.handler.notification :as notification]
|
|
|
[frontend.handler.global-config :as global-config-handler]
|
|
|
[frontend.idb :as idb]
|
|
|
[frontend.search :as search]
|
|
|
@@ -344,16 +345,14 @@
|
|
|
[{:keys [url] :as repo}]
|
|
|
(let [db-based? (config/db-based-graph? url)
|
|
|
delete-db-f (fn []
|
|
|
- (let [graph-exists? (db/get-db url)
|
|
|
- current-repo (state/get-current-repo)]
|
|
|
+ (let [current-repo (state/get-current-repo)]
|
|
|
(db/remove-conn! url)
|
|
|
(db-persist/delete-graph! url)
|
|
|
(search/remove-db! url)
|
|
|
(state/delete-repo! repo)
|
|
|
- (when graph-exists? (ipc/ipc "graphUnlinked" repo))
|
|
|
(when (= current-repo url)
|
|
|
(when-let [graph (:url (first (state/get-repos)))]
|
|
|
- (state/pub-event! [:graph/switch graph {}])))))]
|
|
|
+ (state/pub-event! [:graph/switch graph {:persist? false}])))))]
|
|
|
(when (or (config/local-file-based-graph? url)
|
|
|
db-based?
|
|
|
(config/demo-graph? url))
|
|
|
@@ -532,21 +531,25 @@
|
|
|
(ipc/ipc "graphReady" graph)))
|
|
|
|
|
|
(defn- create-db [full-graph-name]
|
|
|
- (p/let [_ (persist-db/<new full-graph-name)
|
|
|
- _ (op-mem-layer/<init-load-from-indexeddb! full-graph-name)
|
|
|
- _ (start-repo-db-if-not-exists! full-graph-name)
|
|
|
- _ (state/add-repo! {:url full-graph-name})
|
|
|
- _ (route-handler/redirect-to-home!)
|
|
|
- _ (db/transact! full-graph-name [(react/kv :db/type "db")
|
|
|
- (react/kv :schema/version db-schema/version {:id -2})])
|
|
|
- initial-data (sqlite-create-graph/build-db-initial-data config/config-default-content)
|
|
|
- _ (db/transact! full-graph-name initial-data)
|
|
|
- _ (repo-config-handler/set-repo-config-state! full-graph-name config/config-default-content)
|
|
|
+ (->
|
|
|
+ (p/let [_ (persist-db/<new full-graph-name)
|
|
|
+ _ (op-mem-layer/<init-load-from-indexeddb! full-graph-name)
|
|
|
+ _ (start-repo-db-if-not-exists! full-graph-name)
|
|
|
+ _ (state/add-repo! {:url full-graph-name})
|
|
|
+ _ (route-handler/redirect-to-home!)
|
|
|
+ _ (db/transact! full-graph-name [(react/kv :db/type "db")
|
|
|
+ (react/kv :schema/version db-schema/version {:id -2})])
|
|
|
+ initial-data (sqlite-create-graph/build-db-initial-data config/config-default-content)
|
|
|
+ _ (db/transact! full-graph-name initial-data)
|
|
|
+ _ (repo-config-handler/set-repo-config-state! full-graph-name config/config-default-content)
|
|
|
;; TODO: handle global graph
|
|
|
- _ (state/pub-event! [:init/commands])
|
|
|
- _ (state/pub-event! [:page/create (date/today) {:redirect? false}])]
|
|
|
- (js/setTimeout ui-handler/re-render-root! 100)
|
|
|
- (prn "New db created: " full-graph-name)))
|
|
|
+ _ (state/pub-event! [:init/commands])
|
|
|
+ _ (state/pub-event! [:page/create (date/today) {:redirect? false}])]
|
|
|
+ (js/setTimeout ui-handler/re-render-root! 100)
|
|
|
+ (prn "New db created: " full-graph-name))
|
|
|
+ (p/catch (fn [error]
|
|
|
+ (notification/show! "Create graph failed." :error)
|
|
|
+ (js/console.error error)))))
|
|
|
|
|
|
(defn new-db!
|
|
|
"Handler for creating a new database graph"
|