From 8cb9d9c3523139733b494c8744c9ded1987685a5 Mon Sep 17 00:00:00 2001 From: Akshay Gupta Date: Tue, 14 May 2024 18:48:48 +0530 Subject: [PATCH] Add delete token functionality in context menu --- .../app/main/ui/workspace/tokens/common.cljs | 17 +++++++++++++++- .../ui/workspace/tokens/context_menu.cljs | 20 ++++++++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/common.cljs b/frontend/src/app/main/ui/workspace/tokens/common.cljs index bf4c29c5e..d53805959 100644 --- a/frontend/src/app/main/ui/workspace/tokens/common.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/common.cljs @@ -8,7 +8,10 @@ (:require-macros [app.main.style :as stl]) (:require [app.common.data.macros :as dm] + [app.common.files.changes-builder :as pcb] [app.common.geom.point :as gpt] + [app.main.data.workspace.changes :as dch] + [beicon.v2.core :as rx] [potok.v2.core :as ptk] [rumext.v2 :as mf])) @@ -57,4 +60,16 @@ (ptk/reify ::hide-token-context-menu ptk/UpdateEvent (update [_ state] - (assoc-in state [:workspace-local :token-context-menu] nil)))) \ No newline at end of file + (assoc-in state [:workspace-local :token-context-menu] nil)))) + +(defn delete-token + [id] + (dm/assert! (uuid? id)) + (ptk/reify ::delete-token + ptk/WatchEvent + (watch [it state _] + (let [data (get state :workspace-data) + changes (-> (pcb/empty-changes it) + (pcb/with-library-data data) + (pcb/delete-token id))] + (rx/of (dch/commit-changes changes)))))) \ No newline at end of file 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 3808f1b0b..8233316aa 100644 --- a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs @@ -10,13 +10,14 @@ [app.common.data :as d] [app.common.data.macros :as dm] [app.main.data.events :as ev] + [app.main.data.modal :as modal] [app.main.data.shortcuts :as scd] [app.main.data.workspace :as dw] [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.components.dropdown :refer [dropdown]] [app.main.ui.icons :as i] - [app.main.ui.workspace.tokens.common :refer [hide-token-context-menu]] + [app.main.ui.workspace.tokens.common :as tcm] [app.util.dom :as dom] [app.util.timers :as timers] [okulary.core :as l] @@ -113,13 +114,18 @@ (mf/defc token-pill-context-menu [{:keys [token-id]}] - (let [do-delete #(js/console.log "Deleting") + (let [delete-fn #(st/emit! (tcm/delete-token token-id)) + do-delete #(st/emit! (modal/show + {:type :confirm + :title "Delete" + :message "Are you sure?" + :on-accept delete-fn})) do-duplicate #(js/console.log "Duplicating") do-edit #(js/console.log "Editing")] [:ul.context-list - [:> token-menu-entry {:title "Delete Token" :on-click do-delete}] - [:> token-menu-entry {:title "Duplicate Token" :on-click do-duplicate}] - [:> token-menu-entry {:title "Edit Token" :on-click do-edit}]])) + [:& token-menu-entry {:title "Delete Token" :on-click do-delete}] + [:& token-menu-entry {:title "Duplicate Token" :on-click do-duplicate}] + [:& token-menu-entry {:title "Edit Token" :on-click do-edit}]])) (mf/defc token-context-menu [] @@ -142,11 +148,11 @@ (.setAttribute ^js dropdown "style" new-style)))))) [:& dropdown {:show (boolean mdata) - :on-close #(st/emit! hide-token-context-menu)} + :on-close #(st/emit! tcm/hide-token-context-menu)} [:div {:class (stl/css :token-context-menu) :ref dropdown-ref :style {:top top :left left} :on-context-menu prevent-default} (when (= :token (:type mdata)) [:ul {:class (stl/css :context-list)} - [:& token-pill-context-menu {:token-id (:id mdata)}]])]])) \ No newline at end of file + [:& token-pill-context-menu {:token-id (:token-id mdata)}]])]])) \ No newline at end of file