From fcd7a35b466b62077dcb69dc315ad75951ccbd1c Mon Sep 17 00:00:00 2001 From: Akshay Gupta Date: Wed, 15 May 2024 12:59:18 +0530 Subject: [PATCH] move context menu functions to data/tokens --- frontend/src/app/main/data/tokens.cljs | 29 +++++++++++++++ .../app/main/ui/workspace/tokens/common.cljs | 36 +------------------ .../ui/workspace/tokens/context_menu.cljs | 6 ++-- .../app/main/ui/workspace/tokens/sidebar.cljs | 10 +++--- 4 files changed, 38 insertions(+), 43 deletions(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index e3e16b2d3..ac1be4897 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -8,6 +8,7 @@ (:require [app.common.data.macros :as dm] [app.common.files.changes-builder :as pcb] + [app.common.geom.point :as gpt] [app.common.types.shape :as cts] [app.common.uuid :as uuid] [app.main.data.workspace.changes :as dch] @@ -108,3 +109,31 @@ (= (toggle-or-apply-token shape-after-token-2-is-applied token-3) shape-after-token-3-is-applied) nil) + +;; Token Context Menu Functions ------------------------------------------------- + +(defn show-token-context-menu + [{:keys [position token-id] :as params}] + (dm/assert! (gpt/point? position)) + (ptk/reify ::show-token-context-menu + ptk/UpdateEvent + (update [_ state] + (assoc-in state [:workspace-local :token-context-menu] params)))) + +(def hide-token-context-menu + (ptk/reify ::hide-token-context-menu + ptk/UpdateEvent + (update [_ state] + (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/common.cljs b/frontend/src/app/main/ui/workspace/tokens/common.cljs index d53805959..39fc4f58b 100644 --- a/frontend/src/app/main/ui/workspace/tokens/common.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/common.cljs @@ -7,12 +7,6 @@ (ns app.main.ui.workspace.tokens.common (: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])) ;; Helpers --------------------------------------------------------------------- @@ -44,32 +38,4 @@ [:input {:ref input-ref :default-value default-value :autoFocus auto-focus? - :on-change on-change}]]) - -;; Token Context Menu Functions ------------------------------------------------- - -(defn show-token-context-menu - [{:keys [position token-id] :as params}] - (dm/assert! (gpt/point? position)) - (ptk/reify ::show-token-context-menu - ptk/UpdateEvent - (update [_ state] - (assoc-in state [:workspace-local :token-context-menu] params)))) - -(def hide-token-context-menu - (ptk/reify ::hide-token-context-menu - ptk/UpdateEvent - (update [_ state] - (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 + :on-change on-change}]]) \ 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 8233316aa..f6a9f8d4e 100644 --- a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs @@ -12,12 +12,12 @@ [app.main.data.events :as ev] [app.main.data.modal :as modal] [app.main.data.shortcuts :as scd] + [app.main.data.tokens :as dt] [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 :as tcm] [app.util.dom :as dom] [app.util.timers :as timers] [okulary.core :as l] @@ -114,7 +114,7 @@ (mf/defc token-pill-context-menu [{:keys [token-id]}] - (let [delete-fn #(st/emit! (tcm/delete-token token-id)) + (let [delete-fn #(st/emit! (dt/delete-token token-id)) do-delete #(st/emit! (modal/show {:type :confirm :title "Delete" @@ -148,7 +148,7 @@ (.setAttribute ^js dropdown "style" new-style)))))) [:& dropdown {:show (boolean mdata) - :on-close #(st/emit! tcm/hide-token-context-menu)} + :on-close #(st/emit! dt/hide-token-context-menu)} [:div {:class (stl/css :token-context-menu) :ref dropdown-ref :style {:top top :left left} diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index c1eba6e12..f8bdfe226 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -15,7 +15,7 @@ [app.main.ui.components.search-bar :refer [search-bar]] [app.main.ui.icons :as i] [app.main.ui.workspace.sidebar.assets.common :as cmm] - [app.main.ui.workspace.tokens.common :as tcm] + [app.main.ui.workspace.tokens.common :refer [workspace-shapes]] [app.main.ui.workspace.tokens.core :refer [tokens-applied?] :as wtc] [app.util.dom :as dom] [rumext.v2 :as mf])) @@ -54,9 +54,9 @@ (fn [event token] (dom/prevent-default event) (dom/stop-propagation event) - (st/emit! (tcm/show-token-context-menu {:type :token - :position (dom/get-client-position event) - :token-id (:id token)})))) + (st/emit! (dt/show-token-context-menu {:type :token + :position (dom/get-client-position event) + :token-id (:id token)})))) on-toggle-open-click (mf/use-fn (mf/deps open? tokens) @@ -125,7 +125,7 @@ token-groups (mf/with-memo [tokens] (sorted-token-groups tokens)) selected-shape-ids (mf/deref refs/selected-shapes) - selected-shapes (tcm/workspace-shapes workspace-data current-page-id selected-shape-ids)] + selected-shapes (workspace-shapes workspace-data current-page-id selected-shape-ids)] [:article [:div.assets-bar (for [{:keys [token-key token-type-props tokens]} (concat (:filled token-groups)