From 920638a14987b0d83a0ae079341955af41ab5a52 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 14 Jan 2025 12:38:03 +0100 Subject: [PATCH] :sparkles: Open comments from email with parameter --- backend/src/app/rpc/commands/comments.clj | 7 ++-- frontend/src/app/main/data/workspace.cljs | 8 ++++ .../src/app/main/data/workspace/comments.cljs | 37 +++++++++++++++++-- .../src/app/main/ui/workspace/comments.cljs | 15 +------- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/backend/src/app/rpc/commands/comments.clj b/backend/src/app/rpc/commands/comments.clj index f649f577b..a3253085c 100644 --- a/backend/src/app/rpc/commands/comments.clj +++ b/backend/src/app/rpc/commands/comments.clj @@ -47,13 +47,14 @@ (str/join ""))) (defn- format-comment-url - [{:keys [team-id file-id page-id]}] + [thread {:keys [team-id file-id page-id]}] (str/ffmt "%/#/workspace?%" (cf/get :public-uri) (uri/map->query-string {:file-id file-id :page-id page-id - :team-id team-id}))) + :team-id team-id + :comment-id (:id thread)}))) (defn- format-comment-ref [{:keys [seqn]} {:keys [file-name page-name]}] @@ -89,7 +90,7 @@ comment-reference (format-comment-ref thread params) comment-content (format-comment comment) - comment-url (format-comment-url params) + comment-url (format-comment-url thread params) ;; Users mentioned in this comment comment-mentions diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index e84646e67..09b447bae 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -48,6 +48,7 @@ [app.main.data.workspace.bool :as dwb] [app.main.data.workspace.collapse :as dwco] [app.main.data.workspace.colors :as dwcl] + [app.main.data.workspace.comments :as dwcm] [app.main.data.workspace.drawing :as dwd] [app.main.data.workspace.edition :as dwe] [app.main.data.workspace.fix-broken-shapes :as fbs] @@ -355,6 +356,13 @@ (rx/take 1) (rx/map zoom-to-frame))) + (when-let [comment-id (some-> rparams :comment-id parse-uuid)] + (->> stream + (rx/filter (ptk/type? ::workspace-initialized)) + (rx/observe-on :async) + (rx/take 1) + (rx/map #(dwcm/navigate-to-comment-id comment-id)))) + (->> stream (rx/filter dch/commit?) (rx/map deref) diff --git a/frontend/src/app/main/data/workspace/comments.cljs b/frontend/src/app/main/data/workspace/comments.cljs index 1688ec332..2eb9a26ff 100644 --- a/frontend/src/app/main/data/workspace/comments.cljs +++ b/frontend/src/app/main/data/workspace/comments.cljs @@ -6,6 +6,7 @@ (ns app.main.data.workspace.comments (:require + [app.common.data :as d] [app.common.data.macros :as dm] [app.common.files.changes-builder :as pcb] [app.common.geom.point :as gpt] @@ -16,12 +17,14 @@ [app.main.data.comments :as dcmt] [app.main.data.common :as dcm] [app.main.data.event :as ev] - [app.main.data.workspace :as dw] [app.main.data.workspace.common :as dwco] [app.main.data.workspace.drawing :as dwd] + [app.main.data.workspace.edition :as dwe] + [app.main.data.workspace.selection :as dws] [app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.viewport :as dwv] [app.main.repo :as rp] + [app.main.router :as rt] [app.main.streams :as ms] [app.util.mouse :as mse] [beicon.v2.core :as rx] @@ -64,8 +67,8 @@ (:open local) (rx/of (dcmt/close-thread)) :else - (rx/of (dw/clear-edition-mode) - (dw/deselect-all true))))))) + (rx/of (dwe/clear-edition-mode) + (dws/deselect-all true))))))) ;; Event responsible of the what should be executed when user clicked ;; on the comments layer. An option can be create a new draft thread, @@ -200,3 +203,31 @@ (filter (comp frame-ids? :frame-id)) (map build-move-event) (rx/from)))))) + +(defn navigate-to-comment + [thread] + (ptk/reify ::navigate-to-comment + ptk/WatchEvent + (watch [_ state _] + (rx/concat + (rx/of + (rt/nav :workspace + (-> (rt/get-params state) + (assoc :page-id (:page-id thread)) + (dissoc :comment-id)) + {::rt/replace true})) + (->> (rx/of + (dwd/select-for-drawing :comments) + (center-to-comment-thread thread) + (with-meta (dcmt/open-thread thread) {::ev/origin "workspace"})) + (rx/observe-on :async)))))) + +(defn navigate-to-comment-id + [thread-id] + (ptk/reify ::navigate-to-comment-id + ptk/WatchEvent + (watch [_ state _] + (let [file-id (:current-file-id state)] + (->> (rp/cmd! :get-comment-threads {:file-id file-id}) + (rx/map #(d/seek (fn [{:keys [id]}] (= thread-id id)) %)) + (rx/map navigate-to-comment)))))) diff --git a/frontend/src/app/main/ui/workspace/comments.cljs b/frontend/src/app/main/ui/workspace/comments.cljs index 290e3f299..2d416ebcc 100644 --- a/frontend/src/app/main/ui/workspace/comments.cljs +++ b/frontend/src/app/main/ui/workspace/comments.cljs @@ -8,12 +8,9 @@ (:require-macros [app.main.style :as stl]) (:require [app.main.data.comments :as dcmt] - [app.main.data.common :as dcm] - [app.main.data.event :as ev] [app.main.data.workspace :as dw] [app.main.data.workspace.comments :as dwcm] [app.main.refs :as refs] - [app.main.router :as rt] [app.main.store :as st] [app.main.ui.comments :as cmt] [app.main.ui.components.dropdown :refer [dropdown]] @@ -22,7 +19,6 @@ [app.main.ui.icons :as i] [app.util.dom :as dom] [app.util.i18n :as i18n :refer [tr]] - [app.util.timers :as tm] [rumext.v2 :as mf])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -119,16 +115,7 @@ (mf/use-fn (mf/deps page-id) (fn [thread] - (when (not= page-id (:page-id thread)) - (st/emit! (dcm/go-to-workspace :page-id (:page-id thread) - ::rt/new-window true))) - (tm/schedule - (fn [] - (st/emit! (when (not= page-id (:page-id thread)) - (dw/select-for-drawing :comments)) - (dwcm/center-to-comment-thread thread) - (-> (dcmt/open-thread thread) - (with-meta {::ev/origin "workspace"})))))))] + (st/emit! (dwcm/navigate-to-comment thread))))] [:div {:class (stl/css-case :comments-section true :from-viewer from-viewer)}