From 3365482d348c41a49e976878f484dc4d40b5e7cf Mon Sep 17 00:00:00 2001 From: rcmerci Date: Thu, 25 Jan 2024 18:02:20 +0800 Subject: [PATCH] feat: move favorites to db from config.edn in db-verison --- src/main/frontend/handler/common/page.cljs | 66 +++++++++++++++++++++- src/main/frontend/handler/page.cljs | 1 + 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/main/frontend/handler/common/page.cljs b/src/main/frontend/handler/common/page.cljs index b512c99564..a8198e4b3c 100644 --- a/src/main/frontend/handler/common/page.cljs +++ b/src/main/frontend/handler/common/page.cljs @@ -15,7 +15,21 @@ [frontend.fs :as fs] [promesa.core :as p] [frontend.handler.block :as block-handler] - [frontend.handler.file-based.recent :as file-recent-handler])) + [frontend.handler.file-based.recent :as file-recent-handler] + [frontend.format.block :as block] + [logseq.db :as ldb] + [frontend.db.conn :as conn] + [datascript.core :as d] + [frontend.handler.editor :as editor-handler] + [frontend.modules.outliner.ui :as ui-outliner-tx] + [logseq.outliner.core :as outliner-core])) + +(defn build-hidden-page-tx-data + [page-name] + (let [page-name* (str "$$$" page-name)] + (assoc (block/page-name->map page-name* false false) + :block/type #{"hidden"} + :block/format :markdown))) ;; TODO: return page entity instead (defn create! @@ -94,6 +108,47 @@ (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) + page-block-uuid-str (str page-block-uuid) + blocks (ldb/get-page-blocks db favorites-page-name {})] + (some (fn [block] + (when (= page-block-uuid-str (:block/content block)) + block)) + blocks))) + +(defn favorited?-v2 + [page-block-uuid] + {:pre [(uuid? page-block-uuid)]} + (some? (find-block-in-favorites-page page-block-uuid))) + +(defn (state/get-current-page) common-util/page-name-sanity-lc) @@ -154,7 +214,7 @@ :push false :path-params {:name new-page-name}})) - (when (favorited? old-page-name) + (when (and (config/db-based-graph? repo) (favorited? old-page-name)) (unfavorite-page! old-page-name) (favorite-page! new-page-name)) (let [home (get (state/get-config) :default-home {})] diff --git a/src/main/frontend/handler/page.cljs b/src/main/frontend/handler/page.cljs index 12f5cc1699..e1e8829d4a 100644 --- a/src/main/frontend/handler/page.cljs +++ b/src/main/frontend/handler/page.cljs @@ -45,6 +45,7 @@ (def unfavorite-page! page-common-handler/unfavorite-page!) (def favorite-page! page-common-handler/favorite-page!) + ;; FIXME: add whiteboard (defn- get-directory [journal?]