Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/components/NotificationRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('components/NotificationRow.tsx', () => {

describe('notification interactions', () => {
it('should open a notification in the browser - click', () => {
const removeNotificationFromState = jest.fn();
const markNotificationRead = jest.fn();

const props = {
notification: mockSingleNotification,
Expand All @@ -93,7 +93,7 @@ describe('components/NotificationRow.tsx', () => {
<AppContext.Provider
value={{
settings: { ...mockSettings, markAsDoneOnOpen: false },
removeNotificationFromState,
markNotificationRead,
auth: mockAuth,
}}
>
Expand All @@ -103,11 +103,11 @@ describe('components/NotificationRow.tsx', () => {

fireEvent.click(screen.getByRole('main'));
expect(links.openNotification).toHaveBeenCalledTimes(1);
expect(removeNotificationFromState).toHaveBeenCalledTimes(1);
expect(markNotificationRead).toHaveBeenCalledTimes(1);
});

it('should open a notification in the browser - delay notification setting enabled', () => {
const removeNotificationFromState = jest.fn();
const markNotificationRead = jest.fn();

const props = {
notification: mockSingleNotification,
Expand All @@ -122,7 +122,7 @@ describe('components/NotificationRow.tsx', () => {
markAsDoneOnOpen: false,
delayNotificationState: true,
},
removeNotificationFromState,
markNotificationRead,
auth: mockAuth,
}}
>
Expand All @@ -132,11 +132,11 @@ describe('components/NotificationRow.tsx', () => {

fireEvent.click(screen.getByRole('main'));
expect(links.openNotification).toHaveBeenCalledTimes(1);
expect(removeNotificationFromState).toHaveBeenCalledTimes(1);
expect(markNotificationRead).toHaveBeenCalledTimes(1);
});

it('should open a notification in the browser - key down', () => {
const removeNotificationFromState = jest.fn();
const markNotificationRead = jest.fn();

const props = {
notification: mockSingleNotification,
Expand All @@ -147,7 +147,7 @@ describe('components/NotificationRow.tsx', () => {
<AppContext.Provider
value={{
settings: { ...mockSettings, markAsDoneOnOpen: false },
removeNotificationFromState,
markNotificationRead,
auth: mockAuth,
}}
>
Expand All @@ -157,7 +157,7 @@ describe('components/NotificationRow.tsx', () => {

fireEvent.click(screen.getByRole('main'));
expect(links.openNotification).toHaveBeenCalledTimes(1);
expect(removeNotificationFromState).toHaveBeenCalledTimes(1);
expect(markNotificationRead).toHaveBeenCalledTimes(1);
});

it('should open a notification in browser & mark it as done', () => {
Expand Down
11 changes: 2 additions & 9 deletions src/components/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export const NotificationRow: FC<INotificationRow> = ({
}: INotificationRow) => {
const {
settings,
removeNotificationFromState,
markNotificationRead,
markNotificationDone,
unsubscribeNotification,
Expand All @@ -49,15 +48,9 @@ export const NotificationRow: FC<INotificationRow> = ({
if (settings.markAsDoneOnOpen) {
markNotificationDone(notification);
} else {
// no need to mark as read, github does it by default when opening it
removeNotificationFromState(settings, notification);
markNotificationRead(notification);
}
}, [
notification,
markNotificationDone,
removeNotificationFromState,
settings,
]);
}, [notification, markNotificationDone, markNotificationRead, settings]);

const unsubscribeFromThread = (event: MouseEvent<HTMLElement>) => {
// Don't trigger onClick of parent element.
Expand Down
6 changes: 0 additions & 6 deletions src/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ interface AppContextState {
notifications: AccountNotifications[];
status: Status;
errorDetails: GitifyError;
removeNotificationFromState: (
settings: SettingsState,
notification: Notification,
) => void;
fetchNotifications: () => Promise<void>;
markNotificationRead: (notification: Notification) => Promise<void>;
markNotificationDone: (notification: Notification) => Promise<void>;
Expand All @@ -129,7 +125,6 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
notifications,
errorDetails,
status,
removeNotificationFromState,
markNotificationRead,
markNotificationDone,
unsubscribeNotification,
Expand Down Expand Up @@ -317,7 +312,6 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
notifications,
status,
errorDetails,
removeNotificationFromState,
fetchNotifications: fetchNotificationsWithAccounts,
markNotificationRead: markNotificationReadWithAccounts,
markNotificationDone: markNotificationDoneWithAccounts,
Expand Down
39 changes: 0 additions & 39 deletions src/hooks/useNotifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,45 +297,6 @@ describe('hooks/useNotifications.ts', () => {
});
});

describe('removeNotificationFromState', () => {
it('should remove a notification from state', async () => {
const notifications = [
{ id: 1, title: 'This is a notification.' },
{ id: 2, title: 'This is another one.' },
];

nock('https://api.github.com')
.get('/notifications?participating=false')
.reply(200, notifications);

nock('https://github.gitify.io/api/v3')
.get('/notifications?participating=false')
.reply(200, notifications);

const { result } = renderHook(() => useNotifications());

act(() => {
result.current.fetchNotifications({
...mockState,
settings: { ...mockSettings, detailedNotifications: false },
});
});

await waitFor(() => {
expect(result.current.status).toBe('success');
});

act(() => {
result.current.removeNotificationFromState(
mockSettings,
result.current.notifications[0].notifications[0],
);
});

expect(result.current.notifications[0].notifications.length).toBe(1);
});
});

describe('markNotificationRead', () => {
it('should mark a notification as read with success', async () => {
nock('https://api.github.com/')
Expand Down
20 changes: 0 additions & 20 deletions src/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {
AccountNotifications,
GitifyError,
GitifyState,
SettingsState,
Status,
} from '../types';
import type { Notification } from '../typesGitHub';
Expand All @@ -25,10 +24,6 @@ import { removeNotifications } from '../utils/remove-notifications';

interface NotificationsState {
notifications: AccountNotifications[];
removeNotificationFromState: (
settings: SettingsState,
notification: Notification,
) => void;
fetchNotifications: (state: GitifyState) => Promise<void>;
markNotificationRead: (
state: GitifyState,
Expand Down Expand Up @@ -226,26 +221,11 @@ export const useNotifications = (): NotificationsState => {
[notifications, markNotificationDone],
);

const removeNotificationFromState = useCallback(
(settings: SettingsState, notification: Notification) => {
const updatedNotifications = removeNotification(
settings,
notification,
notifications,
);

setNotifications(updatedNotifications);
setTrayIconColor(updatedNotifications);
},
[notifications],
);

return {
status,
errorDetails,
notifications,

removeNotificationFromState,
fetchNotifications,
markNotificationRead,
markNotificationDone,
Expand Down