diff --git a/src/main/frontend/db/model.cljs b/src/main/frontend/db/model.cljs index e16e39cc2..ad60e8796 100644 --- a/src/main/frontend/db/model.cljs +++ b/src/main/frontend/db/model.cljs @@ -1625,25 +1625,31 @@ (remove nil?))] orphaned-pages)) - (defn- block->shape [block] - (let [properties (:block/properties block)] - (merge block - properties + (let [properties (:block/properties block) + uuid (str (:block/uuid block))] + (merge properties ;; Use the block's id as the shape's id. - {:id (str (:block/uuid block))}))) + {:id uuid}))) -(defn- shape->block [shape] +(defn- shape->block [shape page-name] (let [properties shape] - {:block/uuid (uuid (:id shape)) + {:block/uuid (uuid (:id properties)) + :block/page {:block/name page-name} :block/properties properties})) (defn- tldr-page->blocks-tx [page-name tldr-data] - (let [shapes (mapv shape->block (:shapes tldr-data)) - page-block {:block/name page-name + (let [page-block {:block/name page-name :block/whiteboard? true - :block/properties (dissoc tldr-data :shapes)}] - (cons page-block shapes))) + :block/properties (dissoc tldr-data :shapes)} + existing-blocks (get-page-blocks-no-cache page-name) + blocks (mapv #(shape->block % page-name) (:shapes tldr-data)) + block-ids (set (map :block/uuid blocks)) + delete-shapes (filter (fn [shape] + (not (block-ids (:block/uuid shape)))) + existing-blocks) + delete-shapes-tx (mapv (fn [s] [:db/retractEntity (:db/id s)]) delete-shapes)] + (concat [page-block] blocks delete-shapes-tx))) (defn- get-whiteboard-clj [page-name] (let [page-block (get-page page-name) @@ -1654,7 +1660,7 @@ (let [shapes (map block->shape blocks) page-name (:block/name page-block) page-properties (:block/properties page-block)] - (clj->js {:currentPageId page-name + (clj->js {:currentPageId "page" :pages [(merge page-properties {:id "page" :name "page" @@ -1667,5 +1673,4 @@ (defn transact-tldr! [page-name tldr] (let [{:keys [pages]} (js->clj tldr :keywordize-keys true) tx (tldr-page->blocks-tx page-name (first pages))] - (println tx) (db-utils/transact! tx))) diff --git a/src/main/frontend/modules/file/core.cljs b/src/main/frontend/modules/file/core.cljs index 628340b25..66ade98db 100644 --- a/src/main/frontend/modules/file/core.cljs +++ b/src/main/frontend/modules/file/core.cljs @@ -119,6 +119,7 @@ (state/get-preferred-format))) title (string/capitalize (:block/name page)) whiteboard-page? (:block/whiteboard? page) + format (if whiteboard-page? "edn" format) journal-page? (date/valid-journal-title? title) filename (if journal-page? (date/date->file-name journal-page?)