Mark all notifications as read from dashboard (#5805)

*  Mark all notifications as read from dashboard

* ♻️ Mark all notifications as read code review

* ♻️ Mark all notifications as read code review II
This commit is contained in:
María Valderrama 2025-02-14 11:48:24 +01:00 committed by GitHub
parent 8a332c1402
commit 59a57d6c3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 64 additions and 2 deletions

View file

@ -14,8 +14,10 @@
[app.common.uuid :as uuid]
[app.main.data.event :as ev]
[app.main.data.helpers :as dsh]
[app.main.data.notifications :as ntf]
[app.main.data.team :as dtm]
[app.main.repo :as rp]
[app.util.i18n :as i18n :refer [tr]]
[beicon.v2.core :as rx]
[potok.v2.core :as ptk]))
@ -454,6 +456,26 @@
(rx/map #(partial fetched-users %))))))
(rx/catch #(rx/throw {:type :comment-error})))))))
(defn mark-all-threads-as-read
"Mark all threads as read"
[team-id]
(ptk/reify ::mark-all-threads-as-read
ev/Event
(-data [_] {})
ptk/WatchEvent
(watch [_ state _]
(let [threads (-> state :comment-threads vals)]
(rx/concat
(->> (rp/cmd! :mark-all-threads-as-read {:threads (mapv :id threads)})
(rx/map #(retrieve-unread-comment-threads team-id))
(rx/catch #(rx/throw {:type :comment-error})))
(rx/of (ntf/show {:level :info
:type :toast
:content (tr "dashboard.mark-all-as-read.success")
:timeout 7000})))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Local State

View file

@ -63,7 +63,13 @@
(mf/use-callback
(fn [thread]
(st/emit! (-> (dwcm/navigate thread)
(with-meta {::ev/origin "dashboard"})))))]
(with-meta {::ev/origin "dashboard"})))))
on-read-all
(mf/use-callback
(mf/deps team-id)
(fn []
(st/emit! (dcm/mark-all-threads-as-read team-id))))]
(mf/use-effect
(mf/deps team-id)
@ -82,6 +88,13 @@
[:div {:class (stl/css :dropdown :comments-section :comment-threads-section)}
[:div {:class (stl/css :header)}
[:h3 {:class (stl/css :header-title)} (tr "dashboard.notifications")]
(when (seq tgroups)
[:> icon-button* {:variant "ghost"
:tab-index (if show? "0" "-1")
:aria-label (tr "label.mark-all-as-read")
:on-click on-read-all
:icon "tick"}])
[:> icon-button* {:variant "ghost"
:tab-index (if show? "0" "-1")
:aria-label (tr "labels.close")