diff --git a/frontend/src/app/main/ui.cljs b/frontend/src/app/main/ui.cljs index bf6b1ebaa..328f2b3e4 100644 --- a/frontend/src/app/main/ui.cljs +++ b/frontend/src/app/main/ui.cljs @@ -133,13 +133,14 @@ (fn [] (st/emit! (dtm/finalize-team team-id)))) - (let [team (mf/deref refs/team)] + (let [{:keys [permissions] :as team} (mf/deref refs/team)] (when (= team-id (:id team)) - [:& (mf/provider ctx/current-team-id) {:value team-id} - [:& (mf/provider ctx/permissions) {:value (:permissions team)} - ;; The `:key` is mandatory here because we want to reinitialize - ;; all dom tree instead of simple rerender. - [:* {:key (str team-id)} children]]]))) + [:> (mf/provider ctx/current-team-id) {:value team-id} + [:> (mf/provider ctx/permissions) {:value permissions} + [:> (mf/provider ctx/can-edit?) {:value (:can-edit permissions)} + ;; The `:key` is mandatory here because we want to reinitialize + ;; all dom tree instead of simple rerender. + [:* {:key (str team-id)} children]]]]))) (mf/defc page* {::mf/props :obj diff --git a/frontend/src/app/main/ui/context.cljs b/frontend/src/app/main/ui/context.cljs index 09f12f995..abee67fb4 100644 --- a/frontend/src/app/main/ui/context.cljs +++ b/frontend/src/app/main/ui/context.cljs @@ -34,3 +34,4 @@ (def sidebar (mf/create-context nil)) (def permissions (mf/create-context nil)) +(def can-edit? (mf/create-context nil)) diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index 7454489bf..a13abf726 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -9,6 +9,7 @@ (:require [app.common.data :as d] [app.common.data.macros :as dm] + [app.common.json :as json] [app.common.types.tokens-lib :as ctob] [app.main.data.event :as ev] [app.main.data.modal :as modal] @@ -72,6 +73,9 @@ (let [{:keys [modal title]} (get wtch/token-properties type) + can-edit? + (mf/use-ctx ctx/can-edit?) + tokens (mf/with-memo [tokens] (vec (sort-by :name tokens))) @@ -115,14 +119,12 @@ (dom/stop-propagation event) (when (seq selected-shapes) (st/emit! (wtch/toggle-token {:token token - :shapes selected-shapes}))))) - tokens-count (count tokens) - can-edit? (:can-edit (deref refs/permissions))] + :shapes selected-shapes})))))] [:div {:on-click on-toggle-open-click} [:& cmm/asset-section {:icon (token-section-icon type) :title title - :assets-count tokens-count + :assets-count (count tokens) :open? is-open} [:& cmm/asset-section-block {:role :title-button} (when can-edit? @@ -168,11 +170,8 @@ (let [ordered-themes (mf/deref refs/workspace-token-themes-no-hidden) - permissions - (mf/use-ctx ctx/permissions) - can-edit? - (get permissions :can-edit) + (mf/use-ctx ctx/can-edit?) open-modal (mf/use-fn