From 0784d6b62a81211f4a5ba15e3555800228c02d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?luis=CE=B4=CE=BC?= Date: Wed, 19 Feb 2025 16:47:53 +0100 Subject: [PATCH] :bug: Fix reposition comment bubbles under viewer role (#5905) --- .../src/app/main/data/workspace/comments.cljs | 26 ++++++----------- .../src/app/main/ui/workspace/viewport.cljs | 1 - .../main/ui/workspace/viewport/comments.cljs | 29 ++----------------- .../app/main/ui/workspace/viewport_wasm.cljs | 1 - 4 files changed, 11 insertions(+), 46 deletions(-) diff --git a/frontend/src/app/main/data/workspace/comments.cljs b/frontend/src/app/main/data/workspace/comments.cljs index c47fedeaa..36fe3c835 100644 --- a/frontend/src/app/main/data/workspace/comments.cljs +++ b/frontend/src/app/main/data/workspace/comments.cljs @@ -8,12 +8,10 @@ (: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] [app.common.geom.shapes :as gsh] [app.common.schema :as sm] [app.common.types.shape-tree :as ctst] - [app.main.data.changes :as dch] [app.main.data.comments :as dcmt] [app.main.data.common :as dcm] [app.main.data.event :as ev] @@ -125,38 +123,32 @@ {::ev/origin "workspace"})))))))) (defn update-comment-thread-position - ([thread [new-x new-y]] - (update-comment-thread-position thread [new-x new-y] nil)) + ([thread [new-x new-y]] + (update-comment-thread-position thread [new-x new-y] nil)) - ([thread [new-x new-y] frame-id] + ([thread [new-x new-y] frame-id] (dm/assert! "expected valid comment thread" (dcmt/check-comment-thread! thread)) (ptk/reify ::update-comment-thread-position ptk/WatchEvent - (watch [it state _] + (watch [_ state _] (let [page (dsh/lookup-page state) page-id (:id page) objects (dsh/lookup-page-objects state page-id) frame-id (if (nil? frame-id) (ctst/get-frame-id-by-position objects (gpt/point new-x new-y)) (:frame-id thread)) - thread (-> thread (assoc :position (gpt/point new-x new-y)) (assoc :frame-id frame-id)) - - changes (-> (pcb/empty-changes it) - (pcb/with-page page) - (pcb/set-comment-thread-position thread))] + thread-id (:id thread)] (rx/concat - (rx/merge - (rx/of (dch/commit-changes changes)) - (->> (rp/cmd! :update-comment-thread-position thread) - (rx/catch #(rx/throw {:type :update-comment-thread-position})) - (rx/ignore))) - (rx/of (dcmt/refresh-comment-thread thread)))))))) + (rx/of #(update % :comment-threads assoc thread-id thread)) + (->> (rp/cmd! :update-comment-thread-position thread) + (rx/catch #(rx/throw {:type :update-comment-thread-position})) + (rx/ignore)))))))) ;; Move comment threads that are inside a frame when that frame is moved" (defmethod ptk/resolve ::move-frame-comment-threads diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index 2a31a1013..ebeafcad2 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -301,7 +301,6 @@ (when show-comments? [:> comments/comments-layer* {:vbox vbox - :page-id page-id :file-id file-id :vport vport :zoom zoom diff --git a/frontend/src/app/main/ui/workspace/viewport/comments.cljs b/frontend/src/app/main/ui/workspace/viewport/comments.cljs index c08a7f218..74ceafbae 100644 --- a/frontend/src/app/main/ui/workspace/viewport/comments.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/comments.cljs @@ -9,30 +9,14 @@ (:require [app.common.data.macros :as dm] [app.main.data.comments :as dcm] - [app.main.data.helpers :as dsh] [app.main.data.workspace.comments :as dwcm] [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.comments :as cmt] - [okulary.core :as l] [rumext.v2 :as mf])) -(defn- update-position - [positions {:keys [id] :as thread}] - (if (contains? positions id) - (-> thread - (assoc :position (dm/get-in positions [id :position])) - (assoc :frame-id (dm/get-in positions [id :frame-id]))) - thread)) - -(def ^:private ref:thread-positions - (l/derived (fn [state] - (-> (dsh/lookup-page state) - (get :comment-thread-positions))) - st/state)) - (mf/defc comments-layer* - [{:keys [vbox vport zoom drawing file-id page-id]}] + [{:keys [vbox vport zoom drawing file-id]}] (let [vbox-x (dm/get-prop vbox :x) vbox-y (dm/get-prop vbox :y) vport-w (dm/get-prop vport :width) @@ -44,16 +28,7 @@ profile (mf/deref refs/profile) local (mf/deref refs/comments-local) - positions (mf/deref ref:thread-positions) - threads-map (mf/deref refs/threads) - threads-map (mf/with-memo [threads-map page-id positions] - (reduce-kv (fn [threads id thread] - (if (= (:page-id thread) page-id) - (assoc threads id (update-position positions thread)) - threads)) - {} - threads-map)) threads (mf/with-memo [threads-map local profile] @@ -93,7 +68,7 @@ (when-let [thread (get threads-map id)] (when (seq (dcm/apply-filters local profile [thread])) [:> cmt/comment-floating-thread* - {:thread (update-position positions thread) + {:thread thread :viewport viewport :zoom zoom}]))) diff --git a/frontend/src/app/main/ui/workspace/viewport_wasm.cljs b/frontend/src/app/main/ui/workspace/viewport_wasm.cljs index 3de0c4c9d..d74fea809 100644 --- a/frontend/src/app/main/ui/workspace/viewport_wasm.cljs +++ b/frontend/src/app/main/ui/workspace/viewport_wasm.cljs @@ -348,7 +348,6 @@ (when show-comments? [:> comments/comments-layer* {:vbox vbox - :page-id page-id :vport vport :zoom zoom :drawing drawing}])