From ed7e94f408c8b843c62ab573208cf56717a02941 Mon Sep 17 00:00:00 2001 From: Afonso Jorge Ramos Date: Wed, 18 Oct 2023 00:07:24 +0100 Subject: [PATCH 1/3] chore: remove lodash --- package.json | 2 -- pnpm-lock.yaml | 7 ------- src/components/AccountNotifications.tsx | 20 +++++++++++++++----- src/utils/notifications.test.ts | 1 - src/utils/remove-notification.test.ts | 2 -- src/utils/remove-notification.ts | 22 ++++++++++++---------- src/utils/remove-notifications.ts | 22 +++++++++++----------- 7 files changed, 38 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index abbd6b7e1..442c8136c 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,6 @@ "electron-updater": "6.1.4", "final-form": "4.20.10", "history": "4.10.1", - "lodash": "4.17.21", "menubar": "9.3.0", "nprogress": "0.2.0", "react": "18.2.0", @@ -117,7 +116,6 @@ "@testing-library/react": "14.0.0", "@testing-library/react-hooks": "8.0.1", "@types/jest": "29.5.5", - "@types/lodash": "4.14.199", "@types/node": "18.18.0", "@types/react": "18.2.28", "@types/react-router-dom": "5.3.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2c40ac813..676ba981b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,9 +26,6 @@ dependencies: history: specifier: 4.10.1 version: 4.10.1 - lodash: - specifier: 4.17.21 - version: 4.17.21 menubar: specifier: 9.3.0 version: 9.3.0(electron@13.1.7) @@ -1102,10 +1099,6 @@ packages: dependencies: '@types/node': 18.18.0 - /@types/lodash@4.14.199: - resolution: {integrity: sha512-Vrjz5N5Ia4SEzWWgIVwnHNEnb1UE1XMkvY5DGXrAeOGE9imk0hgTHh5GyDjLDJi9OTCn9oo9dXH1uToK1VRfrg==} - dev: true - /@types/ms@0.7.31: resolution: {integrity: sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==} dev: true diff --git a/src/components/AccountNotifications.tsx b/src/components/AccountNotifications.tsx index bd2e9e82f..c5112ed49 100644 --- a/src/components/AccountNotifications.tsx +++ b/src/components/AccountNotifications.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import _ from 'lodash'; import { ChevronDownIcon, ChevronLeftIcon } from '@primer/octicons-react'; import { Notification } from '../typesGithub'; @@ -14,10 +13,21 @@ interface IProps { export const AccountNotifications = (props: IProps) => { const { hostname, showAccountHostname, notifications } = props; - const groupedNotifications = _(notifications) - .groupBy((obj) => obj.repository.full_name) - .sortBy((_, key) => key) - .value(); + const groupedNotifications = Object.values( + notifications.reduce( + (acc: { [key: string]: Notification[] }, notification) => { + const key = notification.repository.full_name; + if (!acc[key]) { + acc[key] = []; + } + acc[key].push(notification); + return acc; + }, + {}, + ), + ).sort((a, b) => + a[0].repository.full_name.localeCompare(b[0].repository.full_name), + ); const Chevron = notifications.length > 0 ? ChevronDownIcon : ChevronLeftIcon; diff --git a/src/utils/notifications.test.ts b/src/utils/notifications.test.ts index 8b37984be..adb1a45ca 100644 --- a/src/utils/notifications.test.ts +++ b/src/utils/notifications.test.ts @@ -1,4 +1,3 @@ -import * as _ from 'lodash'; import { ipcRenderer } from 'electron'; import { generateGitHubWebUrl, getCommentId } from './helpers'; diff --git a/src/utils/remove-notification.test.ts b/src/utils/remove-notification.test.ts index 434dc8102..ed4ce9d91 100644 --- a/src/utils/remove-notification.test.ts +++ b/src/utils/remove-notification.test.ts @@ -1,5 +1,3 @@ -import * as _ from 'lodash'; - import { mockedSingleAccountNotifications, mockedSingleNotification, diff --git a/src/utils/remove-notification.ts b/src/utils/remove-notification.ts index d7a31ce89..7e3b15c57 100644 --- a/src/utils/remove-notification.ts +++ b/src/utils/remove-notification.ts @@ -1,7 +1,4 @@ -import updateWith from 'lodash/updateWith'; - import { AccountNotifications } from '../types'; -import { Notification } from '../typesGithub'; export const removeNotification = ( id: string, @@ -12,11 +9,16 @@ export const removeNotification = ( (accountNotifications) => accountNotifications.hostname === hostname, ); - return updateWith( - [...notifications], - `[${accountIndex}][notifications]`, - (accNotifications: Notification[] = []) => { - return accNotifications.filter((notification) => notification.id !== id); - }, - ); + if (accountIndex !== -1) { + const updatedNotifications = [...notifications]; + updatedNotifications[accountIndex] = { + ...updatedNotifications[accountIndex], + notifications: updatedNotifications[accountIndex].notifications.filter( + (notification) => notification.id !== id, + ), + }; + return updatedNotifications; + } + + return notifications; }; diff --git a/src/utils/remove-notifications.ts b/src/utils/remove-notifications.ts index 47bb6078d..dcfb6bbfc 100644 --- a/src/utils/remove-notifications.ts +++ b/src/utils/remove-notifications.ts @@ -1,7 +1,4 @@ -import updateWith from 'lodash/updateWith'; - import { AccountNotifications } from '../types'; -import { Notification } from '../typesGithub'; export const removeNotifications = ( repoSlug: string, @@ -12,13 +9,16 @@ export const removeNotifications = ( (accountNotifications) => accountNotifications.hostname === hostname, ); - return updateWith( - [...notifications], - `[${accountIndex}][notifications]`, - (accNotifications: Notification[] = []) => { - return accNotifications.filter( + if (accountIndex !== -1) { + const updatedNotifications = [...notifications]; + updatedNotifications[accountIndex] = { + ...updatedNotifications[accountIndex], + notifications: updatedNotifications[accountIndex].notifications.filter( (notification) => notification.repository.full_name !== repoSlug, - ); - }, - ); + ), + }; + return updatedNotifications; + } + + return notifications; }; From a5e6b27c1689c136f55957f212c8db2fde27201c Mon Sep 17 00:00:00 2001 From: Afonso Jorge Ramos Date: Wed, 18 Oct 2023 01:42:31 +0100 Subject: [PATCH 2/3] chore: remove `emojione` --- package.json | 1 - pnpm-lock.yaml | 16 --------------- src/components/AllRead.tsx | 3 +-- src/components/Oops.tsx | 3 +-- .../__snapshots__/Oops.test.tsx.snap | 2 +- src/utils/constants.ts | 20 ++----------------- 6 files changed, 5 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index 442c8136c..4aa7d9492 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,6 @@ "nprogress": "0.2.0", "react": "18.2.0", "react-dom": "18.2.0", - "react-emojione": "5.0.1", "react-final-form": "6.5.9", "react-router": "6.16.0", "react-router-dom": "6.16.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 676ba981b..bf269a2a1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -38,9 +38,6 @@ dependencies: react-dom: specifier: 18.2.0 version: 18.2.0(react@18.2.0) - react-emojione: - specifier: 5.0.1 - version: 5.0.1(react-dom@18.2.0)(react@18.2.0) react-final-form: specifier: 6.5.9 version: 6.5.9(final-form@4.20.10)(react@18.2.0) @@ -70,9 +67,6 @@ devDependencies: '@types/jest': specifier: 29.5.5 version: 29.5.5 - '@types/lodash': - specifier: 4.14.199 - version: 4.14.199 '@types/node': specifier: 18.18.0 version: 18.18.0 @@ -4695,16 +4689,6 @@ packages: react: 18.2.0 scheduler: 0.23.0 - /react-emojione@5.0.1(react-dom@18.2.0)(react@18.2.0): - resolution: {integrity: sha512-sjI6k8uQ14rWENYoAb+2BFQGLBt/cpLDJJNhnZvdFJytAJijhv+JmbmyyrfQPdyID0Cs4N8XFqnek0xq6POwGA==} - peerDependencies: - react: ^16 - react-dom: ^16 - dependencies: - react: 18.2.0 - react-dom: 18.2.0(react@18.2.0) - dev: false - /react-error-boundary@3.1.4(react@18.2.0): resolution: {integrity: sha512-uM9uPzZJTF6wRQORmSrvOIgt4lJ9MC1sNgEOj2XGsDTRE4kmpWxg7ENK9EWNKJRMAOY9z0MuF4yIfl6gp4sotA==} engines: {node: '>=10', npm: '>=6'} diff --git a/src/components/AllRead.tsx b/src/components/AllRead.tsx index 176369d5f..a15488c6f 100644 --- a/src/components/AllRead.tsx +++ b/src/components/AllRead.tsx @@ -1,5 +1,4 @@ import * as React from 'react'; -import { emojify } from 'react-emojione'; import { Constants } from '../utils/constants'; @@ -14,7 +13,7 @@ export const AllRead = () => { return (
-

{emojify(emoji, { output: 'unicode' })}

+

{emoji}

No new notifications. diff --git a/src/components/Oops.tsx b/src/components/Oops.tsx index 4285630b7..3e1dfbf66 100644 --- a/src/components/Oops.tsx +++ b/src/components/Oops.tsx @@ -1,5 +1,4 @@ import * as React from 'react'; -import { emojify } from 'react-emojione'; import { Constants } from '../utils/constants'; @@ -14,7 +13,7 @@ export const Oops = () => { return (
-

{emojify(emoji, { output: 'unicode' })}

+

{emoji}

Something went wrong. diff --git a/src/components/__snapshots__/Oops.test.tsx.snap b/src/components/__snapshots__/Oops.test.tsx.snap index 0fa863208..c6ef9f63f 100644 --- a/src/components/__snapshots__/Oops.test.tsx.snap +++ b/src/components/__snapshots__/Oops.test.tsx.snap @@ -7,7 +7,7 @@ exports[`components/oops.tsx should render itself & its children 1`] = `

- 😔 + 🤔

Date: Wed, 18 Oct 2023 14:02:44 +0100 Subject: [PATCH 3/3] chore: simplify reducer --- src/components/AccountNotifications.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/AccountNotifications.tsx b/src/components/AccountNotifications.tsx index c5112ed49..e28cfaffc 100644 --- a/src/components/AccountNotifications.tsx +++ b/src/components/AccountNotifications.tsx @@ -17,16 +17,12 @@ export const AccountNotifications = (props: IProps) => { notifications.reduce( (acc: { [key: string]: Notification[] }, notification) => { const key = notification.repository.full_name; - if (!acc[key]) { - acc[key] = []; - } + if (!acc[key]) acc[key] = []; acc[key].push(notification); return acc; }, {}, ), - ).sort((a, b) => - a[0].repository.full_name.localeCompare(b[0].repository.full_name), ); const Chevron = notifications.length > 0 ? ChevronDownIcon : ChevronLeftIcon;