mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 15:39:50 -05:00
🐛 Fix excessive data fetching on workspace comments
This commit is contained in:
parent
9dbf6ffd14
commit
f85a9011ee
2 changed files with 36 additions and 32 deletions
|
@ -134,14 +134,13 @@
|
||||||
(rx/throw {:type :comment-error})))))))))
|
(rx/throw {:type :comment-error})))))))))
|
||||||
|
|
||||||
(defn update-comment-thread-status
|
(defn update-comment-thread-status
|
||||||
[{:keys [id] :as thread}]
|
[thread-id]
|
||||||
(dm/assert! (comment-thread? thread))
|
|
||||||
(ptk/reify ::update-comment-thread-status
|
(ptk/reify ::update-comment-thread-status
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [done #(d/update-in-when % [:comment-threads id] assoc :count-unread-comments 0)
|
(let [done #(d/update-in-when % [:comment-threads thread-id] assoc :count-unread-comments 0)
|
||||||
share-id (-> state :viewer-local :share-id)]
|
share-id (-> state :viewer-local :share-id)]
|
||||||
(->> (rp/cmd! :update-comment-thread-status {:id id :share-id share-id})
|
(->> (rp/cmd! :update-comment-thread-status {:id thread-id :share-id share-id})
|
||||||
(rx/map (constantly done))
|
(rx/map (constantly done))
|
||||||
(rx/catch #(rx/throw {:type :comment-error})))))))
|
(rx/catch #(rx/throw {:type :comment-error})))))))
|
||||||
|
|
||||||
|
|
|
@ -310,40 +310,45 @@
|
||||||
[:li {:on-click on-delete-thread} (tr "labels.delete-comment-thread")]
|
[:li {:on-click on-delete-thread} (tr "labels.delete-comment-thread")]
|
||||||
[:li {:on-click on-delete-comment} (tr "labels.delete-comment")])]]]))
|
[:li {:on-click on-delete-comment} (tr "labels.delete-comment")])]]]))
|
||||||
|
|
||||||
(defn comments-ref
|
(defn make-comments-ref
|
||||||
[{:keys [id] :as thread}]
|
[thread-id]
|
||||||
(l/derived (l/in [:comments id]) st/state))
|
(l/derived (l/in [:comments thread-id]) st/state))
|
||||||
|
|
||||||
(mf/defc thread-comments
|
(mf/defc thread-comments
|
||||||
{::mf/wrap [mf/memo]}
|
{::mf/wrap [mf/memo]}
|
||||||
[{:keys [thread zoom users origin position-modifier]}]
|
[{:keys [thread zoom users origin position-modifier]}]
|
||||||
(let [ref (mf/use-ref)
|
(let [ref (mf/use-ref)
|
||||||
pos (cond-> (:position thread)
|
|
||||||
(some? position-modifier)
|
|
||||||
(gpt/transform position-modifier))
|
|
||||||
|
|
||||||
pos-x (+ (* (:x pos) zoom) 14)
|
|
||||||
pos-y (- (* (:y pos) zoom) 14)
|
|
||||||
|
|
||||||
comments-ref (mf/use-memo (mf/deps thread) #(comments-ref thread))
|
thread-id (:id thread)
|
||||||
|
thread-pos (:position thread)
|
||||||
|
|
||||||
|
pos (cond-> thread-pos
|
||||||
|
(some? position-modifier)
|
||||||
|
(gpt/transform position-modifier))
|
||||||
|
|
||||||
|
pos-x (+ (* (:x pos) zoom) 14)
|
||||||
|
pos-y (- (* (:y pos) zoom) 14)
|
||||||
|
|
||||||
|
comments-ref (mf/with-memo [thread-id]
|
||||||
|
(make-comments-ref thread-id))
|
||||||
comments-map (mf/deref comments-ref)
|
comments-map (mf/deref comments-ref)
|
||||||
comments (->> (vals comments-map)
|
|
||||||
(sort-by :created-at))
|
comments (mf/with-memo [comments-map]
|
||||||
|
(->> (vals comments-map)
|
||||||
|
(sort-by :created-at)))
|
||||||
|
|
||||||
comment (first comments)]
|
comment (first comments)]
|
||||||
|
|
||||||
(mf/use-layout-effect
|
(mf/with-effect [thread-id]
|
||||||
(mf/deps thread)
|
(st/emit! (dcm/retrieve-comments thread-id)))
|
||||||
#(st/emit! (dcm/retrieve-comments (:id thread))))
|
|
||||||
|
|
||||||
(mf/use-effect
|
(mf/with-effect [thread-id]
|
||||||
(mf/deps thread)
|
(st/emit! (dcm/update-comment-thread-status thread-id)))
|
||||||
#(st/emit! (dcm/update-comment-thread-status thread)))
|
|
||||||
|
|
||||||
(mf/use-layout-effect
|
(mf/with-layout-effect [thread-pos comments-map]
|
||||||
(mf/deps thread comments-map)
|
(when-let [node (mf/ref-val ref)]
|
||||||
(fn []
|
(dom/scroll-into-view-if-needed! node)))
|
||||||
(when-let [node (mf/ref-val ref)]
|
|
||||||
(dom/scroll-into-view-if-needed! node))))
|
|
||||||
|
|
||||||
(when (some? comment)
|
(when (some? comment)
|
||||||
[:div.thread-content
|
[:div.thread-content
|
||||||
|
@ -368,12 +373,12 @@
|
||||||
(defn use-buble
|
(defn use-buble
|
||||||
[zoom {:keys [position frame-id]}]
|
[zoom {:keys [position frame-id]}]
|
||||||
(let [dragging-ref (mf/use-ref false)
|
(let [dragging-ref (mf/use-ref false)
|
||||||
start-ref (mf/use-ref nil)
|
start-ref (mf/use-ref nil)
|
||||||
|
|
||||||
state (mf/use-state {:hover false
|
state (mf/use-state {:hover false
|
||||||
:new-position-x nil
|
:new-position-x nil
|
||||||
:new-position-y nil
|
:new-position-y nil
|
||||||
:new-frame-id frame-id})
|
:new-frame-id frame-id})
|
||||||
|
|
||||||
on-pointer-down
|
on-pointer-down
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
|
|
Loading…
Add table
Reference in a new issue