From 0b52f8ad58c2c47f2bbea0b3f2c0f5229c6fd5c4 Mon Sep 17 00:00:00 2001 From: rcmerci Date: Wed, 31 Jan 2024 23:49:12 +0800 Subject: [PATCH] enhance: make ui reactive when favorites updated --- src/main/frontend/components/container.cljs | 3 +- src/main/frontend/handler/page.cljs | 43 ++++++++++++--------- src/main/frontend/state.cljs | 8 +++- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/main/frontend/components/container.cljs b/src/main/frontend/components/container.cljs index 0f35eee2e..0b2ffd052 100644 --- a/src/main/frontend/components/container.cljs +++ b/src/main/frontend/components/container.cljs @@ -132,7 +132,8 @@ (rum/defc favorites < rum/reactive [t] - (let [favorite-entities (page-handler/get-favorites)] + (let [_favorites-updated? (state/sub :favorites/updated?) + favorite-entities (page-handler/get-favorites)] (nav-content-item [:a.flex.items-center.text-sm.font-medium.rounded-md.wrap-th (ui/icon "star" {:size 16}) diff --git a/src/main/frontend/handler/page.cljs b/src/main/frontend/handler/page.cljs index c04970175..b52892671 100644 --- a/src/main/frontend/handler/page.cljs +++ b/src/main/frontend/handler/page.cljs @@ -49,21 +49,25 @@ (defn editor-cursor (atom {}) :system/info {} ;; Whether block is selected - :ui/select-query-cache (atom {})}))) + :ui/select-query-cache (atom {}) + + :favorites/updated? (atom 0)}))) ;; Block ast state ;; =============== @@ -2369,3 +2371,7 @@ Similar to re-frame subscriptions" (when (and max-tx-id (nil? (:after (get @(:history/tx->editor-cursor @state) max-tx-id)))) (update-state! :history/tx->editor-cursor (fn [m] (assoc-in m [max-tx-id :after] editor-cursor)))))) + +(defn update-favorites-updated! + [] + (update-state! :favorites/updated? inc))