diff --git a/src/main/webapp/app/shared/sidebar/conversation-options/conversation-options.component.html b/src/main/webapp/app/shared/sidebar/conversation-options/conversation-options.component.html index 1d171dc19915..69bc271744d1 100644 --- a/src/main/webapp/app/shared/sidebar/conversation-options/conversation-options.component.html +++ b/src/main/webapp/app/shared/sidebar/conversation-options/conversation-options.component.html @@ -3,7 +3,7 @@
-
diff --git a/src/main/webapp/app/shared/sidebar/sidebar-card-item/sidebar-card-item.component.html b/src/main/webapp/app/shared/sidebar/sidebar-card-item/sidebar-card-item.component.html index c80404948591..15f1ecdd6e90 100644 --- a/src/main/webapp/app/shared/sidebar/sidebar-card-item/sidebar-card-item.component.html +++ b/src/main/webapp/app/shared/sidebar/sidebar-card-item/sidebar-card-item.component.html @@ -47,7 +47,13 @@
} @else {
- + @if (sidebarItem.icon) { } @@ -58,6 +64,9 @@ } + @if (unreadCount() > 0) { + {{ formattedUnreadCount }} + }
diff --git a/src/main/webapp/app/shared/sidebar/sidebar-card-item/sidebar-card-item.component.scss b/src/main/webapp/app/shared/sidebar/sidebar-card-item/sidebar-card-item.component.scss index 6c43e309b90b..64f4e5a920c0 100644 --- a/src/main/webapp/app/shared/sidebar/sidebar-card-item/sidebar-card-item.component.scss +++ b/src/main/webapp/app/shared/sidebar/sidebar-card-item/sidebar-card-item.component.scss @@ -5,3 +5,17 @@ .muted { color: var(--metis-conversation-sidebar-muted); } + +.unread-count { + background-color: var(--bs-primary); + color: var(--bs-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; +} diff --git a/src/main/webapp/app/shared/sidebar/sidebar-card-item/sidebar-card-item.component.ts b/src/main/webapp/app/shared/sidebar/sidebar-card-item/sidebar-card-item.component.ts index 4f68c0108e99..4c294f485fa7 100644 --- a/src/main/webapp/app/shared/sidebar/sidebar-card-item/sidebar-card-item.component.ts +++ b/src/main/webapp/app/shared/sidebar/sidebar-card-item/sidebar-card-item.component.ts @@ -1,4 +1,4 @@ -import { Component, Input } from '@angular/core'; +import { Component, Input, OnChanges, OnInit, SimpleChanges, input } from '@angular/core'; import { SidebarCardElement, SidebarTypes } from 'app/types/sidebar'; @Component({ @@ -6,8 +6,28 @@ import { SidebarCardElement, SidebarTypes } from 'app/types/sidebar'; templateUrl: './sidebar-card-item.component.html', styleUrls: ['./sidebar-card-item.component.scss', '../sidebar.component.scss'], }) -export class SidebarCardItemComponent { +export class SidebarCardItemComponent implements OnInit, OnChanges { @Input() sidebarItem: SidebarCardElement; @Input() sidebarType?: SidebarTypes; @Input() groupKey?: string; + unreadCount = input(0); + + formattedUnreadCount: string = ''; + + ngOnInit(): void { + this.formattedUnreadCount = this.getFormattedUnreadCount(); + } + + ngOnChanges(changes: SimpleChanges): void { + if (changes['unreadCount']) { + this.formattedUnreadCount = this.getFormattedUnreadCount(); + } + } + + private getFormattedUnreadCount(): string { + if (this.unreadCount() > 99) { + return '99+'; + } + return this.unreadCount().toString() || ''; + } } diff --git a/src/main/webapp/app/shared/sidebar/sidebar-card-medium/sidebar-card-medium.component.html b/src/main/webapp/app/shared/sidebar/sidebar-card-medium/sidebar-card-medium.component.html index f01572634bde..4bb0e62c10bb 100644 --- a/src/main/webapp/app/shared/sidebar/sidebar-card-medium/sidebar-card-medium.component.html +++ b/src/main/webapp/app/shared/sidebar/sidebar-card-medium/sidebar-card-medium.component.html @@ -21,6 +21,11 @@ (click)="emitStoreAndRefresh(sidebarItem.id)" [routerLinkActive]="'bg-selected border-selected'" > - +
} diff --git a/src/main/webapp/app/shared/sidebar/sidebar-card-small/sidebar-card-small.component.html b/src/main/webapp/app/shared/sidebar/sidebar-card-small/sidebar-card-small.component.html index fee876319491..ae134a4dfd8d 100644 --- a/src/main/webapp/app/shared/sidebar/sidebar-card-small/sidebar-card-small.component.html +++ b/src/main/webapp/app/shared/sidebar/sidebar-card-small/sidebar-card-small.component.html @@ -10,7 +10,12 @@ [routerLinkActive]="'bg-selected border-selected'" >
- +
@if (sidebarItem.conversation) {
diff --git a/src/test/javascript/spec/component/shared/sidebar/sidebar-card-item.component.spec.ts b/src/test/javascript/spec/component/shared/sidebar/sidebar-card-item.component.spec.ts index e77a8ca29e17..b82e9af01815 100644 --- a/src/test/javascript/spec/component/shared/sidebar/sidebar-card-item.component.spec.ts +++ b/src/test/javascript/spec/component/shared/sidebar/sidebar-card-item.component.spec.ts @@ -3,6 +3,7 @@ import { SidebarCardItemComponent } from 'app/shared/sidebar/sidebar-card-item/s import { SidebarCardSize } from 'app/types/sidebar'; import { ArtemisTestModule } from '../../../test.module'; import { DifficultyLevel } from 'app/entities/exercise.model'; +import { input, runInInjectionContext } from '@angular/core'; describe('SidebarCardItemComponent', () => { let component: SidebarCardItemComponent; @@ -37,4 +38,20 @@ 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', () => { + runInInjectionContext(fixture.debugElement.injector, () => { + component.unreadCount = input(45); + component.ngOnInit(); + expect(component.formattedUnreadCount).toBe('45'); + }); + }); + + it('should format unreadCount as "99+" when count exceeds 99', () => { + runInInjectionContext(fixture.debugElement.injector, () => { + component.unreadCount = input(120); + component.ngOnInit(); + expect(component.formattedUnreadCount).toBe('99+'); + }); + }); });