Skip to content

Commit

Permalink
merge duplicated notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc committed Jan 31, 2024
1 parent ae4593e commit 1797c20
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/renderer/notification/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
(rf/reg-event-db
:notification/add
(fn [db [_ notification]]
(update db :notifications conj notification)))
(let [notifications (:notifications db)]
(if (= (:content notification) (-> notifications peek :content))
(assoc db :notifications
(conj (pop notifications) (update (peek notifications) :count inc)))
(update db :notifications conj notification)))))

(rf/reg-event-db
:notification/remove
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/notification/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
}

.toast {
@apply flex level-3 w-80 p-4 mb-2 rounded shadow-md;
@apply relative flex level-3 w-80 p-4 mb-2 rounded shadow-md;

max-width: 100vw;
}
Expand All @@ -14,3 +14,8 @@
grid-area: description;
line-height: 1.3;
}

.toast-count {
@apply absolute error left-0 top-0 px-1 py-0.5 rounded;
transform: translate(-50%, -50%);
}
5 changes: 3 additions & 2 deletions src/renderer/notification/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
[]
(let [notifications @(rf/subscribe [:notifications])]
[:div.fixed.flex.flex-col.m-4.right-0.bottom-0.gap-2.items-end

[:div
(map-indexed
(fn [index notification]
Expand All @@ -21,7 +20,9 @@
{:title "Dismiss"
:style {:width "auto"
:height "fit-content"}
:on-click #(rf/dispatch [:notification/remove index])}]])
:on-click #(rf/dispatch [:notification/remove index])}]
(when-let [count (:count notification)]
[:div.toast-count count])])
notifications)]

(when (second notifications)
Expand Down

0 comments on commit 1797c20

Please sign in to comment.