0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-06 12:01:19 -05:00

🐛 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
[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

View file

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

View file

@ -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}])))

View file

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