Skip to content

Commit 0fc4ffb

Browse files
committed
feat: skip fetching if offline
Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent cd66113 commit 0fc4ffb

11 files changed

Lines changed: 521 additions & 110 deletions

src/renderer/components/metrics/CommentsPill.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export const CommentsPill: FC<CommentsPillProps> = ({ commentCount }) => {
2121
return (
2222
<MetricPill
2323
color={IconColor.GRAY}
24+
contents={description}
2425
icon={CommentIcon}
2526
metric={commentCount}
26-
title={description}
2727
/>
2828
);
2929
};

src/renderer/components/metrics/LabelsPill.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import type { FC } from 'react';
22

3+
import { TagIcon } from '@primer/octicons-react';
34
import { IssueLabelToken, LabelGroup } from '@primer/react';
45

5-
import type { GitifyLabels } from '../../types';
6+
import { type GitifyLabels, IconColor } from '../../types';
7+
8+
import { MetricPill } from './MetricPill';
69

710
export interface LabelsPillProps {
811
labels: GitifyLabels[];
@@ -14,7 +17,7 @@ export const LabelsPill: FC<LabelsPillProps> = ({ labels }) => {
1417
}
1518

1619
const labelsContent = (
17-
<LabelGroup visibleChildCount="auto">
20+
<LabelGroup>
1821
{labels.map((label) => {
1922
return (
2023
<IssueLabelToken
@@ -28,5 +31,12 @@ export const LabelsPill: FC<LabelsPillProps> = ({ labels }) => {
2831
</LabelGroup>
2932
);
3033

31-
return labelsContent;
34+
return (
35+
<MetricPill
36+
color={IconColor.GRAY}
37+
contents={labelsContent}
38+
icon={TagIcon}
39+
metric={labels.length}
40+
/>
41+
);
3242
};

src/renderer/components/metrics/LinkedIssuesPill.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ export const LinkedIssuesPill: FC<LinkedIssuesPillProps> = ({
2121
const description = formatMetricDescription(
2222
linkedIssues.length,
2323
'issue',
24-
(count, noun) => `Linked to ${count} ${noun}: ${linkedIssues.join(', ')}`,
24+
(noun) => `Linked to ${noun}: ${linkedIssues.join(', ')}`,
2525
);
2626

2727
return (
2828
<MetricPill
2929
color={IconColor.GRAY}
30+
contents={description}
3031
icon={IssueOpenedIcon}
3132
metric={linkedIssues.length}
32-
title={description}
3333
/>
3434
);
3535
};

src/renderer/components/metrics/MetricPill.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { MetricPill, type MetricPillProps } from './MetricPill';
99
describe('renderer/components/metrics/MetricPill.tsx', () => {
1010
it('should render with metric', () => {
1111
const props: MetricPillProps = {
12-
title: 'Mock Pill',
12+
contents: 'Mock Pill',
1313
metric: 1,
1414
icon: MarkGithubIcon,
1515
color: IconColor.GREEN,
@@ -22,7 +22,7 @@ describe('renderer/components/metrics/MetricPill.tsx', () => {
2222

2323
it('should render without metric', () => {
2424
const props: MetricPillProps = {
25-
title: 'Mock Pill',
25+
contents: 'Mock Pill',
2626
icon: MarkGithubIcon,
2727
color: IconColor.GREEN,
2828
};

src/renderer/components/metrics/MetricPill.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import { Label, Stack, Text, Tooltip } from '@primer/react';
66
import { type IconColor, Size } from '../../types';
77

88
export interface MetricPillProps {
9-
title: string;
9+
contents: string | ReactNode;
1010
metric?: number;
1111
icon: Icon;
1212
color: IconColor;
13-
content?: ReactNode;
1413
}
1514

1615
export const MetricPill: FC<MetricPillProps> = (props: MetricPillProps) => {
1716
const Icon = props.icon;
1817

1918
return (
20-
<Tooltip direction="s" text={props.title}>
19+
// @ts-expect-error: We overload text with a ReactNode
20+
<Tooltip direction="s" text={props.contents}>
2121
<button type="button">
2222
<Label
2323
className="hover:bg-gitify-notification-pill-hover"
@@ -32,7 +32,6 @@ export const MetricPill: FC<MetricPillProps> = (props: MetricPillProps) => {
3232
) : null}
3333
</Stack>
3434
</Label>
35-
{props.content}
3635
</button>
3736
</Tooltip>
3837
);

src/renderer/components/metrics/MilestonePill.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export const MilestonePill: FC<MilestonePillProps> = ({ milestone }) => {
1818
return (
1919
<MetricPill
2020
color={milestone.state === 'OPEN' ? IconColor.GREEN : IconColor.PURPLE}
21+
contents={milestone.title}
2122
icon={MilestoneIcon}
22-
title={milestone.title}
2323
/>
2424
);
2525
};
Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import type { FC } from 'react';
22

33
import { SmileyIcon } from '@primer/octicons-react';
4+
import { IssueLabelToken, LabelGroup } from '@primer/react';
45

56
import { type GitifyReactionGroup, IconColor } from '../../types';
67

7-
import { formatMetricDescription } from '../../utils/notifications/formatters';
8+
// import { formatMetricDescription } from '../../utils/notifications/formatters';
89
import { MetricPill } from './MetricPill';
910

1011
export interface ReactionsPillProps {
@@ -31,33 +32,34 @@ export const ReactionsPill: FC<ReactionsPillProps> = ({
3132
return null;
3233
}
3334

34-
const hasMultipleReactions =
35-
reactionGroups.filter((rg) => rg.reactors.totalCount > 0).length > 1;
36-
37-
const description = formatMetricDescription(
38-
reactionsCount,
39-
'reaction',
40-
(count, noun) => {
41-
const formatted = reactionGroups
42-
.map((rg) => {
43-
const emoji = reactionEmojiMap[rg.content];
44-
if (!emoji || !rg.reactors.totalCount) {
45-
return '';
46-
}
47-
return `${emoji} ${hasMultipleReactions ? rg.reactors.totalCount : ''}`.trim();
48-
})
49-
.filter(Boolean)
50-
.join(' ');
51-
return `${count} ${noun}: ${formatted}`;
52-
},
35+
const visibleReactionGroups = reactionGroups.filter(
36+
(rg) => !!rg.reactors && rg.reactors.totalCount > 0,
37+
);
38+
39+
const reactionsContent = (
40+
<LabelGroup>
41+
{visibleReactionGroups.map((rg) => {
42+
const emoji = reactionEmojiMap[rg.content];
43+
const total = rg.reactors.totalCount;
44+
45+
return (
46+
<IssueLabelToken
47+
fillColor="#24292e" // Same as sidebar color from tailwind config
48+
key={rg.content}
49+
size="small"
50+
text={`${emoji} ${total}`}
51+
/>
52+
);
53+
})}
54+
</LabelGroup>
5355
);
5456

5557
return (
5658
<MetricPill
5759
color={IconColor.GRAY}
60+
contents={reactionsContent}
5861
icon={SmileyIcon}
5962
metric={reactionsCount}
60-
title={description}
6163
/>
6264
);
6365
};

src/renderer/components/metrics/ReviewsPill.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export const ReviewsPill: FC<ReviewsPillProps> = ({ reviews }) => {
2626
return (
2727
<MetricPill
2828
color={icon.color}
29+
contents={icon.description}
2930
icon={icon.type}
3031
key={review.state}
3132
metric={review.users.length}
32-
title={icon.description}
3333
/>
3434
);
3535
})}

0 commit comments

Comments
 (0)