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: Improve unread messages count view on sidebar #9522

Merged
merged 10 commits into from
Oct 20, 2024
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 && unreadCount > 0 ? 'bold-text' : 'fw-semibold'"
krusche marked this conversation as resolved.
Show resolved Hide resolved
krusche marked this conversation as resolved.
Show resolved Hide resolved
>
@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 && unreadCount > 0) {
asliayk marked this conversation as resolved.
Show resolved Hide resolved
<span class="unread-count">{{ formattedUnreadCount }}</span>
asliayk marked this conversation as resolved.
Show resolved Hide resolved
}
</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,23 @@
.muted {
color: var(--metis-conversation-sidebar-muted);
}

.unread-count {
background-color: var(--bs-primary);
color: white;
padding: 0.1rem;
border-radius: 50%;
font-size: clamp(0.4rem, 1vw, 0.7rem);
width: 1.5rem;
height: 1.4rem;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
white-space: nowrap;
flex-shrink: 0;
}
asliayk marked this conversation as resolved.
Show resolved Hide resolved

.bold-text {
asliayk marked this conversation as resolved.
Show resolved Hide resolved
font-weight: 850;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
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() unreadCount!: number | undefined;

krusche marked this conversation as resolved.
Show resolved Hide resolved
asliayk marked this conversation as resolved.
Show resolved Hide resolved
formattedUnreadCount: string = '';

ngOnInit(): void {
this.formattedUnreadCount = this.getFormattedUnreadCount();
asliayk marked this conversation as resolved.
Show resolved Hide resolved
}

private getFormattedUnreadCount(): string {
if (this.unreadCount !== undefined && this.unreadCount > 99) {
return '99+';
asliayk marked this conversation as resolved.
Show resolved Hide resolved
}
return this.unreadCount?.toString() || '';
}
}
krusche marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
(click)="emitStoreAndRefresh(sidebarItem.id)"
[routerLinkActive]="'bg-selected border-selected'"
>
<jhi-sidebar-card-item [sidebarType]="sidebarType" [sidebarItem]="sidebarItem" />
<jhi-sidebar-card-item [unreadCount]="this.sidebarItem.conversation?.unreadMessagesCount" [sidebarType]="sidebarType" [sidebarItem]="sidebarItem" />
asliayk marked this conversation as resolved.
Show resolved Hide resolved
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
(click)="emitStoreAndRefresh(sidebarItem.id)"
[routerLinkActive]="'bg-selected border-selected'"
>
<jhi-sidebar-card-item [sidebarType]="sidebarType" [sidebarItem]="sidebarItem" />
<jhi-sidebar-card-item [unreadCount]="this.sidebarItem.conversation?.unreadMessagesCount" [sidebarType]="sidebarType" [sidebarItem]="sidebarItem" />
asliayk marked this conversation as resolved.
Show resolved Hide resolved
</div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[routerLinkActive]="'bg-selected border-selected'"
>
<div class="w-75 align-self-center">
<jhi-sidebar-card-item [sidebarType]="sidebarType" [sidebarItem]="sidebarItem" />
<jhi-sidebar-card-item [unreadCount]="this.sidebarItem.conversation?.unreadMessagesCount" [sidebarType]="sidebarType" [sidebarItem]="sidebarItem" />
asliayk marked this conversation as resolved.
Show resolved Hide resolved
</div>
@if (sidebarItem.conversation) {
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,22 @@ 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+');
});

it('should return an empty string if unreadCount is undefined', () => {
component.unreadCount = undefined;
component.ngOnInit();
expect(component.formattedUnreadCount).toBe('');
});
});
Loading