mirror of
https://github.com/penpot/penpot.git
synced 2025-02-23 23:35:58 -05:00
✨ Simplify access to can-edit? using react context
This commit is contained in:
parent
4a4cd9492a
commit
efe204c346
3 changed files with 15 additions and 14 deletions
|
@ -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
|
||||
|
|
|
@ -34,3 +34,4 @@
|
|||
(def sidebar (mf/create-context nil))
|
||||
|
||||
(def permissions (mf/create-context nil))
|
||||
(def can-edit? (mf/create-context nil))
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue