🐛 Fix reposition comment bubbles under viewer role (#5905)

This commit is contained in:
luisδμ 2025-02-19 16:47:53 +01:00 committed by GitHub
parent 7a7fa44f6b
commit 0784d6b62a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 11 additions and 46 deletions

View file

@ -8,12 +8,10 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.schema :as sm] [app.common.schema :as sm]
[app.common.types.shape-tree :as ctst] [app.common.types.shape-tree :as ctst]
[app.main.data.changes :as dch]
[app.main.data.comments :as dcmt] [app.main.data.comments :as dcmt]
[app.main.data.common :as dcm] [app.main.data.common :as dcm]
[app.main.data.event :as ev] [app.main.data.event :as ev]
@ -134,29 +132,23 @@
(dcmt/check-comment-thread! thread)) (dcmt/check-comment-thread! thread))
(ptk/reify ::update-comment-thread-position (ptk/reify ::update-comment-thread-position
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [_ state _]
(let [page (dsh/lookup-page state) (let [page (dsh/lookup-page state)
page-id (:id page) page-id (:id page)
objects (dsh/lookup-page-objects state page-id) objects (dsh/lookup-page-objects state page-id)
frame-id (if (nil? frame-id) frame-id (if (nil? frame-id)
(ctst/get-frame-id-by-position objects (gpt/point new-x new-y)) (ctst/get-frame-id-by-position objects (gpt/point new-x new-y))
(:frame-id thread)) (:frame-id thread))
thread (-> thread thread (-> thread
(assoc :position (gpt/point new-x new-y)) (assoc :position (gpt/point new-x new-y))
(assoc :frame-id frame-id)) (assoc :frame-id frame-id))
thread-id (:id thread)]
changes (-> (pcb/empty-changes it)
(pcb/with-page page)
(pcb/set-comment-thread-position thread))]
(rx/concat (rx/concat
(rx/merge (rx/of #(update % :comment-threads assoc thread-id thread))
(rx/of (dch/commit-changes changes))
(->> (rp/cmd! :update-comment-thread-position thread) (->> (rp/cmd! :update-comment-thread-position thread)
(rx/catch #(rx/throw {:type :update-comment-thread-position})) (rx/catch #(rx/throw {:type :update-comment-thread-position}))
(rx/ignore))) (rx/ignore))))))))
(rx/of (dcmt/refresh-comment-thread thread))))))))
;; Move comment threads that are inside a frame when that frame is moved" ;; Move comment threads that are inside a frame when that frame is moved"
(defmethod ptk/resolve ::move-frame-comment-threads (defmethod ptk/resolve ::move-frame-comment-threads

View file

@ -301,7 +301,6 @@
(when show-comments? (when show-comments?
[:> comments/comments-layer* {:vbox vbox [:> comments/comments-layer* {:vbox vbox
:page-id page-id
:file-id file-id :file-id file-id
:vport vport :vport vport
:zoom zoom :zoom zoom

View file

@ -9,30 +9,14 @@
(:require (:require
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.main.data.comments :as dcm] [app.main.data.comments :as dcm]
[app.main.data.helpers :as dsh]
[app.main.data.workspace.comments :as dwcm] [app.main.data.workspace.comments :as dwcm]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.comments :as cmt] [app.main.ui.comments :as cmt]
[okulary.core :as l]
[rumext.v2 :as mf])) [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* (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) (let [vbox-x (dm/get-prop vbox :x)
vbox-y (dm/get-prop vbox :y) vbox-y (dm/get-prop vbox :y)
vport-w (dm/get-prop vport :width) vport-w (dm/get-prop vport :width)
@ -44,16 +28,7 @@
profile (mf/deref refs/profile) profile (mf/deref refs/profile)
local (mf/deref refs/comments-local) local (mf/deref refs/comments-local)
positions (mf/deref ref:thread-positions)
threads-map (mf/deref refs/threads) 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 threads
(mf/with-memo [threads-map local profile] (mf/with-memo [threads-map local profile]
@ -93,7 +68,7 @@
(when-let [thread (get threads-map id)] (when-let [thread (get threads-map id)]
(when (seq (dcm/apply-filters local profile [thread])) (when (seq (dcm/apply-filters local profile [thread]))
[:> cmt/comment-floating-thread* [:> cmt/comment-floating-thread*
{:thread (update-position positions thread) {:thread thread
:viewport viewport :viewport viewport
:zoom zoom}]))) :zoom zoom}])))

View file

@ -348,7 +348,6 @@
(when show-comments? (when show-comments?
[:> comments/comments-layer* {:vbox vbox [:> comments/comments-layer* {:vbox vbox
:page-id page-id
:vport vport :vport vport
:zoom zoom :zoom zoom
:drawing drawing}]) :drawing drawing}])