config.edn changes should update repo config state

Porting over more alter-file behavior
pull/10016/head
Gabriel Horner 2023-06-26 15:01:31 -04:00
parent f9c202c284
commit e8803f6a97
1 changed files with 18 additions and 9 deletions

View File

@ -6,11 +6,14 @@
[frontend.format.block :as block] [frontend.format.block :as block]
[frontend.format.mldoc :as mldoc] [frontend.format.mldoc :as mldoc]
[frontend.util :as util] [frontend.util :as util]
[frontend.state :as state]
[logseq.graph-parser.mldoc :as gp-mldoc] [logseq.graph-parser.mldoc :as gp-mldoc]
[logseq.graph-parser.util.page-ref :as page-ref] [logseq.graph-parser.util.page-ref :as page-ref]
[frontend.handler.ui :as ui-handler] [frontend.handler.ui :as ui-handler]
[frontend.handler.common.config-edn :as config-edn-common-handler] [frontend.handler.common.config-edn :as config-edn-common-handler]
[frontend.schema.handler.repo-config :as repo-config-schema])) [frontend.handler.repo-config :as repo-config-handler]
[frontend.schema.handler.repo-config :as repo-config-schema]
[promesa.core :as p]))
(defn- remove-non-existed-refs! (defn- remove-non-existed-refs!
[refs] [refs]
@ -87,13 +90,19 @@
result)) result))
(defn save-file! (defn save-file!
"This fn is the db version of file-handler/alter-file"
[path content] [path content]
(when path ;; Pre save
(when (= path "logseq/config.edn") (when (= path "logseq/config.edn")
(config-edn-common-handler/detect-deprecations path content) (config-edn-common-handler/detect-deprecations path content)
(config-edn-common-handler/validate-config-edn path content repo-config-schema/Config-edn)) (config-edn-common-handler/validate-config-edn path content repo-config-schema/Config-edn))
(db/transact! [{:file/path path (db/transact! [{:file/path path
:file/content content}]) :file/content content}])
(when (= path "logseq/custom.css")
(ui-handler/add-style-if-exists!)))) ;; Post save
(cond (= path "logseq/config.edn")
(p/let [_ (repo-config-handler/restore-repo-config! (state/get-current-repo) content)]
(state/pub-event! [:shortcut/refresh]))
(= path "logseq/custom.css")
(ui-handler/add-style-if-exists!)))