mirror of
https://github.com/penpot/penpot.git
synced 2025-06-07 17:21:39 +02:00
🚧 Show back button only when coming from a modal view
This commit is contained in:
parent
c1165bd12d
commit
12f72c8ca9
1 changed files with 37 additions and 24 deletions
|
@ -33,11 +33,11 @@
|
||||||
[rumext.v2 :as mf]))
|
[rumext.v2 :as mf]))
|
||||||
|
|
||||||
(mf/defc empty-themes
|
(mf/defc empty-themes
|
||||||
[{:keys [set-state]}]
|
[{:keys [change-view]}]
|
||||||
(let [create-theme
|
(let [create-theme
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps set-state)
|
(mf/deps change-view)
|
||||||
#(set-state (fn [_] {:type :create-theme})))
|
#(change-view :create-theme))
|
||||||
close-modal
|
close-modal
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
#(st/emit! (modal/hide)))]
|
#(st/emit! (modal/hide)))]
|
||||||
|
@ -78,17 +78,17 @@
|
||||||
:label ""}]]))
|
:label ""}]]))
|
||||||
|
|
||||||
(mf/defc themes-overview
|
(mf/defc themes-overview
|
||||||
[{:keys [set-state]}]
|
[{:keys [change-view]}]
|
||||||
(let [active-theme-ids (mf/deref refs/workspace-active-theme-paths)
|
(let [active-theme-ids (mf/deref refs/workspace-active-theme-paths)
|
||||||
themes-groups (mf/deref refs/workspace-token-theme-tree-no-hidden)
|
themes-groups (mf/deref refs/workspace-token-theme-tree-no-hidden)
|
||||||
|
|
||||||
create-theme
|
create-theme
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps set-state)
|
(mf/deps change-view)
|
||||||
(fn [e]
|
(fn [e]
|
||||||
(dom/prevent-default e)
|
(dom/prevent-default e)
|
||||||
(dom/stop-propagation e)
|
(dom/stop-propagation e)
|
||||||
(set-state (fn [_] {:type :create-theme}))))
|
(change-view :create-theme)))
|
||||||
|
|
||||||
close-modal
|
close-modal
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
|
@ -122,8 +122,7 @@
|
||||||
(fn [e]
|
(fn [e]
|
||||||
(dom/prevent-default e)
|
(dom/prevent-default e)
|
||||||
(dom/stop-propagation e)
|
(dom/stop-propagation e)
|
||||||
(set-state (fn [_] {:type :edit-theme
|
(change-view :edit-theme {:theme-path [(:id theme) (:group theme) (:name theme)]}))]]
|
||||||
:theme-path [(:id theme) (:group theme) (:name theme)]})))]]
|
|
||||||
[:li {:key theme-id
|
[:li {:key theme-id
|
||||||
:class (stl/css :theme-row)}
|
:class (stl/css :theme-row)}
|
||||||
[:div {:class (stl/css :theme-switch-row)}
|
[:div {:class (stl/css :theme-switch-row)}
|
||||||
|
@ -249,7 +248,7 @@
|
||||||
(ctob/activate-theme tlib (:group theme) (:name theme))))
|
(ctob/activate-theme tlib (:group theme) (:name theme))))
|
||||||
|
|
||||||
(mf/defc edit-create-theme*
|
(mf/defc edit-create-theme*
|
||||||
[{:keys [set-state theme on-save is-editing]}]
|
[{:keys [state change-view theme on-save is-editing]}]
|
||||||
(let [ordered-token-sets (mf/deref refs/workspace-ordered-token-sets)
|
(let [ordered-token-sets (mf/deref refs/workspace-ordered-token-sets)
|
||||||
token-sets (mf/deref refs/workspace-token-sets-tree)
|
token-sets (mf/deref refs/workspace-token-sets-tree)
|
||||||
|
|
||||||
|
@ -257,8 +256,12 @@
|
||||||
current-theme (deref current-theme*)
|
current-theme (deref current-theme*)
|
||||||
lib (make-lib-with-theme current-theme ordered-token-sets)
|
lib (make-lib-with-theme current-theme ordered-token-sets)
|
||||||
|
|
||||||
|
has-back-button? (contains? #{:empty-themes :themes-overview} (:prev-type state))
|
||||||
|
|
||||||
;; Form / Modal handlers
|
;; Form / Modal handlers
|
||||||
on-back (mf/use-fn #(set-state (constantly {:type :themes-overview})))
|
on-back (mf/use-fn
|
||||||
|
(mf/deps change-view)
|
||||||
|
#(change-view :themes-overview))
|
||||||
disabled? (-> (:name current-theme)
|
disabled? (-> (:name current-theme)
|
||||||
(str/trim)
|
(str/trim)
|
||||||
(str/empty?))
|
(str/empty?))
|
||||||
|
@ -336,7 +339,7 @@
|
||||||
|
|
||||||
[:form {:on-submit on-save-form :class (stl/css :edit-theme-form)}
|
[:form {:on-submit on-save-form :class (stl/css :edit-theme-form)}
|
||||||
[:div {:class (stl/css :edit-theme-wrapper)}
|
[:div {:class (stl/css :edit-theme-wrapper)}
|
||||||
(when is-editing
|
(when has-back-button?
|
||||||
[:button {:on-click on-back
|
[:button {:on-click on-back
|
||||||
:class (stl/css :back-btn)
|
:class (stl/css :back-btn)
|
||||||
:type "button"}
|
:type "button"}
|
||||||
|
@ -372,8 +375,8 @@
|
||||||
:disabled? disabled?}]]]]]]))
|
:disabled? disabled?}]]]]]]))
|
||||||
|
|
||||||
(mf/defc edit-theme
|
(mf/defc edit-theme
|
||||||
[{:keys [state set-state]}]
|
[{:keys [state change-view]}]
|
||||||
(let [{:keys [theme-path]} @state
|
(let [{:keys [theme-path]} state
|
||||||
[_ theme-group theme-name] theme-path
|
[_ theme-group theme-name] theme-path
|
||||||
theme (mf/deref (refs/workspace-token-theme theme-group theme-name))
|
theme (mf/deref (refs/workspace-token-theme theme-group theme-name))
|
||||||
|
|
||||||
|
@ -384,15 +387,15 @@
|
||||||
(st/emit! (wdt/update-token-theme [(:group theme) (:name theme)] theme'))))]
|
(st/emit! (wdt/update-token-theme [(:group theme) (:name theme)] theme'))))]
|
||||||
|
|
||||||
[:> edit-create-theme*
|
[:> edit-create-theme*
|
||||||
{:set-state set-state
|
{:state state
|
||||||
|
:change-view change-view
|
||||||
:theme theme
|
:theme theme
|
||||||
:on-save on-save
|
:on-save on-save
|
||||||
:is-editing true}]))
|
:is-editing true}]))
|
||||||
|
|
||||||
(mf/defc create-theme
|
(mf/defc create-theme
|
||||||
[{:keys [set-state]}]
|
[{:keys [state change-view]}]
|
||||||
(let [theme (ctob/make-token-theme :name "")
|
(let [theme (ctob/make-token-theme :name "")
|
||||||
|
|
||||||
on-save
|
on-save
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn [theme]
|
(fn [theme]
|
||||||
|
@ -400,7 +403,8 @@
|
||||||
(wdt/create-token-theme theme))))]
|
(wdt/create-token-theme theme))))]
|
||||||
|
|
||||||
[:> edit-create-theme*
|
[:> edit-create-theme*
|
||||||
{:set-state set-state
|
{:state state
|
||||||
|
:change-view change-view
|
||||||
:theme theme
|
:theme theme
|
||||||
:on-save on-save}]))
|
:on-save on-save}]))
|
||||||
|
|
||||||
|
@ -408,17 +412,26 @@
|
||||||
{::mf/private true}
|
{::mf/private true}
|
||||||
[]
|
[]
|
||||||
(let [themes (mf/deref refs/workspace-token-themes-no-hidden)
|
(let [themes (mf/deref refs/workspace-token-themes-no-hidden)
|
||||||
state (mf/use-state #(if (empty? themes)
|
state* (mf/use-state #(if (empty? themes)
|
||||||
{:type :create-theme}
|
{:type :create-theme}
|
||||||
{:type :themes-overview}))
|
{:type :themes-overview}))
|
||||||
set-state (mf/use-fn #(swap! state %))
|
state (deref state*)
|
||||||
component (case (:type @state)
|
|
||||||
|
change-view (mf/use-fn
|
||||||
|
(fn [type & [state']]
|
||||||
|
(swap! state* (fn [current-state]
|
||||||
|
(merge
|
||||||
|
{:type type
|
||||||
|
:prev-type (:type current-state)}
|
||||||
|
state')))))
|
||||||
|
|
||||||
|
component (case (:type state)
|
||||||
:empty-themes empty-themes
|
:empty-themes empty-themes
|
||||||
:themes-overview (if (empty? themes) empty-themes themes-overview)
|
:themes-overview (if (empty? themes) empty-themes themes-overview)
|
||||||
:edit-theme edit-theme
|
:edit-theme edit-theme
|
||||||
:create-theme create-theme)]
|
:create-theme create-theme)]
|
||||||
[:& component {:state state
|
[:& component {:state state
|
||||||
:set-state set-state}]))
|
:change-view change-view}]))
|
||||||
|
|
||||||
(mf/defc token-themes-modal
|
(mf/defc token-themes-modal
|
||||||
{::mf/wrap-props false
|
{::mf/wrap-props false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue