@@ -13,6 +13,7 @@ import { useAppContext } from '../../hooks/useAppContext';
1313import { type GitifyNotification , IconColor } from '../../types' ;
1414
1515import { getPullRequestReviewIcon } from '../../utils/icons' ;
16+ import { formatMetricDescription } from '../../utils/notifications/formatters' ;
1617import { MetricPill } from './MetricPill' ;
1718
1819export interface MetricGroupProps {
@@ -26,11 +27,11 @@ export const MetricGroup: FC<MetricGroupProps> = ({
2627
2728 const linkedIssues = notification . subject . linkedIssues ?? [ ] ;
2829 const hasLinkedIssues = linkedIssues . length > 0 ;
29- const linkedIssuesPillDescription = hasLinkedIssues
30- ? `Linked to ${
31- linkedIssues . length > 1 ? 'issues:' : ' issue'
32- } ${ linkedIssues . join ( ', ' ) } `
33- : '' ;
30+ const linkedIssuesPillDescription = formatMetricDescription (
31+ linkedIssues . length ,
32+ ' issue',
33+ ( count , noun ) => `Linked to ${ count } ${ noun } : ${ linkedIssues . join ( ', ' ) } `,
34+ ) ;
3435
3536 const reactionCount = notification . subject . reactionsCount ?? 0 ;
3637 const reactionGroups = notification . subject . reactionGroups ?? [ ] ;
@@ -48,40 +49,41 @@ export const MetricGroup: FC<MetricGroupProps> = ({
4849 HEART : '❤️' ,
4950 } ;
5051
51- const reactionPillDescription = hasReactions
52- ? `${ reactionCount } ${
53- reactionCount > 1 ? 'reactions' : 'reaction'
54- } : ${ reactionGroups
55- . reduce ( ( acc , rg ) => {
56- if ( ! rg . reactors . totalCount || rg . reactors . totalCount <= 0 ) {
57- return acc ;
58- }
59-
52+ const reactionPillDescription = formatMetricDescription (
53+ reactionCount ,
54+ 'reaction' ,
55+ ( count , noun ) => {
56+ const formatted = reactionGroups
57+ . map ( ( rg ) => {
6058 const emoji = reactionEmojiMap [ rg . content ] ;
61- if ( ! emoji ) {
62- return acc ;
59+ if ( ! emoji || ! rg . reactors . totalCount ) {
60+ return '' ;
6361 }
6462
65- acc . push (
66- ` ${ emoji } ${ hasMultipleReactions ? rg . reactors . totalCount : '' } ` . trim ( ) ,
67- ) ;
68- return acc ;
69- } , [ ] as string [ ] )
70- . join ( ' ' ) } `
71- : '' ;
63+ return ` ${ emoji } ${ hasMultipleReactions ? rg . reactors . totalCount : '' } ` . trim ( ) ;
64+ } )
65+ . filter ( Boolean )
66+ . join ( ' ' ) ;
67+ return ` ${ count } ${ noun } : ${ formatted } ` ;
68+ } ,
69+ ) ;
7270
7371 const commentCount = notification . subject . commentCount ?? 0 ;
7472 const hasComments = commentCount > 0 ;
75- const commentsPillDescription = hasComments
76- ? `${ notification . subject . commentCount } ${ notification . subject . commentCount > 1 ? 'comments' : 'comment' } `
77- : '' ;
73+ const commentsPillDescription = formatMetricDescription (
74+ commentCount ,
75+ 'comment' ,
76+ ) ;
7877
7978 const labels = notification . subject . labels ?? [ ] ;
8079 const labelsCount = labels . length ;
8180 const hasLabels = labelsCount > 0 ;
82- const labelsPillDescription = hasLabels
83- ? `${ labelsCount } ${ labelsCount > 1 ? 'labels' : 'label' } : ${ labels . map ( ( label ) => `🏷️ ${ label } ` ) . join ( ', ' ) } `
84- : '' ;
81+ const labelsPillDescription = formatMetricDescription (
82+ labelsCount ,
83+ 'label' ,
84+ ( count , noun ) =>
85+ `${ count } ${ noun } : ${ labels . map ( ( label ) => `🏷️ ${ label } ` ) . join ( ', ' ) } ` ,
86+ ) ;
8587
8688 const milestone = notification . subject . milestone ;
8789
0 commit comments