From ead8a983ab4753b840c8aa796309783d05c3f1d8 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 15 Aug 2024 14:26:12 +0200 Subject: [PATCH] Move to token-set namespace --- frontend/src/app/main/data/tokens.cljs | 34 ++--------------- .../main/ui/workspace/tokens/token_set.cljs | 37 +++++++++++++++++++ 2 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 frontend/src/app/main/ui/workspace/tokens/token_set.cljs diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index cab0e5c753..ddd5f55500 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -19,7 +19,8 @@ [beicon.v2.core :as rx] [clojure.data :as data] [cuerdas.core :as str] - [potok.v2.core :as ptk])) + [potok.v2.core :as ptk] + [app.main.ui.workspace.tokens.token-set :as wtts])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Helpers @@ -79,39 +80,12 @@ (let [workspace-data (deref refs/workspace-data)] (get (:tokens workspace-data) id))) -(defn get-workspace-sets [state] - (get-in state [:workspace-data :token-sets-index])) - -(defn get-token-set [set-id state] - (some-> (get-workspace-sets state) - (get set-id))) - -(def default-token-set-name "Global") - -(defn create-global-set []) - -(defn add-token-to-token-set [token token-set] - (update token-set :items conj (:id token))) - -(defn get-selected-token-set-id [state] - (get-in state [:workspace-local :selected-token-set-id])) - -(defn get-selected-token-set [state] - (when-let [id (get-selected-token-set-id state)] - (get-token-set id state))) - -(defn get-token-set-tokens [{:keys [tokens] :as token-set} file] - (map #(get-in file [:data :tokens %]) tokens)) - -(defn assoc-selected-token-set-id [state id] - (assoc-in state [:workspace-local :selected-token-set-id] id)) - (defn set-selected-token-set-id [id] (ptk/reify ::set-selected-token-set-id ptk/UpdateEvent (update [_ state] - (assoc-selected-token-set-id state id)))) + (wtts/assoc-selected-token-set-id state id)))) (defn update-create-token [token] @@ -126,7 +100,7 @@ (pcb/add-token token)) (-> (pcb/empty-changes it) (pcb/update-token token prev-token))) - token-set (get-selected-token-set state) + token-set (wtts/get-selected-token-set state) create-set? (not token-set) new-token-set {:id (uuid/next) :name "Global" diff --git a/frontend/src/app/main/ui/workspace/tokens/token_set.cljs b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs new file mode 100644 index 0000000000..c76784c496 --- /dev/null +++ b/frontend/src/app/main/ui/workspace/tokens/token_set.cljs @@ -0,0 +1,37 @@ +(ns app.main.ui.workspace.tokens.token-set) + +(defn get-workspace-tokens [state] + (get-in state [:workspace-data :tokens])) + +(defn get-workspace-sets [state] + (get-in state [:workspace-data :token-sets-index])) + +(defn get-token-set [set-id state] + (some-> (get-workspace-sets state) + (get set-id))) + +(def default-token-set-name "Global") + +(defn create-global-set []) + +(defn add-token-to-token-set [token token-set] + (update token-set :items conj (:id token))) + +(defn get-selected-token-set-id [state] + (or (get-in state [:workspace-local :selected-token-set-id]) + (get-in state [:workspace-data :token-set-groups 0]))) + +(defn get-selected-token-set [state] + (when-let [id (get-selected-token-set-id state)] + (get-token-set id state))) + +(defn get-selected-token-set-tokens [state] + (when-let [token-set (get-selected-token-set state)] + (let [tokens (or (get-workspace-tokens state) {})] + (select-keys tokens (:tokens token-set))))) + +(defn get-token-set-tokens [{:keys [tokens] :as token-set} file] + (map #(get-in file [:data :tokens %]) tokens)) + +(defn assoc-selected-token-set-id [state id] + (assoc-in state [:workspace-local :selected-token-set-id] id))