From 4dd3367bdda6ff509a25e01c0297bdc4c26503fd Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 27 Aug 2024 14:26:06 +0200 Subject: [PATCH] Allow creating token sets --- .../app/main/ui/workspace/tokens/sets.cljs | 63 ++++++++++++------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/sets.cljs b/frontend/src/app/main/ui/workspace/tokens/sets.cljs index 463a6f72f..9f9c6daa9 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets.cljs @@ -33,6 +33,9 @@ (defn on-update-token-set [token-set] (st/emit! (wdt/update-token-set token-set))) +(defn on-create-token-set [token-set] + (st/emit! (wdt/create-token-set token-set))) + (mf/defc editing-node [{:keys [default-value on-cancel on-submit]}] (let [ref (mf/use-ref) @@ -58,7 +61,16 @@ :default-value default-value}])) (mf/defc sets-tree - [{:keys [token-set token-set-active? token-set-selected? editing? on-select on-toggle on-edit on-submit on-cancel] :as _props}] + [{:keys [token-set + token-set-active? + token-set-selected? + editing? + on-select + on-toggle + on-edit + on-submit + on-cancel] + :as _props}] (let [{:keys [id name _children]} token-set selected? (and set? (token-set-selected? id)) visible? (token-set-active? id) @@ -111,29 +123,38 @@ :selected-set-id selected-token-set-id)])]))])]])) (mf/defc controlled-sets-list - [{:keys [token-sets on-rename] :as props}] - (let [{:keys [editing? new? on-edit on-reset]} (sets-context/use-context)] + [{:keys [token-sets + on-update-token-set + token-set-selected? + token-set-active? + on-create-token-set + on-select] + :as _props}] + (let [{:keys [editing? new? on-edit on-create on-reset]} (sets-context/use-context)] [:ul {:class (stl/css :sets-list)} (for [[id token-set] token-sets] - [:& sets-tree (-> (assoc props - :key id - :token-set token-set - :editing? editing? - :set-editing-node on-edit - :on-edit on-edit - :on-submit #(do - (on-rename %) - (on-reset)) - :on-cancel on-reset) - (dissoc :token-sets))]) + [:& sets-tree {:key id + :token-set token-set + :token-set-selected? (if new? (constantly false) token-set-selected?) + :token-set-active? token-set-active? + :editing? editing? + :on-select on-select + :on-edit on-edit + :on-submit #(do + (on-update-token-set %) + (on-reset)) + :on-cancel on-reset}]) (when new? - [:& sets-tree {:token-set {} - :token-set-active? (constantly true) + [:& sets-tree {:token-set {:name ""} :token-set-selected? (constantly true) - :on-select identity + :token-set-active? (constantly true) :editing? (constantly true) - :set-editing-node on-edit}])])) - + :on-select (constantly nil) + :on-edit on-create + :on-submit #(do + (on-create-token-set %) + (on-reset)) + :on-cancel on-reset}])])) (mf/defc sets-list [{:keys []}] @@ -150,9 +171,9 @@ (get active-token-set-ids id)))] [:& controlled-sets-list {:token-sets token-sets - :selected-token-set-id selected-token-set-id :token-set-selected? token-set-selected? :token-set-active? token-set-active? :on-select on-select-token-set-click :on-toggle on-toggle-token-set-click - :on-rename on-update-token-set}])) + :on-update-token-set on-update-token-set + :on-create-token-set on-create-token-set}]))