From bd92936a64e43b28eb067b77583dbe8ccd0e4faf Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 1 Oct 2020 14:05:21 +0200 Subject: [PATCH] :sparkles: Allows renaming when new typography and context menu --- .../app/main/data/workspace/libraries.cljs | 7 +++-- .../app/main/ui/workspace/sidebar/assets.cljs | 30 +++++++++++++++---- .../workspace/sidebar/options/typography.cljs | 15 ++++++---- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 246ac8128..1a7328591 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -541,10 +541,13 @@ ptk/WatchEvent (watch [_ state s] (let [rchg {:type :add-typography - :typography typography} + :typography (assoc typography :ts (.now js/Date))} uchg {:type :del-typography :id (:id typography)}] - (rx/of (dwc/commit-changes [rchg] [uchg] {:commit-local? true}))))))) + (rx/of (dwc/commit-changes [rchg] [uchg] {:commit-local? true}) + #(assoc-in % + [:workspace-local :rename-typography] + (:id typography)))))))) (defn update-typography [typography] diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs index c2da2a8fc..06ac0034a 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs @@ -380,10 +380,25 @@ (mf/deps file-id) (fn [event] )) - handle-rename-typography-clicked (fn []) - handle-edit-typography-clicked (fn [] ) - handle-delete-typography (fn [] - (st/emit! (dwl/delete-typography (:id @state))))] + handle-rename-typography-clicked + (fn [] + (st/emit! #(assoc-in % [:workspace-local :rename-typography] (:id @state)))) + + handle-edit-typography-clicked + (fn [] + (st/emit! #(assoc-in % [:workspace-local :edit-typography] (:id @state)))) + + handle-delete-typography + (fn [] + (st/emit! (dwl/delete-typography (:id @state))))] + + (mf/use-effect + (mf/deps local) + (fn [] + (when (:rename-typography local) + (st/emit! #(update % :workspace-local dissoc :rename-typography))) + (when (:edit-typography local) + (st/emit! #(update % :workspace-local dissoc :edit-typography))))) [:div.asset-group [:div.group-title {:class (when (not open?) "closed")} @@ -403,14 +418,17 @@ [(t locale "workspace.assets.delete") handle-delete-typography]]}] (when open? [:div.group-list - (for [typography (sort-by (comp - :ts) typographies)] + (for [typography (sort-by :ts typographies)] [:& typography-entry {:key (:id typography) :typography typography :read-only? (not local?) :on-context-menu #(on-context-menu (:id typography) %) :on-change #(handle-change typography %) - :on-select #(handle-typography-selection typography)}])])])) + :on-select #(handle-typography-selection typography) + :editting? (or (= (:rename-typography local) (:id typography)) + (= (:edit-typography local) (:id typography))) + :focus-name? (= (:rename-typography local) (:id typography))}])])])) (defn file-colors-ref [id] diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/typography.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/typography.cljs index 167069559..9f93b8e05 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/typography.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/typography.cljs @@ -18,8 +18,9 @@ [app.main.data.workspace.texts :as dwt] [app.main.ui.components.editable-select :refer [editable-select]] [app.main.ui.workspace.sidebar.options.common :refer [advanced-options]] - [app.util.dom :as dom] [app.main.fonts :as fonts] + [app.util.dom :as dom] + [app.util.timers :as ts] [app.util.i18n :as i18n :refer [t]])) (defn- attr->string [value] @@ -216,14 +217,18 @@ (mf/use-effect (mf/deps editting?) - (fn [] (reset! open? editting?))) + (fn [] + (when editting? + (reset! open? editting?)))) (mf/use-effect (mf/deps focus-name?) (fn [] - (when-let [node (mf/ref-val name-input-ref)] - (dom/focus! node) - (dom/select-text! node)))) + (when focus-name? + (ts/schedule 100 + #(when-let [node (mf/ref-val name-input-ref)] + (dom/focus! node) + (dom/select-text! node)))))) [:* [:div.element-set-options-group.typography-entry