Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
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
10 changes: 7 additions & 3 deletions src/components/views/avatars/DecoratedRoomAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ interface IProps {
room: Room;
size: string;
displayBadge?: boolean;
forceCount?: boolean;
/**
* If true, show nothing if the notification would only cause a dot to be shown rather than
* a badge. That is: only display badges and not dots. Default: false.
*/
hideIfDot?: boolean;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it were me I would phrase this in the positive as showDot, as I find that a little more comprehensible

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the the reason I didn't go with this is that it would be something like, 'showIfDot', ie. whether to show the component if it would only be a dot. Having it as 'hide' felt more apparent that it was talking about hiding the component itself, rather than some part of the component? It is still, admittedly, a slightly weird option.

oobData?: IOOBData;
viewAvatarOnClick?: boolean;
tooltipProps?: {
Expand Down Expand Up @@ -178,14 +182,14 @@ export default class DecoratedRoomAvatar extends React.PureComponent<IProps, ISt

public render(): React.ReactNode {
// Spread the remaining props to make it work with compound component
const { room, size, displayBadge, forceCount, oobData, viewAvatarOnClick, tooltipProps, ...props } = this.props;
const { room, size, displayBadge, hideIfDot, oobData, viewAvatarOnClick, tooltipProps, ...props } = this.props;

let badge: React.ReactNode;
if (this.props.displayBadge && this.state.notificationState) {
badge = (
<NotificationBadge
notification={this.state.notificationState}
forceCount={this.props.forceCount}
hideIfDot={this.props.hideIfDot}
roomId={this.props.room.roomId}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/rooms/ExtraTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function ExtraTile({

let badge: JSX.Element | null = null;
if (notificationState) {
badge = <NotificationBadge notification={notificationState} forceCount={false} />;
badge = <NotificationBadge notification={notificationState} />;
}

let name = displayName;
Expand Down
15 changes: 8 additions & 7 deletions src/components/views/rooms/NotificationBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ interface IProps {
notification: NotificationState;

/**
* If true, the badge will show a count if at all possible. This is typically
* used to override the user's preference for things like room sublists.
* If true, show nothing if the notification would only cause a dot to be shown rather than
* a badge. That is: only display badges and not dots. Default: false.
*/
forceCount?: boolean;
hideIfDot?: boolean;

/**
* The room ID, if any, the badge represents.
Expand All @@ -48,7 +48,7 @@ interface IClickableProps extends IProps, React.InputHTMLAttributes<Element> {
}

interface IState {
showCounts: boolean; // whether to show counts. Independent of props.forceCount
showCounts: boolean; // whether to show counts.
}

export default class NotificationBadge extends React.PureComponent<XOR<IProps, IClickableProps>, IState> {
Expand Down Expand Up @@ -97,11 +97,12 @@ export default class NotificationBadge extends React.PureComponent<XOR<IProps, I

public render(): ReactNode {
/* eslint @typescript-eslint/no-unused-vars: ["error", { "ignoreRestSiblings": true }] */
const { notification, showUnsentTooltip, forceCount, onClick, tabIndex } = this.props;
const { notification, showUnsentTooltip, hideIfDot, onClick, tabIndex } = this.props;

if (notification.isIdle && !notification.knocked) return null;
if (forceCount) {
if (!notification.hasUnreadCount) return null; // Can't render a badge
if (hideIfDot && notification.level < NotificationLevel.Notification) {
// This would just be a dot and we've been told not to show dots, so don't show it
if (!notification.hasUnreadCount) return null;
}

const commonProps: React.ComponentProps<typeof StatelessNotificationBadge> = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/rooms/RoomBreadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const RoomBreadcrumbTile: React.FC<{ room: Room; onClick: (ev: ButtonEvent) => v
room={room}
size="32px"
displayBadge={true}
forceCount={true}
hideIfDot={true}
tooltipProps={{ tabIndex: isActive ? 0 : -1 }}
/>
</AccessibleTooltipButton>
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/rooms/RoomSublist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ export default class RoomSublist extends React.Component<IProps, IState> {

const badge = (
<NotificationBadge
forceCount={true}
hideIfDot={true}
notification={this.notificationState}
onClick={this.onBadgeClick}
tabIndex={tabIndex}
Expand Down
6 changes: 1 addition & 5 deletions src/components/views/rooms/RoomTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,7 @@ export class RoomTile extends React.PureComponent<ClassProps, State> {
// aria-hidden because we summarise the unread count/highlight status in a manual aria-label below
badge = (
<div className="mx_RoomTile_badgeContainer" aria-hidden="true">
<NotificationBadge
notification={this.notificationState}
forceCount={false}
roomId={this.props.room.roomId}
/>
<NotificationBadge notification={this.notificationState} roomId={this.props.room.roomId} />
</div>
);
}
Expand Down
1 change: 0 additions & 1 deletion src/components/views/spaces/SpaceTreeLevel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export const SpaceButton = <T extends keyof JSX.IntrinsicElements>({
<div className="mx_SpacePanel_badgeContainer">
<NotificationBadge
onClick={jumpToNotification}
forceCount={false}
notification={notificationState}
aria-label={ariaLabel}
tabIndex={tabIndex}
Expand Down