diff --git a/frontend/src/app/main/data/comments.cljs b/frontend/src/app/main/data/comments.cljs index ce58747df..65f409178 100644 --- a/frontend/src/app/main/data/comments.cljs +++ b/frontend/src/app/main/data/comments.cljs @@ -134,14 +134,13 @@ (rx/throw {:type :comment-error}))))))))) (defn update-comment-thread-status - [{:keys [id] :as thread}] - (dm/assert! (comment-thread? thread)) + [thread-id] (ptk/reify ::update-comment-thread-status ptk/WatchEvent (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)] - (->> (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/catch #(rx/throw {:type :comment-error}))))))) diff --git a/frontend/src/app/main/ui/comments.cljs b/frontend/src/app/main/ui/comments.cljs index 99c883348..7adcede2d 100644 --- a/frontend/src/app/main/ui/comments.cljs +++ b/frontend/src/app/main/ui/comments.cljs @@ -310,40 +310,45 @@ [:li {:on-click on-delete-thread} (tr "labels.delete-comment-thread")] [:li {:on-click on-delete-comment} (tr "labels.delete-comment")])]]])) -(defn comments-ref - [{:keys [id] :as thread}] - (l/derived (l/in [:comments id]) st/state)) +(defn make-comments-ref + [thread-id] + (l/derived (l/in [:comments thread-id]) st/state)) (mf/defc thread-comments {::mf/wrap [mf/memo]} [{:keys [thread zoom users origin position-modifier]}] - (let [ref (mf/use-ref) - pos (cond-> (:position thread) - (some? position-modifier) - (gpt/transform position-modifier)) + (let [ref (mf/use-ref) - 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 (->> (vals comments-map) - (sort-by :created-at)) + + comments (mf/with-memo [comments-map] + (->> (vals comments-map) + (sort-by :created-at))) + comment (first comments)] - (mf/use-layout-effect - (mf/deps thread) - #(st/emit! (dcm/retrieve-comments (:id thread)))) + (mf/with-effect [thread-id] + (st/emit! (dcm/retrieve-comments thread-id))) - (mf/use-effect - (mf/deps thread) - #(st/emit! (dcm/update-comment-thread-status thread))) + (mf/with-effect [thread-id] + (st/emit! (dcm/update-comment-thread-status thread-id))) - (mf/use-layout-effect - (mf/deps thread comments-map) - (fn [] - (when-let [node (mf/ref-val ref)] - (dom/scroll-into-view-if-needed! node)))) + (mf/with-layout-effect [thread-pos comments-map] + (when-let [node (mf/ref-val ref)] + (dom/scroll-into-view-if-needed! node))) (when (some? comment) [:div.thread-content @@ -368,12 +373,12 @@ (defn use-buble [zoom {:keys [position frame-id]}] (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 - :new-position-x nil - :new-position-y nil - :new-frame-id frame-id}) + state (mf/use-state {:hover false + :new-position-x nil + :new-position-y nil + :new-frame-id frame-id}) on-pointer-down (mf/use-fn