Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Popover } from "@headlessui/react";
import { mdiBell, mdiBellOutline } from "@mdi/js";
import React, { useCallback, useEffect, useRef, useState } from "react";
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useSelector } from "react-redux";

import { useExtensionContext } from "../../../../ExtensionProvider";
Expand All @@ -23,6 +23,10 @@ const NotificationsContent: React.FC<{ popoverOpen: boolean }> = ({
const api = extensions.getApi();

const notifications = useSelector(notificationsSelector);
const visibleCount = useMemo(
() => notifications.filter((n) => n.type !== "silent").length,
[notifications],
);
const buttonRef = useRef<HTMLButtonElement>(null);
const prevIdsRef = useRef(new Set(notifications.map((n) => n.id)));

Expand All @@ -48,10 +52,13 @@ const NotificationsContent: React.FC<{ popoverOpen: boolean }> = ({
}
}, [popoverOpen, expand]);

// Auto-open popover when new notifications arrive
// Auto-open popover when new notifications arrive.
// Silent notifications should never open the tray.
useEffect(() => {
const currentIds = new Set(notifications.map((n) => n.id));
const hasNew = notifications.some((n) => !prevIdsRef.current.has(n.id));
const hasNew = notifications.some(
(n) => !prevIdsRef.current.has(n.id) && n.type !== "silent",
);
prevIdsRef.current = currentIds;

if (hasNew && !popoverOpen && buttonRef.current) {
Expand All @@ -65,9 +72,9 @@ const NotificationsContent: React.FC<{ popoverOpen: boolean }> = ({
<>
<Popover.Button
as={IconButton}
disabled={notifications.length === 0}
iconPath={notifications.length > 0 ? mdiBell : mdiBellOutline}
itemCount={notifications.length}
disabled={visibleCount === 0}
iconPath={visibleCount > 0 ? mdiBell : mdiBellOutline}
itemCount={visibleCount}
ref={buttonRef}
title="Notifications"
onClick={() => {
Expand Down
Loading