From 90244dbc6b878473a7a788d18a202a48ae02ce54 Mon Sep 17 00:00:00 2001 From: AltinGruda Date: Sun, 3 Mar 2024 19:34:13 +0100 Subject: [PATCH 1/7] feat: group by date/repository --- src/components/AccountNotifications.tsx | 26 ++++- src/components/NotificationRow.test.tsx | 6 ++ src/components/NotificationRow.tsx | 7 ++ src/components/Repository.test.tsx | 1 + src/components/Repository.tsx | 49 +++++----- .../AccountNotifications.test.tsx.snap | 94 ++++++++++++++----- 6 files changed, 134 insertions(+), 49 deletions(-) diff --git a/src/components/AccountNotifications.tsx b/src/components/AccountNotifications.tsx index e28cfaffc..43490cc01 100644 --- a/src/components/AccountNotifications.tsx +++ b/src/components/AccountNotifications.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { ChevronDownIcon, ChevronLeftIcon } from '@primer/octicons-react'; import { Notification } from '../typesGithub'; @@ -13,6 +13,10 @@ interface IProps { export const AccountNotifications = (props: IProps) => { const { hostname, showAccountHostname, notifications } = props; + const [groupType, setGroupType] = useState<'repository' | 'date'>( + 'repository', + ); + const groupedNotifications = Object.values( notifications.reduce( (acc: { [key: string]: Notification[] }, notification) => { @@ -27,6 +31,10 @@ export const AccountNotifications = (props: IProps) => { const Chevron = notifications.length > 0 ? ChevronDownIcon : ChevronLeftIcon; + const handleGroupTypeChange = (type: 'repository' | 'date') => { + setGroupType(type); + }; + return ( <> {showAccountHostname && ( @@ -37,15 +45,29 @@ export const AccountNotifications = (props: IProps) => { )} + + {Object.values(groupedNotifications).map((repoNotifications) => { const repoSlug = repoNotifications[0].repository.full_name; - return ( ); })} diff --git a/src/components/NotificationRow.test.tsx b/src/components/NotificationRow.test.tsx index 9158a62d6..c33906554 100644 --- a/src/components/NotificationRow.test.tsx +++ b/src/components/NotificationRow.test.tsx @@ -24,6 +24,7 @@ describe('components/Notification.js', () => { const props = { notification: mockedSingleNotification, hostname: 'github.com', + groupType: 'repository', }; const tree = TestRenderer.create(); @@ -36,6 +37,7 @@ describe('components/Notification.js', () => { const props = { notification: mockedSingleNotification, hostname: 'github.com', + groupType: 'repository', }; const { getByRole } = render( @@ -61,6 +63,7 @@ describe('components/Notification.js', () => { const props = { notification: mockedSingleNotification, hostname: 'github.com', + groupType: 'repository', }; const { getByRole } = render( @@ -86,6 +89,7 @@ describe('components/Notification.js', () => { const props = { notification: mockedSingleNotification, hostname: 'github.com', + groupType: 'repository', }; const { getByTitle } = render( @@ -111,6 +115,7 @@ describe('components/Notification.js', () => { const props = { notification: mockedSingleNotification, hostname: 'github.com', + groupType: 'repository', }; const { getByTitle } = render( @@ -136,6 +141,7 @@ describe('components/Notification.js', () => { const props = { notification: mockedSingleNotification, hostname: 'github.com', + groupType: 'repository', }; const { getByLabelText } = render( diff --git a/src/components/NotificationRow.tsx b/src/components/NotificationRow.tsx index 44c049c0a..7fcb2b537 100644 --- a/src/components/NotificationRow.tsx +++ b/src/components/NotificationRow.tsx @@ -14,11 +14,13 @@ import { AppContext } from '../context/App'; interface IProps { hostname: string; notification: Notification; + groupType: string; } export const NotificationRow: React.FC = ({ notification, hostname, + groupType, }) => { const { settings, @@ -73,6 +75,11 @@ export const NotificationRow: React.FC = ({ onClick={() => pressTitle()} role="main" > + {groupType === 'date' && ( +
+ {notification.repository.full_name} +
+ )}
{notification.subject.title}
diff --git a/src/components/Repository.test.tsx b/src/components/Repository.test.tsx index 9eaa7aec5..f40546b89 100644 --- a/src/components/Repository.test.tsx +++ b/src/components/Repository.test.tsx @@ -20,6 +20,7 @@ describe('components/Repository.tsx', () => { hostname: 'github.com', repoName: 'manosim/gitify', repoNotifications: mockedGithubNotifications, + groupType: 'repository', }; beforeEach(() => { diff --git a/src/components/Repository.tsx b/src/components/Repository.tsx index 7cf0ed8ca..6a95ee481 100644 --- a/src/components/Repository.tsx +++ b/src/components/Repository.tsx @@ -11,12 +11,14 @@ interface IProps { hostname: string; repoNotifications: Notification[]; repoName: string; + groupType: string; } export const RepositoryNotifications: React.FC = ({ repoName, repoNotifications, hostname, + groupType, }) => { const { markRepoNotifications, markRepoNotificationsDone } = useContext(AppContext); @@ -40,32 +42,34 @@ export const RepositoryNotifications: React.FC = ({ return ( <> -
-
- - {repoName} -
+ {groupType === 'repository' && ( +
+
+ + {repoName} +
-
- +
+ -
+
- + +
-
+ )} {repoNotifications.map((obj) => ( @@ -74,6 +78,7 @@ export const RepositoryNotifications: React.FC = ({ key={obj.id} hostname={hostname} notification={obj} + groupType={groupType} /> ))} diff --git a/src/components/__snapshots__/AccountNotifications.test.tsx.snap b/src/components/__snapshots__/AccountNotifications.test.tsx.snap index 1e14664e4..476586a04 100644 --- a/src/components/__snapshots__/AccountNotifications.test.tsx.snap +++ b/src/components/__snapshots__/AccountNotifications.test.tsx.snap @@ -29,6 +29,27 @@ exports[`components/AccountNotifications.tsx should render itself (github.com wi />
, + ,
Repository
, @@ -36,31 +57,54 @@ exports[`components/AccountNotifications.tsx should render itself (github.com wi `; exports[`components/AccountNotifications.tsx should render itself (github.com without notifications) 1`] = ` -
- github.com -
, +
+ Group by: + + , +] `; From aeae79582b3a71d0139d03037ef3a11652d3fc26 Mon Sep 17 00:00:00 2001 From: AltinGruda Date: Sun, 3 Mar 2024 20:11:51 +0100 Subject: [PATCH 2/7] dropdown button styles --- src/components/AccountNotifications.tsx | 6 +++--- .../AccountNotifications.test.tsx.snap | 20 +++++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/components/AccountNotifications.tsx b/src/components/AccountNotifications.tsx index 43490cc01..5d735ed20 100644 --- a/src/components/AccountNotifications.tsx +++ b/src/components/AccountNotifications.tsx @@ -45,14 +45,14 @@ export const AccountNotifications = (props: IProps) => {
)} -