Browse Source

fix most issues on whiteboards

Tienson Qin 1 year ago
parent
commit
1f32893547

+ 16 - 26
deps/graph-parser/src/logseq/graph_parser/whiteboard.cljs

@@ -1,9 +1,6 @@
 (ns logseq.graph-parser.whiteboard
   "Whiteboard related parser utilities"
-  (:require [logseq.common.util :as common-util]
-            [logseq.common.util.block-ref :as block-ref]
-            [logseq.common.util.page-ref :as page-ref]
-            [logseq.db.frontend.property :as db-property]))
+  (:require [logseq.db.frontend.property :as db-property]))
 
 (defn block->shape [block]
   (get-in block [:block/properties :logseq.tldraw.shape]))
@@ -42,22 +39,19 @@
 
 (defn- get-shape-refs [shape]
   (let [portal-refs (when (= "logseq-portal" (:type shape))
-                      [(if (= (:blockType shape) "P")
-                         {:block/name (common-util/page-name-sanity-lc (:pageId shape))}
-                         {:block/uuid (uuid (:pageId shape))})])
+                      [{:block/uuid (uuid (:pageId shape))}])
         shape-link-refs (->> (:refs shape)
                              (filter (complement empty?))
-                             (map (fn [ref] (if (parse-uuid ref)
-                                              {:block/uuid (parse-uuid ref)}
-                                              {:block/name (common-util/page-name-sanity-lc ref)}))))]
+                             (keep (fn [ref] (when (parse-uuid ref)
+                                              {:block/uuid (parse-uuid ref)}))))]
     (concat portal-refs shape-link-refs)))
 
 (defn- with-whiteboard-block-refs
-  [shape page-name]
+  [shape page-id]
   (let [refs (or (get-shape-refs shape) [])]
     (merge {:block/refs (if (seq refs) refs [])
             :block/path-refs (if (seq refs)
-                               (conj refs {:block/name page-name})
+                               (conj refs page-id)
                                [])})))
 
 (defn- with-whiteboard-content
@@ -65,37 +59,33 @@
   [shape]
   {:block/content (case (:type shape)
                     "text" (:text shape)
-                    "logseq-portal" (if (= (:blockType shape) "P")
-                                      (page-ref/->page-ref (:pageId shape))
-                                      (block-ref/->block-ref (:pageId shape)))
+                    "logseq-portal" ""
                     "line" (str "whiteboard arrow" (when-let [label (:label shape)] (str ": " label)))
                     (str "whiteboard " (:type shape)))})
 
 (defn with-whiteboard-block-props
   "Builds additional block attributes for a whiteboard block. Expects :block/properties
    to be in file graph format"
-  [block page-name]
+  [block page-id]
   (let [shape? (shape-block? block)
-        shape (block->shape block)
-        default-page-ref {:block/name page-name}]
+        shape (block->shape block)]
     (merge (when shape?
              (merge
               {:block/uuid (uuid (:id shape))}
-              (with-whiteboard-block-refs shape page-name)
+              (with-whiteboard-block-refs shape page-id)
               (with-whiteboard-content shape)))
-           (when (nil? (:block/parent block)) {:block/parent default-page-ref})
+           (when (nil? (:block/parent block)) {:block/parent page-id})
            (when (nil? (:block/format block)) {:block/format :markdown}) ;; TODO: read from config
-           {:block/page default-page-ref})))
+           {:block/page page-id})))
 
-(defn shape->block [repo shape page-name]
+(defn shape->block [repo shape page-id]
   (let [properties {(db-property/get-pid repo :logseq.property/ls-type) :whiteboard-shape
                     (db-property/get-pid repo :logseq.property.tldraw/shape) shape}
-        page-name (common-util/page-name-sanity-lc page-name)
         block {:block/uuid (if (uuid? (:id shape)) (:id shape) (uuid (:id shape)))
-               :block/page {:block/name page-name}
-               :block/parent {:block/name page-name}
+               :block/page page-id
+               :block/parent page-id
                :block/properties properties}
         additional-props (with-whiteboard-block-props
                            (assoc block :block/properties {:ls-type :whiteboard-shape :logseq.tldraw.shape shape})
-                           page-name)]
+                           page-id)]
     (merge block additional-props)))

+ 11 - 11
src/main/frontend/components/block.cljs

@@ -864,17 +864,17 @@
                     page-name)
               (not= (util/page-name-sanity-lc (get config :id ""))
                     page-name))
-         (if whiteboard-page?
-           ((state/get-component :whiteboard/tldraw-preview) page-name)
-           (let [block (model/get-page page-name)
-                 block (db/sub-block (:db/id block))
-                 blocks (db/sort-by-left (:block/_parent block) block)]
-             (blocks-container blocks (assoc config
-                                             :db/id (:db/id block)
-                                             :id page-name
-                                             :embed? true
-                                             :page-embed? true
-                                             :ref? false))))))]))
+         (let [block (model/get-page page-name)
+               block (db/sub-block (:db/id block))]
+           (if whiteboard-page?
+             ((state/get-component :whiteboard/tldraw-preview) (:block/uuid block))
+             (let [blocks (db/sort-by-left (:block/_parent block) block)]
+               (blocks-container blocks (assoc config
+                                               :db/id (:db/id block)
+                                               :id page-name
+                                               :embed? true
+                                               :page-embed? true
+                                               :ref? false)))))))]))
 
 (defn- get-label-text
   [label]

+ 6 - 5
src/main/frontend/components/container.cljs

@@ -907,7 +907,8 @@
         onboarding-state (state/sub :file-sync/onboarding-state)
         right-sidebar-blocks (state/sub-right-sidebar-blocks)
         route-name (get-in route-match [:data :name])
-        margin-less-pages? (boolean (#{:graph :whiteboard} route-name))
+        margin-less-pages? (or (boolean (#{:graph} route-name))
+                               (db-model/whiteboard-page? (state/get-current-page)))
         db-restoring? (state/sub :db/restoring?)
         indexeddb-support? (state/sub :indexeddb/support?)
         page? (= :page route-name)
@@ -997,10 +998,10 @@
       (select/select-modal)
       (custom-context-menu)
       (plugins/custom-js-installer
-        {:t t
-         :current-repo current-repo
-         :nfs-granted? granted?
-         :db-restoring? db-restoring?})
+       {:t t
+        :current-repo current-repo
+        :nfs-granted? granted?
+        :db-restoring? db-restoring?})
       (app-context-menu-observer)
 
       [:a#download.hidden]

+ 5 - 5
src/main/frontend/components/page.cljs

@@ -82,11 +82,11 @@
   [state]
   (let [[_ block _ sidebar? preview?] (:rum/args state)]
     (when (and
-            (or preview?
-              (not (contains? #{:home :all-journals :whiteboard} (state/get-current-route))))
-            (not sidebar?))
+           (or preview?
+               (not (contains? #{:home :all-journals} (state/get-current-route))))
+           (not sidebar?))
       (when (and (string/blank? (:block/content block))
-              (not preview?))
+                 (not preview?))
         (editor-handler/edit-block! block :max (:block/uuid block)))))
   state)
 
@@ -481,7 +481,7 @@
                        :class (util/classnames [{:is-journals (or journal? fmt-journal?)}])})
 
                (if (and whiteboard-page? (not sidebar?))
-                 [:div ((state/get-component :whiteboard/tldraw-preview) page-name)] ;; FIXME: this is not reactive
+                 [:div ((state/get-component :whiteboard/tldraw-preview) (:block/uuid page))] ;; FIXME: this is not reactive
                  [:div.relative
                   (when (and (not sidebar?) (not block?))
                     [:div.flex.flex-row.space-between

+ 1 - 3
src/main/frontend/components/right_sidebar.cljs

@@ -220,9 +220,7 @@
      (when (= type :page)
        (let [page  (db/entity db-id)
              name (:block/name page)]
-         (menu-item {:href (if (db-model/whiteboard-page? page)
-                             (rfe/href :whiteboard {:name name})
-                             (rfe/href :page {:name name}))} (t :right-side-bar/pane-open-as-page)))))))
+         (menu-item {:href (rfe/href :page {:name name})} (t :right-side-bar/pane-open-as-page)))))))
 
 (rum/defc drop-indicator
   [idx drag-to]

+ 53 - 59
src/main/frontend/components/whiteboard.cljs

@@ -31,27 +31,28 @@
            (p/let [_ (loader/load :tldraw)]
              (reset! tldraw-loaded? true))
            state)}
-  [name shape-id]
+  [page-uuid shape-id]
   (let [loaded? (rum/react tldraw-loaded?)
         draw-component (when loaded?
                          (resolve 'frontend.extensions.tldraw/tldraw-app))]
     (when draw-component
-      (draw-component name shape-id))))
+      (draw-component page-uuid shape-id))))
 
 (rum/defc tldraw-preview < rum/reactive
   {:init (fn [state]
            (p/let [_ (loader/load :tldraw)]
              (reset! tldraw-loaded? true))
-           (let [page-name (first (:rum/args state))]
-             (db-async/<get-block (state/get-current-repo) page-name))
+           (let [page-uuid (first (:rum/args state))]
+             (db-async/<get-block (state/get-current-repo) page-uuid))
            state)}
-  [page-name]
-  (let [loaded? (rum/react tldraw-loaded?)
-        tldr (whiteboard-handler/page-name->tldr! page-name)
-        generate-preview (when loaded?
-                           (resolve 'frontend.extensions.tldraw/generate-preview))]
-    (when (and generate-preview (not (state/sub-async-query-loading page-name)))
-      (generate-preview tldr))))
+  [page-uuid]
+  (when page-uuid
+    (let [loaded? (rum/react tldraw-loaded?)
+          tldr (whiteboard-handler/get-page-tldr page-uuid)
+          generate-preview (when loaded?
+                             (resolve 'frontend.extensions.tldraw/generate-preview))]
+      (when (and generate-preview (not (state/sub-async-query-loading page-uuid)))
+        (generate-preview tldr)))))
 
 ;; TODO: use frontend.ui instead of making a new one
 (rum/defc dropdown
@@ -123,37 +124,30 @@
                                         hover?
                                         portal?]
                                  :or {portal? true}}]
-   (let [page-entity (model/get-page page-name-or-uuid)
-         page (model/sub-block (:db/id page-entity))
-         block-uuid (:block/uuid page-entity)
-         refs-count (count (:block/_refs page))]
-     (when (> refs-count 0)
-       (dropdown-menu {:classname classname
-                       :label (fn [open?]
-                                [:div.inline-flex.items-center.gap-2
-                                 [:div.open-page-ref-link refs-count]
-                                 (when render-fn (render-fn open? refs-count))])
-                       :hover? hover?
-                       :portal? portal?
-                       :children (reference/block-linked-references block-uuid)})))))
-
-(defn- get-page-display-name
-  [page-name]
-  (let [page-entity (model/get-page page-name)]
-    (or
-     (:block/original-name page-entity)
-     page-name)))
+   (when page-name-or-uuid
+     (let [page-entity (model/get-page page-name-or-uuid)
+           page (model/sub-block (:db/id page-entity))
+           block-uuid (:block/uuid page-entity)
+           refs-count (count (:block/_refs page))]
+       (when (> refs-count 0)
+         (dropdown-menu {:classname classname
+                         :label (fn [open?]
+                                  [:div.inline-flex.items-center.gap-2
+                                   [:div.open-page-ref-link refs-count]
+                                   (when render-fn (render-fn open? refs-count))])
+                         :hover? hover?
+                         :portal? portal?
+                         :children (reference/block-linked-references block-uuid)}))))))
 
 ;; This is not accurate yet
 (defn- get-page-human-update-time
-  [page-name]
-  (let [page-entity (model/get-page page-name)
-        {:block/keys [updated-at created-at]} page-entity]
+  [page]
+  (let [{:block/keys [updated-at created-at]} page]
     (str (if (= created-at updated-at) (t :whiteboard/dashboard-card-created) (t :whiteboard/dashboard-card-edited))
          (util/time-ago (js/Date. updated-at)))))
 
 (rum/defc dashboard-preview-card
-  [page-name {:keys [checked on-checked-change show-checked?]}]
+  [whiteboard {:keys [checked on-checked-change show-checked?]}]
   [:div.dashboard-card.dashboard-preview-card.cursor-pointer.hover:shadow-lg
    {:data-checked checked
     :style {:filter (if (and show-checked? (not checked)) "opacity(0.5)" "none")}
@@ -162,13 +156,13 @@
       (util/stop e)
       (if show-checked?
         (on-checked-change (not checked))
-        (route-handler/redirect-to-page! page-name)))}
+        (route-handler/redirect-to-page! (:block/uuid whiteboard))))}
    [:div.dashboard-card-title
     [:div.flex.w-full.items-center
      [:div.dashboard-card-title-name.font-bold
-      (if (model/untitled-page? page-name)
+      (if (common-util/uuid-string? (:block/name whiteboard))
         [:span.opacity-50 (t :untitled)]
-        (get-page-display-name page-name))]
+        (:block/original-name whiteboard))]
      [:div.flex-1]
      [:div.dashboard-card-checkbox
       {:tab-index -1
@@ -177,12 +171,12 @@
       (ui/checkbox {:value checked
                     :on-change (fn [] (on-checked-change (not checked)))})]]
     [:div.flex.w-full.opacity-50
-     [:div (get-page-human-update-time page-name)]
+     [:div (get-page-human-update-time whiteboard)]
      [:div.flex-1]
-     (references-count page-name nil {:hover? true})]]
+     (references-count (:block/uuid whiteboard) nil {:hover? true})]]
    (ui/lazy-visible
     (fn [] [:div.p-4.h-64.flex.justify-center
-            (tldraw-preview page-name)]))])
+            (tldraw-preview (:block/uuid whiteboard))]))])
 
 (rum/defc dashboard-create-card
   []
@@ -201,7 +195,6 @@
     (let [whiteboards (->> (model/get-all-whiteboards (state/get-current-repo))
                            (sort-by :block/updated-at)
                            reverse)
-          whiteboard-names (map :block/name whiteboards)
           [ref rect] (use-bounding-client-rect)
           [container-width] (when rect [(.-width rect) (.-height rect)])
           cols (cond (< container-width 600) 1
@@ -211,8 +204,8 @@
           total-whiteboards (count whiteboards)
           empty-cards (- (max (* (math/ceil (/ (inc total-whiteboards) cols)) cols) (* 2 cols))
                          (inc total-whiteboards))
-          [checked-page-names set-checked-page-names] (rum/use-state #{})
-          has-checked? (not-empty checked-page-names)]
+          [checked-page-ids set-checked-page-ids] (rum/use-state #{})
+          has-checked? (not-empty checked-page-ids)]
       [:<>
        [:h1.select-none.flex.items-center.whiteboard-dashboard-title.title
         [:div (t :all-whiteboards)
@@ -221,14 +214,14 @@
         [:div.flex-1]
         (when has-checked?
           (ui/button
-           (count checked-page-names)
+           (count checked-page-ids)
            {:icon "trash"
             :on-click
             (fn []
               (state/set-modal! (page/batch-delete-dialog
-                                 (map (fn [name]
-                                        (some (fn [w] (when (= (:block/name w) name) w)) whiteboards))
-                                      checked-page-names)
+                                 (map (fn [id]
+                                        (some (fn [w] (when (= (:db/id w) id) w)) whiteboards))
+                                      checked-page-ids)
                                  false route-handler/redirect-to-whiteboard-dashboard!)))}))]
        [:div
         {:ref ref}
@@ -236,15 +229,16 @@
          {:style {:visibility (when (nil? container-width) "hidden")
                   :grid-template-columns (str "repeat(" cols ", minmax(0, 1fr))")}}
          (when-not config/publishing? (dashboard-create-card))
-         (for [whiteboard-name whiteboard-names]
-           [:<> {:key whiteboard-name}
-            (dashboard-preview-card whiteboard-name
-                                    {:show-checked? has-checked?
-                                     :checked (boolean (checked-page-names whiteboard-name))
-                                     :on-checked-change (fn [checked]
-                                                          (set-checked-page-names (if checked
-                                                                                    (conj checked-page-names whiteboard-name)
-                                                                                    (disj checked-page-names whiteboard-name))))})])
+         (for [whiteboard whiteboards]
+           (let [id (:db/id whiteboard)]
+             [:<> {:key (str id)}
+             (dashboard-preview-card whiteboard
+                                     {:show-checked? has-checked?
+                                      :checked (boolean (checked-page-ids id))
+                                      :on-checked-change (fn [checked]
+                                                           (set-checked-page-ids (if checked
+                                                                                   (conj checked-page-ids id)
+                                                                                   (disj checked-page-ids id))))})]))
          (for [n (range empty-cards)]
            [:div.dashboard-card.dashboard-bg-card {:key n}])]]])
     [:div "This feature is not publicly available yet."]))
@@ -277,14 +271,14 @@
        (page/page-title page {:*hover? (atom false)})]
 
       [:div.whiteboard-page-refs
-       (references-count (:block/original-name page)
+       (references-count (:block/uuid page)
                          "text-md px-3 py-2 cursor-default whiteboard-page-refs-count"
                          {:hover? true
                           :render-fn (fn [open? refs-count] [:span.whiteboard-page-refs-count-label
                                                              (t :whiteboard/reference-count refs-count)
                                                              (ui/icon (if open? "references-hide" "references-show")
                                                                       {:extension? true})])})]]
-     (tldraw-app (:block/original-name page) block-id)]))
+     (tldraw-app page-uuid block-id)]))
 
 (rum/defc whiteboard-route <
   (shortcut/mixin :shortcut.handler/whiteboard false)

+ 1 - 1
src/main/frontend/db.cljs

@@ -40,7 +40,7 @@
   get-all-pages get-pages-relation get-pages-that-mentioned-page get-tag-pages
   journal-page? page-alias-set sub-block
   set-file-last-modified-at! page-empty? page-exists? get-alias-source-page
-  set-file-content! has-children?]
+  set-file-content! has-children? whiteboard-page?]
 
  [frontend.db.react
   get-current-page set-key-value

+ 6 - 3
src/main/frontend/db/model.cljs

@@ -531,7 +531,8 @@ independent of format as format specific heading characters are stripped"
 
 (defn get-page
   [page-name-or-uuid]
-  (ldb/get-page (conn/get-db) page-name-or-uuid))
+  (when page-name-or-uuid
+    (ldb/get-page (conn/get-db) page-name-or-uuid)))
 
 ;; FIXME: should pass page's db id
 (defn get-redirect-page-name
@@ -813,7 +814,7 @@ independent of format as format specific heading characters are stripped"
   "Given a page entity, page object or page name, check if it is a whiteboard page"
   [page]
   (let [page (if (string? page)
-               (db-utils/entity (ldb/get-first-page-by-name (conn/get-db) page))
+               (get-page page)
                page)]
     (ldb/whiteboard-page? page)))
 
@@ -836,7 +837,9 @@ independent of format as format specific heading characters are stripped"
 (defn get-all-whiteboards
   [repo]
   (d/q
-    '[:find [(pull ?page [:block/name
+    '[:find [(pull ?page [:db/id
+                          :block/uuid
+                          :block/name
                           :block/original-name
                           :block/created-at
                           :block/updated-at]) ...]

+ 0 - 4
src/main/frontend/db/react.cljs

@@ -158,10 +158,6 @@
         page (case route-name
                :page
                (get-in match [:path-params :name])
-
-               :whiteboard
-               (get-in match [:path-params :name])
-
                (date/journal-name))]
     (when page
       (if (common-util/uuid-string? page)

+ 19 - 18
src/main/frontend/extensions/tldraw.cljs

@@ -106,7 +106,7 @@
 
 (def undo (fn [] (history/undo! nil)))
 (def redo (fn [] (history/redo! nil)))
-(defn get-tldraw-handlers [current-whiteboard-name]
+(defn get-tldraw-handlers [current-whiteboard-uuid]
   {:t (fn [key] (t (keyword key)))
    :search search-handler
    :queryBlockByUUID (fn [block-uuid]
@@ -133,7 +133,7 @@
    :addNewWhiteboard (fn [page-name]
                        (whiteboard-handler/<create-new-whiteboard-page! page-name))
    :addNewBlock (fn [content]
-                  (p/let [new-block-id (whiteboard-handler/<add-new-block! current-whiteboard-name content)]
+                  (p/let [new-block-id (whiteboard-handler/<add-new-block! current-whiteboard-uuid content)]
                     (str new-block-id)))
    :sidebarAddBlock (fn [uuid type]
                       (state/sidebar-add-block! (state/get-current-repo)
@@ -168,7 +168,7 @@
 
 (rum/defc tldraw-inner < rum/static
   {:will-remount (fn [old-state new-state]
-                   (let [page-name (first (:rum/args old-state))
+                   (let [page-uuid (first (:rum/args old-state))
                          old-data (nth (:rum/args old-state) 1)
                          new-data (nth (:rum/args new-state) 1)
                          old-shapes (let [shapes (some-> (gobj/get old-data "pages")
@@ -187,9 +187,9 @@
                      (when (seq updated-shapes)
                        (whiteboard-handler/update-shapes! updated-shapes))
 
-                     (whiteboard-handler/update-shapes-index! page-name))
+                     (whiteboard-handler/update-shapes-index! page-uuid))
                    new-state)}
-  [page-name data populate-onboarding? loaded-app on-mount]
+  [page-uuid data populate-onboarding? loaded-app on-mount]
   [:div.draw.tldraw.whiteboard.relative.w-full.h-full
    {:style {:overscroll-behavior "none"}
     :on-blur (fn [e]
@@ -205,21 +205,21 @@
       (ui/loading "Loading onboarding whiteboard ...")])
 
    (tldraw {:renderers tldraw-renderers
-            :handlers (get-tldraw-handlers page-name)
+            :handlers (get-tldraw-handlers page-uuid)
             :onMount on-mount
             :readOnly config/publishing?
-            ;; :onPersist (debounce #(on-persist page-name %1 %2) 200)
-            :onPersist #(on-persist page-name %1 %2)
+            ;; :onPersist (debounce #(on-persist page-uuid %1 %2) 200)
+            :onPersist #(on-persist page-uuid %1 %2)
             :model data})])
 
 (rum/defc tldraw-app-inner < rum/reactive
   {:init (fn [state]
-           (let [page-name (first (:rum/args state))]
-             (db-async/<get-block (state/get-current-repo) page-name)
+           (let [page-uuid (first (:rum/args state))]
+             (db-async/<get-block (state/get-current-repo) (str page-uuid))
              state))}
-  [page-name block-id loaded-app set-loaded-app]
-  (when-not (state/sub-async-query-loading page-name)
-    (let [populate-onboarding? (whiteboard-handler/should-populate-onboarding-whiteboard? page-name)
+  [page-uuid block-id loaded-app set-loaded-app]
+  (when-not (state/sub-async-query-loading (str page-uuid))
+    (let [populate-onboarding? (whiteboard-handler/should-populate-onboarding-whiteboard? page-uuid)
           on-mount (fn [^js tln]
                      (when tln
                        (set! (.-appUndo tln) undo)
@@ -230,16 +230,17 @@
                                  #(do (whiteboard-handler/cleanup! (.-currentPage tln))
                                       (state/focus-whiteboard-shape tln block-id)
                                       (set-loaded-app tln))))))
-          data (whiteboard-handler/page-name->tldr! page-name)]
+          data (whiteboard-handler/get-page-tldr page-uuid)]
       (when data
-        (tldraw-inner page-name data populate-onboarding? loaded-app on-mount)))))
+        (tldraw-inner page-uuid data populate-onboarding? loaded-app on-mount)))))
 
 (rum/defc tldraw-app
-  [page-name block-id]
-  (let [[loaded-app set-loaded-app] (rum/use-state nil)]
+  [page-uuid block-id]
+  (let [page-uuid (str page-uuid)
+        [loaded-app set-loaded-app] (rum/use-state nil)]
     (rum/use-effect! (fn []
                        (when (and loaded-app block-id)
                          (state/focus-whiteboard-shape loaded-app block-id))
                        #())
                      [block-id loaded-app])
-    (tldraw-app-inner page-name block-id loaded-app set-loaded-app)))
+    (tldraw-app-inner page-uuid block-id loaded-app set-loaded-app)))

+ 6 - 4
src/main/frontend/handler/common/page.cljs

@@ -200,19 +200,21 @@
                 (println "file rename failed: " error))))))
 
 (defn after-page-renamed!
-  [repo {:keys [old-name new-name old-path new-path]}]
+  [repo {:keys [page-id old-name new-name old-path new-path]}]
   (let [db-based?           (config/db-based-graph? repo)
         old-page-name       (common-util/page-name-sanity-lc old-name)
         new-page-name       (common-util/page-name-sanity-lc new-name)
         redirect? (= (some-> (state/get-current-page) common-util/page-name-sanity-lc)
-                     (common-util/page-name-sanity-lc old-page-name))]
+                     (common-util/page-name-sanity-lc old-page-name))
+        page (db/entity repo page-id)]
 
     ;; Redirect to the newly renamed page
-    (when redirect?
+    (when (and redirect? (not (db/whiteboard-page? page)))
       (route-handler/redirect! {:to          :page
                                 :push        false
-                                :path-params {:name new-page-name}}))
+                                :path-params {:name (str (:block/uuid page))}}))
 
+    ;; FIXME: favorites should store db id/uuid instead of page names
     (when (and (config/db-based-graph? repo) (favorited? old-page-name))
       (unfavorite-page! old-page-name)
       (favorite-page! new-page-name))

+ 1 - 1
src/main/frontend/handler/editor.cljs

@@ -3230,7 +3230,7 @@
 
 (defn whiteboard?
   []
-  (and (state/whiteboard-route?)
+  (and (db-model/whiteboard-page? (state/get-current-page))
        (.closest (.-activeElement js/document) ".logseq-tldraw")))
 
 (defn shortcut-cut

+ 0 - 1
src/main/frontend/handler/page.cljs

@@ -363,7 +363,6 @@
                (not (:graph/loading? @state/state))
                (not (:graph/importing @state/state))
                (not (state/loading-files? repo))
-               (not (state/whiteboard-route?))
                (not config/publishing?))
       (state/set-today! (date/today))
       (when (or (config/db-based-graph? repo)

+ 1 - 1
src/main/frontend/handler/route.cljs

@@ -84,7 +84,7 @@
                         (:db/id (db/entity [:block/uuid page-name]))
                         (:db/id (db/entity (ldb/get-first-page-by-name (db/get-db) page-name))))]
        (recent-handler/add-page-to-recent! db-id click-from-recent?))
-     (if (and (= name (state/get-current-whiteboard)) block-id)
+     (if (and (= (str page-name) (state/get-current-page)) block-id)
        (state/focus-whiteboard-shape block-id)
        (let [m (cond->
                 (default-page-route (str page-name))

+ 25 - 25
src/main/frontend/handler/whiteboard.cljs

@@ -24,9 +24,9 @@
   [obj]
   (js->clj obj :keywordize-keys true))
 
-(defn shape->block [shape page-name]
+(defn shape->block [shape page-id]
   (let [repo (state/get-current-repo)]
-    (gp-whiteboard/shape->block repo shape page-name)))
+    (gp-whiteboard/shape->block repo shape page-id)))
 
 (defn- build-shapes
   [page-block blocks]
@@ -75,8 +75,9 @@
                            (util/time-ms))}))
 
 (defn- compute-tx
-  [^js app ^js tl-page new-id-nonces db-id-nonces page-name replace?]
-  (let [assets (js->clj-keywordize (.getCleanUpAssets app))
+  [^js app ^js tl-page new-id-nonces db-id-nonces page-uuid replace?]
+  (let [page-entity (db/get-page page-uuid)
+        assets (js->clj-keywordize (.getCleanUpAssets app))
         new-shapes (.-shapes tl-page)
         shapes-index (map #(gobj/get % "id") new-shapes)
         shape-id->index (zipmap shapes-index (range (.-length new-shapes)))
@@ -100,7 +101,7 @@
                               (mapv (fn [b] (pu/get-block-property-value b :logseq.property.tldraw/shape)))
                               (remove nil?)))
         deleted-shapes-tx (mapv (fn [id] [:db/retractEntity [:block/uuid (uuid id)]]) deleted-ids)
-        upserted-blocks (->> (map #(shape->block % page-name) upsert-shapes)
+        upserted-blocks (->> (map #(shape->block % (:db/id page-entity)) upsert-shapes)
                              (remove (fn [b]
                                        (= (:nonce
                                            (pu/get-block-property-value
@@ -110,7 +111,7 @@
                                            (pu/get-block-property-value
                                             b
                                             :logseq.property.tldraw/shape))))))
-        page-entity (model/get-page page-name)
+        page-name (or (:block/original-name page-entity) (str page-uuid))
         page-block (build-page-block page-entity page-name tl-page assets shapes-index)]
     (when (or (seq upserted-blocks)
               (seq deleted-shapes-tx)
@@ -128,10 +129,10 @@
 
 ;; FIXME: it seems that nonce for the page block will not be updated with new updates for the whiteboard
 (defn <transact-tldr-delta!
-  [page-name ^js app replace?]
+  [page-uuid ^js app replace?]
   (let [tl-page ^js (second (first (.-pages app)))
         shapes (.-shapes ^js tl-page)
-        page-block (model/get-page page-name)
+        page-block (model/get-page page-uuid)
         prev-page-metadata (pu/get-block-property-value page-block :logseq.property.tldraw/page)
         prev-shapes-index (:shapes-index prev-page-metadata)
         shape-id->prev-index (zipmap prev-shapes-index (range (count prev-shapes-index)))
@@ -143,30 +144,30 @@
                                                       (js/Date.now))})) shapes))
         repo (state/get-current-repo)
         db-id-nonces (or
-                      (get-in @*last-shapes-nonce [repo page-name])
+                      (get-in @*last-shapes-nonce [repo page-uuid])
                       (set (->> (model/get-whiteboard-id-nonces repo (:db/id page-block))
                                 (map #(update % :id str)))))
         {:keys [page-block new-shapes deleted-shapes upserted-blocks delete-blocks metadata] :as result}
-        (compute-tx app tl-page new-id-nonces db-id-nonces page-name replace?)]
+        (compute-tx app tl-page new-id-nonces db-id-nonces page-uuid replace?)]
     (when (seq result)
       (let [tx-data (concat delete-blocks [page-block] upserted-blocks)
             metadata' (cond
-                    ;; group
+                        ;; group
                         (some #(= "group" (:type %)) new-shapes)
                         (assoc metadata :whiteboard/op :group)
 
-                    ;; ungroup
+                        ;; ungroup
                         (and (not-empty deleted-shapes) (every? #(= "group" (:type %)) deleted-shapes))
                         (assoc metadata :whiteboard/op :un-group)
 
-                    ;; arrow
+                        ;; arrow
                         (some #(and (= "line" (:type %))
                                     (= "arrow " (:end (:decorations %)))) new-shapes)
 
                         (assoc metadata :whiteboard/op :new-arrow)
                         :else
                         metadata)]
-        (swap! *last-shapes-nonce assoc-in [repo page-name] new-id-nonces)
+        (swap! *last-shapes-nonce assoc-in [repo page-uuid] new-id-nonces)
         (if (contains? #{:new-arrow} (:whiteboard/op metadata'))
           (state/set-state! :whiteboard/pending-tx-data
                             {:tx-data tx-data
@@ -241,24 +242,23 @@
       (when link?
         (.createNewLineBinding api source-shape (:id shape))))))
 
-(defn page-name->tldr!
-  [page-name]
-  (let [page (model/get-page page-name)
+(defn get-page-tldr
+  [page-uuid]
+  (let [page (model/get-page page-uuid)
         react-page (db/sub-block (:db/id page))
         blocks (:block/_page react-page)]
     (whiteboard-clj->tldr react-page blocks)))
 
 (defn <add-new-block!
-  [page-name content]
+  [page-uuid content]
   (p/let [repo (state/get-current-repo)
           new-block-id (db/new-block-id)
-          page-entity (model/get-page page-name)
+          page-entity (model/get-page page-uuid)
           tx (sqlite-util/block-with-timestamps
               {:block/uuid new-block-id
                :block/content (or content "")
                :block/format :markdown
-               :block/page {:block/name (util/page-name-sanity-lc page-name)
-                            :block/original-name page-name}
+               :block/page (:db/id page-entity)
                :block/parent (:db/id page-entity)})
           _ (db/transact! repo [tx] {:whiteboard/transact? true})]
     new-block-id))
@@ -296,12 +296,12 @@
                                                     :bindings bindings})))))
 (defn should-populate-onboarding-whiteboard?
   "When there is no whiteboard, or there is only one whiteboard that has the given page name, we should populate the onboarding shapes"
-  [page-name]
+  [page-uuid]
   (let [whiteboards (model/get-all-whiteboards (state/get-current-repo))]
     (and (or (empty? whiteboards)
              (and
               (= 1 (count whiteboards))
-              (= page-name (:block/name (first whiteboards)))))
+              (= (str page-uuid) (str (:block/uuid (first whiteboards))))))
          (not (state/get-onboarding-whiteboard?)))))
 
 (defn update-shapes!
@@ -311,11 +311,11 @@
       (apply (.-updateShapes api) (bean/->js shapes)))))
 
 (defn update-shapes-index!
-  [page-name]
+  [page-uuid]
   (when-let [app (state/active-tldraw-app)]
     (let [tl-page ^js (second (first (.-pages app)))]
       (when tl-page
-        (when-let [page (db/get-page page-name)]
+        (when-let [page (db/get-page page-uuid)]
           (let [page-metadata (pu/get-block-property-value page :logseq.property.tldraw/page)
                 shapes-index (:shapes-index page-metadata)]
             (when (seq shapes-index)

+ 1 - 3
src/main/frontend/routes.cljs

@@ -40,9 +40,7 @@
     {:name :page
      :view (fn [route-match]
              (let [page-name (get-in route-match [:parameters :path :name])
-                   db (db/get-db)
-                   whiteboard? (when db
-                                 (ldb/whiteboard-page? (db/entity (ldb/get-first-page-by-name db page-name))))]
+                   whiteboard? (ldb/whiteboard-page? (db/get-page page-name))]
                (if whiteboard?
                  (whiteboard/whiteboard-route route-match)
                  (page/page route-match))))}]

+ 1 - 11
src/main/frontend/state.cljs

@@ -847,17 +847,7 @@ Similar to re-frame subscriptions"
 
 (defn get-current-page
   []
-  (when (contains? #{:whiteboard :page} (get-current-route)) ; TODO: move /whiteboard to /page
-    (get-in (get-route-match)
-            [:path-params :name])))
-
-(defn whiteboard-route?
-  []
-  (= :whiteboard (get-current-route)))
-
-(defn get-current-whiteboard
-  []
-  (when (whiteboard-route?)
+  (when (= :page (get-current-route))
     (get-in (get-route-match)
             [:path-params :name])))
 

+ 3 - 5
src/main/frontend/util/page.cljs

@@ -7,17 +7,15 @@
 (defn get-current-page-name
   "Fetch the current page's original name with same approach as get-current-page-id"
   []
-  (or (state/get-current-page)
-      (state/get-current-whiteboard)
+  (or (:block/original-name (db/get-page (state/get-current-page)))
       (get-in (first (state/get-editor-args)) [:block :block/page :block/original-name])))
 
 (defn get-current-page-id
   "Fetches the current page id. Looks up page based on latest route and if
   nothing is found, gets page of last edited block"
   []
-  (let [page-name (or (state/get-current-page) (state/get-current-whiteboard))]
-    (or (and page-name (db/get-page page-name))
-        (get-in (first (state/get-editor-args)) [:block :block/page :db/id]))))
+  (let [page-name (state/get-current-page)]
+    (:db/id (db/get-page page-name))))
 
 (defn get-editing-page-id
   "Fetch the editing page id. If there is an edit-input-id set, we are probably still

+ 2 - 1
src/main/frontend/worker/handler/page/rename.cljs

@@ -102,7 +102,8 @@
 
         (ldb/transact! conn txs {:outliner-op :rename-page
                                  :data (cond->
-                                        {:old-name old-page-name
+                                        {:page-id (:db/id page)
+                                         :old-name old-page-name
                                          :new-name new-name}
                                          (and old-path new-path)
                                          (merge {:old-path old-path