From 5eef106efe2d29e0bc1e45cf6e5351c928fadf4a Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sat, 3 Sep 2022 17:21:32 +0100 Subject: [PATCH] add NotifPanel badge back. partially fixes https://github.com/vector-im/element-web/issues/17641 provides a dot, but not a badge. fixes chronic bug 87. --- .../views/right_panel/RoomHeaderButtons.tsx | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/components/views/right_panel/RoomHeaderButtons.tsx b/src/components/views/right_panel/RoomHeaderButtons.tsx index 4b5889bc820..2194191ab06 100644 --- a/src/components/views/right_panel/RoomHeaderButtons.tsx +++ b/src/components/views/right_panel/RoomHeaderButtons.tsx @@ -33,7 +33,7 @@ import { useSettingValue } from "../../../hooks/useSettings"; import { useReadPinnedEvents, usePinnedEvents } from './PinnedMessagesCard'; import { showThreadPanel } from "../../../dispatcher/dispatch-actions/threads"; import SettingsStore from "../../../settings/SettingsStore"; -import { RoomNotificationStateStore } from "../../../stores/notifications/RoomNotificationStateStore"; +import { RoomNotificationStateStore, UPDATE_STATUS_INDICATOR } from "../../../stores/notifications/RoomNotificationStateStore"; import { NotificationColor } from "../../../stores/notifications/NotificationColor"; import { ThreadsRoomNotificationState } from "../../../stores/notifications/ThreadsRoomNotificationState"; import { NotificationStateEvents } from "../../../stores/notifications/NotificationState"; @@ -130,29 +130,42 @@ export default class RoomHeaderButtons extends HeaderButtons { RightPanelPhases.ThreadView, ]; private threadNotificationState: ThreadsRoomNotificationState; + private globalNotificationState: SummarizedNotificationState; constructor(props: IProps) { super(props, HeaderKind.Room); this.threadNotificationState = RoomNotificationStateStore.instance.getThreadsRoomState(this.props.room); + this.globalNotificationState = RoomNotificationStateStore.instance.globalState; } public componentDidMount(): void { super.componentDidMount(); this.threadNotificationState.on(NotificationStateEvents.Update, this.onThreadNotification); + RoomNotificationStateStore.instance.on(UPDATE_STATUS_INDICATOR, this.onUpdateStatus); } public componentWillUnmount(): void { super.componentWillUnmount(); this.threadNotificationState.off(NotificationStateEvents.Update, this.onThreadNotification); + RoomNotificationStateStore.instance.off(UPDATE_STATUS_INDICATOR, this.onUpdateStatus); } private onThreadNotification = (): void => { + // XXX: why don't we read from this.state.threadNotificationColor in the render methods? this.setState({ threadNotificationColor: this.threadNotificationState.color, }); }; + private onUpdateStatus = (notificationState: SummarizedNotificationState): void => { + // XXX: why don't we read from this.state.globalNotificationCount in the render methods? + this.globalNotificationState = notificationState; + this.setState({ + globalNotificationColor: notificationState.color, + }); + } + protected onAction(payload: ActionPayload) { if (payload.action === Action.ViewUser) { if (payload.member) { @@ -254,7 +267,10 @@ export default class RoomHeaderButtons extends HeaderButtons { title={_t('Notifications')} isHighlighted={this.isPhase(RightPanelPhases.NotificationPanel)} onClick={this.onNotificationsClicked} - />, + isUnread={this.globalNotificationState.color === NotificationColor.Red} + > + { this.globalNotificationState.color === NotificationColor.Red ? : null } + , ); rightPanelPhaseButtons.set(RightPanelPhases.RoomSummary,