improvement: notify counter badge added to treatment and tasks tabs for upadted and edited cases.
This commit is contained in:
31
frontend/src/lib/tabBadgeUtils.ts
Normal file
31
frontend/src/lib/tabBadgeUtils.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
export type TabBadgeCounts = {
|
||||
cases?: number;
|
||||
tasks?: number;
|
||||
treatment?: number;
|
||||
};
|
||||
|
||||
export type LabCaseTabReadTarget = 'CASES' | 'TASKS' | 'TREATMENT';
|
||||
|
||||
const TAB_BADGES_CHANGED_EVENT = 'tab-badges-changed';
|
||||
|
||||
export function notifyTabBadgesChanged() {
|
||||
window.dispatchEvent(new Event(TAB_BADGES_CHANGED_EVENT));
|
||||
}
|
||||
|
||||
export function tabBadgesChangedEventName() {
|
||||
return TAB_BADGES_CHANGED_EVENT;
|
||||
}
|
||||
|
||||
export function tabFromPathname(pathname: string): LabCaseTabReadTarget | null {
|
||||
if (pathname === '/cases' || pathname.startsWith('/cases/')) return 'CASES';
|
||||
if (pathname === '/tasks' || pathname.startsWith('/tasks/')) return 'TASKS';
|
||||
if (pathname === '/treatment' || pathname.startsWith('/treatment/')) return 'TREATMENT';
|
||||
return null;
|
||||
}
|
||||
|
||||
export function badgeCountForPath(counts: TabBadgeCounts, pathname: string): number {
|
||||
if (pathname === '/cases' || pathname.startsWith('/cases/')) return counts.cases ?? 0;
|
||||
if (pathname === '/tasks' || pathname.startsWith('/tasks/')) return counts.tasks ?? 0;
|
||||
if (pathname === '/treatment' || pathname.startsWith('/treatment/')) return counts.treatment ?? 0;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user