fix: use :block/type instead of :block/whiteboard?

This commit is contained in:
Peng Xiao
2022-09-28 18:27:03 +08:00
parent 1aa54a4048
commit ce4b2a4ad1
15 changed files with 32 additions and 39 deletions

View File

@@ -3555,7 +3555,7 @@
(when (seq blocks)
(let [alias? (:block/alias? page)
page (db/entity (:db/id page))
whiteboard? (:block/whiteboard? page)]
whiteboard? (= "whiteboard" (:block/type page))]
[:div.my-2 (cond-> {:key (str "page-" (:db/id page))}
(:ref? config)
(assoc :class "color-level px-2 sm:px-7 py-2 rounded"))

View File

@@ -231,6 +231,9 @@
(and (collide?) whiteboard-page?)
(notification/show! (str "Page “" @*title-value "” already exists!") :error)
(and (date/valid-journal-title? @*title-value) whiteboard-page?)
(notification/show! (str "Whiteboard page cannot be renamed with journal titles!") :error)
untitled?
(page-handler/rename! (or title page-name) @*title-value)
@@ -897,7 +900,7 @@
(or (boolean journal?)
(= false (boolean (:block/journal? %))))
(or (boolean whiteboard?)
(= false (boolean (:block/whiteboard? %))))))
(not= "whiteboard" (:block/type %)))))
(sort-pages-by sort-by-item desc?)))))
(reset! *pages pages)))

View File

@@ -123,7 +123,7 @@
(page-handler/create! search-q {:redirect? true})
:new-whiteboard
(whiteboard-handler/create-new-whiteboard! search-q)
(whiteboard-handler/create-new-whiteboard-and-redirect! search-q)
:page
(let [data (or alias data)]

View File

@@ -249,7 +249,7 @@
:class "new-whiteboard-link"
:shortcut (ui/keyboard-shortcut-from-config :editor/new-whiteboard)
:options {:on-click #(do (close-sidebar-on-mobile!)
(whiteboard-handler/create-new-whiteboard!))}
(whiteboard-handler/create-new-whiteboard-and-redirect!))}
:icon (ui/type-icon {:name "new-whiteboard"
:class "highlight"
:extension? true})}])

View File

@@ -161,7 +161,7 @@
{:on-click
(fn [e]
(util/stop e)
(whiteboard-handler/create-new-whiteboard!))}
(whiteboard-handler/create-new-whiteboard-and-redirect!))}
(ui/icon "plus")
[:span.dashboard-create-card-caption.select-none
"New whiteboard"]])

View File

@@ -1649,7 +1649,7 @@
[page-name]
(let [page (db-utils/entity [:block/name (util/safe-page-name-sanity-lc page-name)])]
(or
(:block/whiteboard? page)
(= "whiteboard" (:block/type page))
(when-let [file (:block/file page)]
(when-let [path (:file/path (db-utils/entity (:db/id file)))]
(gp-config/whiteboard? path))))))
@@ -1658,21 +1658,6 @@
[block]
(gp-block/whiteboard-properties? (:properties block)))
;; ;; fixme: caching?
;; (defn get-all-whiteboard-tldrs
;; "Returns a vector of all whiteboard tldrs."
;; [repo]
;; (let [result (d/q
;; '[:find [(pull ?page [* {:block/_page [:block/properties]}]) ...]
;; :where
;; [?page :block/name]
;; [?page :block/whiteboard? true]]
;; (conn/get-db repo))
;; tldrs (mapv (fn [row] (let [blocks (:block/_page row)
;; page (dissoc row :block/_page)]
;; (whiteboard-clj->tldr page blocks))) result)]
;; tldrs))
(defn get-all-whiteboards
[repo]
(->> (d/q
@@ -1681,5 +1666,5 @@
:block/updated-at]) ...]
:where
[?page :block/name]
[?page :block/whiteboard? true]]
[?page :block/type "whiteboard"]]
(conn/get-db repo))))

View File

@@ -107,7 +107,7 @@
(:block/name page)))
page (merge page
(when (seq properties) {:block/properties properties})
(when whiteboard? {:block/whiteboard? whiteboard?}))
(when whiteboard? {:block/type "whiteboard"}))
page-empty? (db/page-empty? (state/get-current-repo) (:block/name page))]
(cond
(not page-empty?)
@@ -458,7 +458,7 @@
;; Redirect to the newly renamed page
(when redirect?
(route-handler/redirect! {:to (if (:block/whiteboard? page) :whiteboard :page)
(route-handler/redirect! {:to (if (= "whiteboard" (:block/type page)) :whiteboard :page)
:push false
:path-params {:name new-page-name}}))

View File

@@ -26,7 +26,7 @@
(let [page-name (util/page-name-sanity-lc page-name)
page-entity (model/get-page page-name)
page-block (merge {:block/name page-name
:block/whiteboard? true
:block/type "whiteboard"
:block/properties (-> tldr-data
(dissoc :shapes)
(assoc :ls-type :whiteboard-page))}
@@ -120,12 +120,12 @@
(outliner-file/sync-to-file page-entity))))
tldr)))
(defn create-new-whiteboard!
(defn create-new-whiteboard-and-redirect!
([]
(create-new-whiteboard-and-redirect! (str (d/squuid))))
([name]
(create-new-whiteboard-page! name)
(route-handler/redirect-to-whiteboard! name))
([]
(create-new-whiteboard! (str (d/squuid)))))
(route-handler/redirect-to-whiteboard! name)))
(defn page-name->tldr!
([page-name]

View File

@@ -110,7 +110,7 @@
(let [format (name (get page :block/format
(state/get-preferred-format)))
title (string/capitalize (:block/name page))
whiteboard-page? (:block/whiteboard? page)
whiteboard-page? (= "whiteboard" (:block/type page))
format (if whiteboard-page? "edn" format)
journal-page? (date/valid-journal-title? title)
filename (if journal-page?
@@ -138,7 +138,7 @@
file-db-id (-> page-block :block/file :db/id)
file-path (-> (db-utils/entity file-db-id) :file/path)]
(if (and (string? file-path) (not-empty file-path))
(let [new-content (if (:block/whiteboard? page-block)
(let [new-content (if (= "whiteboard" (:block/type page-block))
(pr-str {:blocks (map remove-transit-ids tree)
:pages (list (remove-transit-ids page-block))})
(tree->file-content tree {:init-level init-level}))

View File

@@ -42,7 +42,7 @@
[repo page-db-id]
(let [page-block (db/pull repo '[*] page-db-id)
page-db-id (:db/id page-block)
whiteboard? (:block/whiteboard? page-block)
whiteboard? (= "whiteboard" (:block/type page-block))
blocks-count (model/get-page-blocks-count repo page-db-id)]
(if (or (and (> blocks-count 500)
(not (state/input-idle? repo {:diff 3000}))) ;; long page

View File

@@ -104,7 +104,7 @@
:fn editor-handler/keydown-new-line-handler}
:editor/new-whiteboard {:binding "n w"
:fn #(whiteboard-handler/create-new-whiteboard!)}
:fn #(whiteboard-handler/create-new-whiteboard-and-redirect!)}
:editor/follow-link {:binding "mod+o"
:fn editor-handler/follow-link-under-cursor!}