From e1ae3d55afb5b159c9527f395b075c64908337fb Mon Sep 17 00:00:00 2001 From: Akshay Gupta Date: Thu, 16 May 2024 14:08:11 +0530 Subject: [PATCH] ad functionality to duplicate token from context menu --- frontend/src/app/main/data/tokens.cljs | 18 ++++++++++++++++++ .../main/ui/workspace/tokens/context_menu.cljs | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 503941a8b..824edbf7b 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -12,9 +12,12 @@ [app.common.types.shape :as cts] [app.common.uuid :as uuid] [app.main.data.workspace.changes :as dch] + [app.main.refs :as refs] + [app.main.store :as st] [app.main.ui.workspace.tokens.common :refer [workspace-shapes]] [beicon.v2.core :as rx] [clojure.data :as data] + [cuerdas.core :as str] [potok.v2.core :as ptk])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -65,6 +68,11 @@ next-applied-tokens (toggle-or-apply-token shape token)] (rx/of (update-shape shape-id {:applied-tokens next-applied-tokens})))))) +(defn get-token-data-from-token-id + [id] + (let [workspace-data (deref refs/workspace-data)] + (get (:tokens workspace-data) id))) + (defn add-token [token] (let [token (update token :id #(or % (uuid/next)))] @@ -87,6 +95,16 @@ (pcb/delete-token id))] (rx/of (dch/commit-changes changes)))))) +(defn duplicate-token + [id] + (let [token-data (get-token-data-from-token-id id) + duplicate-token-name (str/concat (:name token-data) "-copy") + duplicate-token {:name duplicate-token-name + :value (:value token-data) + :type (:type token-data) + :description (or (:description token-data) "")}] + (st/emit! (add-token duplicate-token)))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; TEMP (Move to test) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs index ec4fcb4c2..c6825f621 100644 --- a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs @@ -29,7 +29,7 @@ (mf/defc token-pill-context-menu [{:keys [token-id]}] (let [do-delete #(st/emit! (dt/delete-token token-id)) - do-duplicate #(js/console.log "Duplicating") + do-duplicate #(st/emit! (dt/duplicate-token token-id)) do-edit #(js/console.log "Editing")] [:* [:& menu-entry {:title "Delete Token" :on-click do-delete}]