Browse Source

fix: hidden pages like favorites showing up in page property

dropdown. Dry up favorites page name scattered across namespaces.
Should be using vars + namespaces in common dep for commonly
referenced features
Gabriel Horner 2 years ago
parent
commit
1706a5c725

+ 3 - 1
deps/common/src/logseq/common/config.cljs

@@ -1,5 +1,5 @@
 (ns logseq.common.config
-  "Common config that is shared between deps and app"
+  "Common config and constants that are shared between deps and app"
   (:require [clojure.string :as string]
             [goog.object :as gobj]))
 
@@ -35,6 +35,8 @@
 
 (defonce local-assets-dir "assets")
 
+(defonce favorites-page-name "$$$favorites")
+
 (defn local-asset?
   [s]
   (and (string? s)

+ 3 - 2
deps/db/src/logseq/db.cljs

@@ -197,8 +197,9 @@
   [page]
   (when page
     (if (string? page)
-      (and (string/starts-with? page "$$$")
-           (common-util/uuid-string? (common-util/safe-subs page 3)))
+      (or (and (string/starts-with? page "$$$")
+               (common-util/uuid-string? (common-util/safe-subs page 3)))
+          (= common-config/favorites-page-name page))
       (contains? (set (:block/type page)) "hidden"))))
 
 (defn get-pages

+ 3 - 2
deps/db/src/logseq/db/sqlite/common_db.cljs

@@ -5,7 +5,8 @@
             [clojure.string :as string]
             [logseq.db.sqlite.util :as sqlite-util]
             [logseq.common.util.date-time :as date-time-util]
-            [logseq.common.util :as common-util]))
+            [logseq.common.util :as common-util]
+            [logseq.common.config :as common-config]))
 
 (comment
   (defn- get-built-in-files
@@ -126,7 +127,7 @@
 (defn get-favorites
   "Favorites page and its blocks"
   [db]
-  (let [{:keys [block children]} (get-block-and-children db "$$$favorites" true)]
+  (let [{:keys [block children]} (get-block-and-children db common-config/favorites-page-name true)]
     (when block
       (concat [block]
               (->> (keep :block/link children)

+ 1 - 1
src/main/frontend/components/imports.cljs

@@ -196,7 +196,7 @@
       :block/format :markdown})
    page-block-uuid-coll))
 
-(def hidden-favorites-page-name "$$$favorites")
+(def hidden-favorites-page-name common-config/favorites-page-name)
 (def hidden-favorites-page-tx
   {:block/uuid (d/squuid)
    :block/name hidden-favorites-page-name

+ 3 - 2
src/main/frontend/components/property/value.cljs

@@ -23,7 +23,8 @@
             [frontend.handler.property.util :as pu]
             [promesa.core :as p]
             [frontend.db.async :as db-async]
-            [logseq.common.util.macro :as macro-util]))
+            [logseq.common.util.macro :as macro-util]
+            [logseq.db :as ldb]))
 
 (defn- select-type?
   [property type]
@@ -215,7 +216,7 @@
                  :else
                  (model/get-all-page-original-names repo))
                distinct
-               (remove (fn [p] (util/uuid-string? (str p)))))
+               (remove (fn [p] (or (ldb/hidden-page? p) (util/uuid-string? (str p))))))
         options (map (fn [p] {:value p}) pages)
         string-classes (remove #(= :logseq.class %) classes)
         opts' (cond->

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

@@ -10,6 +10,7 @@
             [frontend.state :as state]
             [frontend.worker.handler.page :as worker-page]
             [logseq.common.util :as common-util]
+            [logseq.common.config :as common-config]
             [frontend.handler.ui :as ui-handler]
             [frontend.config :as config]
             [frontend.fs :as fs]
@@ -106,12 +107,10 @@
       (when-not (= old-favorites new-favorites)
         (config-handler/set-config! :favorites new-favorites)))))
 
-(def favorites-page-name "$$$favorites")
-
 (defn- find-block-in-favorites-page
   [page-block-uuid]
   (let [db (conn/get-db)
-        blocks (ldb/get-page-blocks db favorites-page-name {})]
+        blocks (ldb/get-page-blocks db common-config/favorites-page-name {})]
     (when-let [page-block-entity (d/entity db [:block/uuid page-block-uuid])]
       (some (fn [block]
               (when (= (:db/id (:block/link block)) (:db/id page-block-entity))
@@ -126,7 +125,7 @@
 (defn <favorite-page!-v2
   [page-block-uuid]
   {:pre [(uuid? page-block-uuid)]}
-  (let [favorites-page (d/entity (conn/get-db) [:block/name favorites-page-name])
+  (let [favorites-page (d/entity (conn/get-db) [:block/name common-config/favorites-page-name])
         favorites-page-tx-data (build-hidden-page-tx-data "favorites")]
     (when (d/entity (conn/get-db) [:block/uuid page-block-uuid])
       (p/do!
@@ -136,7 +135,7 @@
         (outliner-op/insert-blocks! [{:block/link [:block/uuid page-block-uuid]
                                       :block/content ""
                                       :block/format :markdown}]
-                                    (d/entity (conn/get-db) [:block/name favorites-page-name])
+                                    (d/entity (conn/get-db) [:block/name common-config/favorites-page-name])
                                     {}))))))
 
 (defn <unfavorite-page!-v2

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

@@ -87,8 +87,8 @@
     (let [repo (state/get-current-repo)]
       (if (config/db-based-graph? repo)
         (let [blocks (ldb/sort-by-left
-                      (ldb/get-page-blocks db page-common-handler/favorites-page-name {})
-                      (d/entity db [:block/name page-common-handler/favorites-page-name]))]
+                      (ldb/get-page-blocks db common-config/favorites-page-name {})
+                      (d/entity db [:block/name common-config/favorites-page-name]))]
           (keep (fn [block]
                   (when-let [block-db-id (:db/id (:block/link block))]
                     (d/entity db block-db-id))) blocks))
@@ -140,13 +140,13 @@
 (defn <reorder-favorites!
   [favorites]
   (let [conn (conn/get-db false)]
-    (when-let [favorites-page-entity (d/entity @conn [:block/name page-common-handler/favorites-page-name])]
+    (when-let [favorites-page-entity (d/entity @conn [:block/name common-config/favorites-page-name])]
       (let [favorite-page-block-db-id-coll
             (keep (fn [page-name]
                     (some-> (d/entity @conn [:block/name (common-util/page-name-sanity-lc page-name)])
                             :db/id))
                   favorites)
-            current-blocks (ldb/sort-by-left (ldb/get-page-blocks @conn page-common-handler/favorites-page-name {})
+            current-blocks (ldb/sort-by-left (ldb/get-page-blocks @conn common-config/favorites-page-name {})
                                              favorites-page-entity)]
         (p/do!
          (ui-outliner-tx/transact!