Skip to content

Commit ed7e94f

Browse files
committed
chore: remove lodash
1 parent 134771c commit ed7e94f

File tree

7 files changed

+38
-38
lines changed

7 files changed

+38
-38
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
"electron-updater": "6.1.4",
101101
"final-form": "4.20.10",
102102
"history": "4.10.1",
103-
"lodash": "4.17.21",
104103
"menubar": "9.3.0",
105104
"nprogress": "0.2.0",
106105
"react": "18.2.0",
@@ -117,7 +116,6 @@
117116
"@testing-library/react": "14.0.0",
118117
"@testing-library/react-hooks": "8.0.1",
119118
"@types/jest": "29.5.5",
120-
"@types/lodash": "4.14.199",
121119
"@types/node": "18.18.0",
122120
"@types/react": "18.2.28",
123121
"@types/react-router-dom": "5.3.3",

pnpm-lock.yaml

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/AccountNotifications.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import _ from 'lodash';
32
import { ChevronDownIcon, ChevronLeftIcon } from '@primer/octicons-react';
43

54
import { Notification } from '../typesGithub';
@@ -14,10 +13,21 @@ interface IProps {
1413
export const AccountNotifications = (props: IProps) => {
1514
const { hostname, showAccountHostname, notifications } = props;
1615

17-
const groupedNotifications = _(notifications)
18-
.groupBy((obj) => obj.repository.full_name)
19-
.sortBy((_, key) => key)
20-
.value();
16+
const groupedNotifications = Object.values(
17+
notifications.reduce(
18+
(acc: { [key: string]: Notification[] }, notification) => {
19+
const key = notification.repository.full_name;
20+
if (!acc[key]) {
21+
acc[key] = [];
22+
}
23+
acc[key].push(notification);
24+
return acc;
25+
},
26+
{},
27+
),
28+
).sort((a, b) =>
29+
a[0].repository.full_name.localeCompare(b[0].repository.full_name),
30+
);
2131

2232
const Chevron = notifications.length > 0 ? ChevronDownIcon : ChevronLeftIcon;
2333

src/utils/notifications.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as _ from 'lodash';
21
import { ipcRenderer } from 'electron';
32

43
import { generateGitHubWebUrl, getCommentId } from './helpers';

src/utils/remove-notification.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as _ from 'lodash';
2-
31
import {
42
mockedSingleAccountNotifications,
53
mockedSingleNotification,

src/utils/remove-notification.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import updateWith from 'lodash/updateWith';
2-
31
import { AccountNotifications } from '../types';
4-
import { Notification } from '../typesGithub';
52

63
export const removeNotification = (
74
id: string,
@@ -12,11 +9,16 @@ export const removeNotification = (
129
(accountNotifications) => accountNotifications.hostname === hostname,
1310
);
1411

15-
return updateWith(
16-
[...notifications],
17-
`[${accountIndex}][notifications]`,
18-
(accNotifications: Notification[] = []) => {
19-
return accNotifications.filter((notification) => notification.id !== id);
20-
},
21-
);
12+
if (accountIndex !== -1) {
13+
const updatedNotifications = [...notifications];
14+
updatedNotifications[accountIndex] = {
15+
...updatedNotifications[accountIndex],
16+
notifications: updatedNotifications[accountIndex].notifications.filter(
17+
(notification) => notification.id !== id,
18+
),
19+
};
20+
return updatedNotifications;
21+
}
22+
23+
return notifications;
2224
};

src/utils/remove-notifications.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import updateWith from 'lodash/updateWith';
2-
31
import { AccountNotifications } from '../types';
4-
import { Notification } from '../typesGithub';
52

63
export const removeNotifications = (
74
repoSlug: string,
@@ -12,13 +9,16 @@ export const removeNotifications = (
129
(accountNotifications) => accountNotifications.hostname === hostname,
1310
);
1411

15-
return updateWith(
16-
[...notifications],
17-
`[${accountIndex}][notifications]`,
18-
(accNotifications: Notification[] = []) => {
19-
return accNotifications.filter(
12+
if (accountIndex !== -1) {
13+
const updatedNotifications = [...notifications];
14+
updatedNotifications[accountIndex] = {
15+
...updatedNotifications[accountIndex],
16+
notifications: updatedNotifications[accountIndex].notifications.filter(
2017
(notification) => notification.repository.full_name !== repoSlug,
21-
);
22-
},
23-
);
18+
),
19+
};
20+
return updatedNotifications;
21+
}
22+
23+
return notifications;
2424
};

0 commit comments

Comments
 (0)