fix: remove hack $$property page

This commit is contained in:
Tienson Qin
2023-08-07 18:35:05 +08:00
parent 668a17c2af
commit fe9c082e5e
5 changed files with 48 additions and 23 deletions

View File

@@ -24,7 +24,8 @@
[cljs-time.coerce :as tc]
[clojure.set :as set]
[frontend.db-mixins :as db-mixins]
[frontend.handler.property.util :as pu]))
[frontend.handler.property.util :as pu]
[frontend.modules.outliner.core :as outliner-core]))
(rum/defc icon
[block {:keys [_type id]}] ; only :emoji supported yet
@@ -232,23 +233,19 @@
(case (util/ekey e)
"Enter"
(when not-matched?
(let [content (string/trim (util/evalue e))]
(let [repo (state/get-current-repo)
content (string/trim (util/evalue e))]
(when-not (string/blank? content)
(let [property-page config/property-page]
(when-not (db/entity [:block/name property-page])
(let [id (db/new-block-id)]
(db/transact! [{:block/uuid id
:block/name property-page
:block/original-name property-page
:block/type "page"
:block/created-at (util/time-ms)
:block/updated-at (util/time-ms)}])))
(let [new-block (editor-handler/api-insert-new-block! content
{:page property-page
:replace-empty-target? false})]
(when-let [id (:block/uuid new-block)]
(add-property! block (:block/original-name property) id))
(when-let [f (:on-chosen opts)] (f)))))))
(let [new-block (-> (editor-handler/wrap-parse-block {:block/format :markdown
:block/content content})
(outliner-core/block-with-timestamps)
(assoc :block/page {:db/id
(or (:db/id (:block/page block))
(:db/id block))}))
id (:block/uuid new-block)]
(db/transact! repo [new-block] {:outliner-op :insert-blocks})
(add-property! block (:block/original-name property) id)
(when-let [f (:on-chosen opts)] (f))))))
"Escape"
(do (exit-edit-property)
(when-let [f (:on-chosen opts)] (f)))

View File

@@ -369,7 +369,6 @@
(defonce local-db-prefix "logseq_local_")
(defonce local-handle "handle")
(defonce db-version-prefix "logseq_db_")
(defonce property-page "$$property")
(defn local-file-based-graph?
[s]

View File

@@ -4,6 +4,7 @@
[datascript.core :as d]
[electron.ipc :as ipc]
[frontend.config :as config]
[frontend.db :as db]
[frontend.db.conn :as db-conn]
[frontend.db.migrate :as db-migrate]
[frontend.db.persist :as db-persist]
@@ -15,7 +16,9 @@
[logseq.db.sqlite.restore :as sqlite-restore]
[promesa.core :as p]
[frontend.util :as util]
[cljs-time.core :as t]))
[cljs-time.core :as t]
[frontend.modules.outliner.core :as outliner-core]
[logseq.graph-parser.property :as gp-property]))
(defn- old-schema?
"Requires migration if the schema version is older than db-schema/version"
@@ -62,6 +65,26 @@
(conj! unloaded-block-ids (gobj/get b "uuid") (gobj/get b "page_uuid")))
(state/set-state! [repo :restore/unloaded-blocks] (persistent! unloaded-block-ids)))))
(defn- update-built-in-properties!
[conn]
(let [txs (keep
(fn [[k-keyword {:keys [schema original-name]}]]
(let [k-name (name k-keyword)]
(let [property (d/entity @conn [:block/name k-name])]
(when-not (= {:schema schema
:original-name original-name}
{:schema (:block/schema property)
:original-name (:block/original-name property)})
(outliner-core/block-with-timestamps
{:block/schema schema
:block/original-name (or original-name k-name)
:block/name (util/page-name-sanity-lc k-name)
:block/uuid (db/new-block-id)
:block/type "property"})))))
gp-property/db-built-in-properties)]
(when (seq txs)
(d/transact! conn txs))))
(defn- restore-other-data-from-sqlite!
[repo data uuid->db-id-map]
(let [start (util/time-ms)
@@ -74,6 +97,8 @@
(reset! conn new-db)
(update-built-in-properties! conn)
(let [end (util/time-ms)]
(println "[debug] load others from SQLite: " (int (- end start)) " ms."))

View File

@@ -29,8 +29,7 @@
(defn- logseq-block?
[id]
(and (uuid? id)
(when-let [e (db/entity [:block/uuid id])]
(some? (:block/page e)))))
(some? (db/entity [:block/uuid id]))))
(defn- logseq-object?
[id]

View File

@@ -59,7 +59,8 @@
[logseq.graph-parser.util.block-ref :as block-ref]
[logseq.graph-parser.util.page-ref :as page-ref]
[promesa.core :as p]
[rum.core :as rum]))
[rum.core :as rum]
[frontend.handler.db-based.property :as db-property]))
;; FIXME: should support multiple images concurrently uploading
@@ -481,7 +482,8 @@
sibling? (if before? true (if page false sibling?))
block (if page
(db/entity [:block/name (util/page-name-sanity-lc page)])
(db/entity [:block/uuid block-uuid]))]
(db/entity [:block/uuid block-uuid]))
db-based? (config/db-based-graph? repo)]
(when block
(let [last-block (when (not sibling?)
(let [children (:block/_parent block)
@@ -507,6 +509,9 @@
new-block (-> new-block
(wrap-parse-block)
(assoc :block/uuid (or custom-uuid (db/new-block-id))))
new-block (if (and db-based? (seq properties))
(assoc new-block :block/properties (db-property/replace-key-with-id! properties))
new-block)
[block-m sibling?] (cond
before?
(let [first-child? (->> [:block/parent :block/left]