mirror of https://github.com/logseq/logseq
enhance: replace favorite related fns
parent
3365482d34
commit
7d54918ca6
|
@ -104,7 +104,7 @@
|
||||||
{:class "w-60"}
|
{:class "w-60"}
|
||||||
(when-not recent?
|
(when-not recent?
|
||||||
(shui/context-menu-item
|
(shui/context-menu-item
|
||||||
{:on-click #(page-handler/unfavorite-page! original-name)}
|
{:on-click #(page-handler/<unfavorite-page! original-name)}
|
||||||
(ctx-icon "star-off")
|
(ctx-icon "star-off")
|
||||||
(t :page/unfavorite)
|
(t :page/unfavorite)
|
||||||
(shui/context-menu-shortcut (some-> (shortcut-dh/shortcut-binding :command/toggle-favorite) (first)
|
(shui/context-menu-shortcut (some-> (shortcut-dh/shortcut-binding :command/toggle-favorite) (first)
|
||||||
|
|
|
@ -71,9 +71,7 @@
|
||||||
contents? (= page-name "contents")
|
contents? (= page-name "contents")
|
||||||
properties (:block/properties page)
|
properties (:block/properties page)
|
||||||
public? (true? (pu/lookup properties :public))
|
public? (true? (pu/lookup properties :public))
|
||||||
favorites (:favorites (state/sub-config))
|
favorited? (page-handler/favorited? page-name)
|
||||||
favorited? (contains? (set (map util/page-name-sanity-lc favorites))
|
|
||||||
page-name)
|
|
||||||
developer-mode? (state/sub [:ui/developer-mode?])
|
developer-mode? (state/sub [:ui/developer-mode?])
|
||||||
file-rpath (when (util/electron?) (page-util/get-page-file-rpath page-name))
|
file-rpath (when (util/electron?) (page-util/get-page-file-rpath page-name))
|
||||||
_ (state/sub :auth/id-token)
|
_ (state/sub :auth/id-token)
|
||||||
|
@ -91,8 +89,8 @@
|
||||||
:options {:on-click
|
:options {:on-click
|
||||||
(fn []
|
(fn []
|
||||||
(if favorited?
|
(if favorited?
|
||||||
(page-handler/unfavorite-page! page-original-name)
|
(page-handler/<unfavorite-page! page-original-name)
|
||||||
(page-handler/favorite-page! page-original-name)))}})
|
(page-handler/<favorite-page! page-original-name)))}})
|
||||||
|
|
||||||
(when (or (util/electron?) file-sync-graph-uuid)
|
(when (or (util/electron?) file-sync-graph-uuid)
|
||||||
{:title (t :page/version-history)
|
{:title (t :page/version-history)
|
||||||
|
|
|
@ -37,13 +37,41 @@
|
||||||
[electron.ipc :as ipc]
|
[electron.ipc :as ipc]
|
||||||
[frontend.context.i18n :refer [t]]
|
[frontend.context.i18n :refer [t]]
|
||||||
[frontend.persist-db.browser :as db-browser]
|
[frontend.persist-db.browser :as db-browser]
|
||||||
[cljs-bean.core :as bean]))
|
[cljs-bean.core :as bean]
|
||||||
|
[datascript.core :as d]
|
||||||
|
[frontend.db.conn :as conn]))
|
||||||
|
|
||||||
(def create! page-common-handler/create!)
|
(def create! page-common-handler/create!)
|
||||||
(def <create! page-common-handler/<create!)
|
(def <create! page-common-handler/<create!)
|
||||||
(def delete! page-common-handler/delete!)
|
(def delete! page-common-handler/delete!)
|
||||||
(def unfavorite-page! page-common-handler/unfavorite-page!)
|
|
||||||
(def favorite-page! page-common-handler/favorite-page!)
|
(defn <unfavorite-page!
|
||||||
|
[page-name]
|
||||||
|
(let [repo (state/get-current-repo)]
|
||||||
|
(if (config/db-based-graph? repo)
|
||||||
|
(let [db (conn/get-db)]
|
||||||
|
(when-let [page-block-uuid (:block/uuid (d/entity db [:block/name (common-util/page-name-sanity-lc page-name)]))]
|
||||||
|
(page-common-handler/<unfavorite-page!-v2 page-block-uuid)))
|
||||||
|
(page-common-handler/unfavorite-page! page-name))))
|
||||||
|
|
||||||
|
(defn <favorite-page!
|
||||||
|
[page-name]
|
||||||
|
(let [repo (state/get-current-repo)]
|
||||||
|
(if (config/db-based-graph? repo)
|
||||||
|
(let [db (conn/get-db)]
|
||||||
|
(when-let [page-block-uuid (:block/uuid (d/entity db [:block/name (common-util/page-name-sanity-lc page-name)]))]
|
||||||
|
(page-common-handler/<favorite-page!-v2 page-block-uuid)))
|
||||||
|
(page-common-handler/favorite-page! page-name))))
|
||||||
|
|
||||||
|
(defn favorited?
|
||||||
|
[page-name]
|
||||||
|
(let [repo (state/get-current-repo)]
|
||||||
|
(if (config/db-based-graph? repo)
|
||||||
|
(when-let [db (conn/get-db)]
|
||||||
|
(boolean
|
||||||
|
(when-let [page-block-uuid (:block/uuid (d/entity db [:block/name (common-util/page-name-sanity-lc page-name)]))]
|
||||||
|
(page-common-handler/favorited?-v2 page-block-uuid))))
|
||||||
|
(page-common-handler/favorited? page-name))))
|
||||||
|
|
||||||
|
|
||||||
;; FIXME: add whiteboard
|
;; FIXME: add whiteboard
|
||||||
|
@ -65,12 +93,10 @@
|
||||||
(defn toggle-favorite! []
|
(defn toggle-favorite! []
|
||||||
;; NOTE: in journals or settings, current-page is nil
|
;; NOTE: in journals or settings, current-page is nil
|
||||||
(when-let [page-name (state/get-current-page)]
|
(when-let [page-name (state/get-current-page)]
|
||||||
(let [favorites (:favorites (state/sub-config))
|
(let [favorited? (favorited? page-name)]
|
||||||
favorited? (contains? (set (map string/lower-case favorites))
|
|
||||||
(string/lower-case page-name))]
|
|
||||||
(if favorited?
|
(if favorited?
|
||||||
(unfavorite-page! page-name)
|
(<unfavorite-page! page-name)
|
||||||
(favorite-page! page-name)))))
|
(<favorite-page! page-name)))))
|
||||||
|
|
||||||
(defn rename!
|
(defn rename!
|
||||||
[old-name new-name & {:as _opts}]
|
[old-name new-name & {:as _opts}]
|
||||||
|
@ -86,8 +112,9 @@
|
||||||
nil))))
|
nil))))
|
||||||
|
|
||||||
(defn reorder-favorites!
|
(defn reorder-favorites!
|
||||||
[favorites]
|
[_favorites]
|
||||||
(config-handler/set-config! :favorites favorites))
|
;; TODO
|
||||||
|
nil)
|
||||||
|
|
||||||
(defn has-more-journals?
|
(defn has-more-journals?
|
||||||
[]
|
[]
|
||||||
|
|
Loading…
Reference in New Issue