Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communication: Refactor unread messages count view on sidebar #9522

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@
</div>
} @else {
<div class="d-flex justify-content-between align-items-baseline">
<span id="test-sidebar-card-title" class="small fw-semibold text-truncate me-2" [title]="sidebarItem.title" [class.muted]="sidebarItem.conversation?.isMuted">
<span
id="test-sidebar-card-title"
class="small text-truncate me-2"
[title]="sidebarItem.title"
[class.muted]="sidebarItem.conversation?.isMuted"
[ngClass]="unreadCount > 0 ? 'fw-bold' : 'fw-semibold'"
>
@if (sidebarItem.icon) {
<fa-icon [fixedWidth]="true" [icon]="sidebarItem.icon" />
}
Expand All @@ -58,6 +64,9 @@
<fa-icon [fixedWidth]="true" [icon]="sidebarItem.rightIcon" />
}
</span>
@if (unreadCount > 0) {
<span class="unread-count">{{ formattedUnreadCount }}</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

I would decrease the spacing between the heart and the counter: me-n2
In addition I would also add px-2 to the button of the faEllipsisVertical icon in the conversation-options.component.html file

}
</div>
<div class="d-flex justify-content-between align-items-baseline small" [ngClass]="{ 'mt-1': sidebarItem.subtitleLeft }">
<small class="me-2 text-truncate">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,17 @@
.muted {
color: var(--metis-conversation-sidebar-muted);
}

.unread-count {
background-color: var(--bs-primary);
color: white;
border-radius: 50%;
font-size: 0.6rem;
width: 1.1rem;
height: 1.1rem;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
white-space: nowrap;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { Component, Input } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import { SidebarCardElement, SidebarTypes } from 'app/types/sidebar';

@Component({
selector: 'jhi-sidebar-card-item',
templateUrl: './sidebar-card-item.component.html',
styleUrls: ['./sidebar-card-item.component.scss', '../sidebar.component.scss'],
})
export class SidebarCardItemComponent {
export class SidebarCardItemComponent implements OnInit {
@Input() sidebarItem: SidebarCardElement;
@Input() sidebarType?: SidebarTypes;
@Input() groupKey?: string;
@Input() unreadCount: number = 0;

formattedUnreadCount: string = '';

ngOnInit(): void {
this.formattedUnreadCount = this.getFormattedUnreadCount();
}

private getFormattedUnreadCount(): string {
if (this.unreadCount > 99) {
return '99+';
}
return this.unreadCount?.toString() || '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
(click)="emitStoreAndRefresh(sidebarItem.id)"
[routerLinkActive]="'bg-selected border-selected'"
>
<jhi-sidebar-card-item [groupKey]="groupKey" [sidebarType]="sidebarType" [sidebarItem]="sidebarItem" />
<jhi-sidebar-card-item
[unreadCount]="this.sidebarItem.conversation?.unreadMessagesCount ?? 0"
[groupKey]="groupKey"
[sidebarType]="sidebarType"
[sidebarItem]="sidebarItem"
/>
</div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
[routerLinkActive]="'bg-selected border-selected'"
>
<div class="w-75 align-self-center">
<jhi-sidebar-card-item [groupKey]="groupKey" [sidebarType]="sidebarType" [sidebarItem]="sidebarItem" />
<jhi-sidebar-card-item
[unreadCount]="this.sidebarItem.conversation?.unreadMessagesCount ?? 0"
[groupKey]="groupKey"
[sidebarType]="sidebarType"
[sidebarItem]="sidebarItem"
/>
</div>
@if (sidebarItem.conversation) {
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@ describe('SidebarCardItemComponent', () => {
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('#test-sidebar-card-title').textContent).toContain(testItem.title);
});

it('should format unreadCount correctly when count is less than 99', () => {
component.unreadCount = 45;
component.ngOnInit();
expect(component.formattedUnreadCount).toBe('45');
});

it('should format unreadCount as "99+" when count exceeds 99', () => {
component.unreadCount = 120;
component.ngOnInit();
expect(component.formattedUnreadCount).toBe('99+');
});
});
Loading