0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-21 06:02:32 -05:00

Hide temporary token theme from user

This commit is contained in:
Florian Schroedl 2024-09-26 12:03:03 +02:00
parent e216d84484
commit 895f92e7c2
4 changed files with 27 additions and 13 deletions

View file

@ -16,6 +16,14 @@
[cuerdas.core :as str]
#?(:clj [app.common.fressian :as fres])))
;; === Constants
(def hidden-token-theme-group
"")
(def hidden-token-theme-name
"__PENPOT__HIDDEN__TOKEN__THEME__")
;; === Groups handling
(def schema:groupable-item
@ -257,7 +265,9 @@
(defprotocol ITokenTheme
(toggle-set [_ set-name] "togle a set used / not used in the theme")
(theme-path [_] "get `token-theme-path` from theme"))
(theme-path [_] "get `token-theme-path` from theme")
(theme-matches-group-name [_ group name] "if a theme matches the given group & name")
(hidden-temporary-theme? [_] "if a theme is the (from the user ui) hidden temporary theme"))
(defrecord TokenTheme [name group description is-source modified-at sets]
ITokenTheme
@ -271,7 +281,14 @@
(disj sets set-name)
(conj sets set-name))))
(theme-path [_]
(token-theme-path group name)))
(token-theme-path group name))
(theme-matches-group-name [this group name]
(and (= (:group this) group)
(= (:name this) name)))
(hidden-temporary-theme? [this]
(theme-matches-group-name this hidden-token-theme-group hidden-token-theme-name)))
(def schema:token-theme
[:and [:map {:title "TokenTheme"}

View file

@ -48,12 +48,6 @@
(defn get-tokens-lib [state]
(get-in state [:workspace-data :tokens-lib]))
(def hidden-token-theme-group
"")
(def hidden-token-theme-name
"__PENPOT__HIDDEN__TOKEN__SET__")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TOKENS Actions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -222,14 +216,14 @@
ptk/WatchEvent
(watch [it state _]
(let [tokens-lib (get-tokens-lib state)
prev-theme (ctob/get-theme tokens-lib hidden-token-theme-group hidden-token-theme-name)
prev-theme (ctob/get-theme tokens-lib ctob/hidden-token-theme-group ctob/hidden-token-theme-name)
theme (-> (or prev-theme (ctob/make-token-theme
:group hidden-token-theme-group
:name hidden-token-theme-name))
:group ctob/hidden-token-theme-group
:name ctob/hidden-token-theme-name))
(ctob/toggle-set token-set-name))
prev-active-token-themes (ctob/get-active-theme-paths tokens-lib)
changes (-> (pcb/empty-changes it)
(pcb/update-active-token-themes #{(ctob/token-theme-path hidden-token-theme-group hidden-token-theme-name)} prev-active-token-themes))
(pcb/update-active-token-themes #{(ctob/token-theme-path ctob/hidden-token-theme-group ctob/hidden-token-theme-name)} prev-active-token-themes))
changes' (if prev-theme
(pcb/update-token-theme changes theme prev-theme)
(pcb/add-token-theme changes theme))]

View file

@ -465,6 +465,9 @@
(def workspace-token-themes
(l/derived #(or (some-> % ctob/get-themes) []) tokens-lib))
(def workspace-token-themes-no-hidden
(l/derived #(remove ctob/hidden-temporary-theme? %) workspace-token-themes))
(def workspace-selected-token-set-id
(l/derived wtts/get-selected-token-set-id st/state))

View file

@ -241,7 +241,7 @@
(mf/defc themes
[_]
(let [themes (mf/deref refs/workspace-token-themes)
(let [themes (mf/deref refs/workspace-token-themes-no-hidden)
state (mf/use-state (if (empty? themes)
{:type :create-theme}
{:type :themes-overview}))