Skip to content

Commit

Permalink
fix: delay state
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy committed Jun 16, 2024
1 parent d19e664 commit 2163a49
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/components/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ export const NotificationRow: FC<IProps> = ({ notification }) => {
unsubscribeNotification,
} = useContext(AppContext);
const [animateExit, setAnimateExit] = useState(false);
const [showAsRead, setShowAsRead] = useState(false);

const handleNotification = useCallback(() => {
setAnimateExit(!settings.delayNotificationState);
setShowAsRead(settings.delayNotificationState);

openNotification(notification);

if (settings.markAsDoneOnOpen) {
Expand Down Expand Up @@ -102,6 +105,7 @@ export const NotificationRow: FC<IProps> = ({ notification }) => {
'group flex border-b border-gray-100 bg-white px-3 py-2 hover:bg-gray-100 dark:border-gray-darker dark:bg-gray-dark dark:text-white dark:hover:bg-gray-darker',
animateExit &&
'translate-x-full opacity-0 transition duration-[350ms] ease-in-out',
showAsRead && 'opacity-50 dark:opacity-50',
)}
>
<div
Expand Down Expand Up @@ -219,6 +223,7 @@ export const NotificationRow: FC<IProps> = ({ notification }) => {
title="Mark as Done"
onClick={() => {
setAnimateExit(!settings.delayNotificationState);
setShowAsRead(settings.delayNotificationState);
markNotificationDone(notification);
}}
>
Expand All @@ -240,6 +245,7 @@ export const NotificationRow: FC<IProps> = ({ notification }) => {
title="Mark as Read"
onClick={() => {
setAnimateExit(!settings.delayNotificationState);
setShowAsRead(settings.delayNotificationState);
markNotificationRead(notification);
}}
>
Expand Down
2 changes: 0 additions & 2 deletions src/styles/gitify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ export const BUTTON_CLASS_NAME =

export const BUTTON_SIDEBAR_CLASS_NAME =
'flex justify-evenly items-center bg-transparent border-0 w-full text-sm text-white my-1 py-2 cursor-pointer hover:text-gray-500 focus:outline-none disabled:text-gray-500 disabled:cursor-default';

export const READ_NOTIFICATION_CLASS_NAME = 'opacity-50 dark:opacity-50';
11 changes: 1 addition & 10 deletions src/utils/remove-notification.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { mockSingleAccountNotifications } from '../__mocks__/notifications-mocks';
import { mockSettings } from '../__mocks__/state-mocks';
import { READ_NOTIFICATION_CLASS_NAME } from '../styles/gitify';
import { mockSingleNotification } from './api/__mocks__/response-mocks';
import { removeNotification } from './remove-notification';

Expand All @@ -17,11 +16,7 @@ describe('utils/remove-notification.ts', () => {
expect(result[0].notifications.length).toBe(0);
});

it('should set notification as opaque if delayNotificationState enabled', () => {
const mockElement = document.createElement('div');
mockElement.id = mockSingleAccountNotifications[0].notifications[0].id;
jest.spyOn(document, 'getElementById').mockReturnValue(mockElement);

it('should skip notification removal if delay state enabled', () => {
expect(mockSingleAccountNotifications[0].notifications.length).toBe(1);

const result = removeNotification(
Expand All @@ -31,9 +26,5 @@ describe('utils/remove-notification.ts', () => {
);

expect(result[0].notifications.length).toBe(1);
expect(document.getElementById).toHaveBeenCalledWith(
mockSingleAccountNotifications[0].notifications[0].id,
);
expect(mockElement.className).toContain(READ_NOTIFICATION_CLASS_NAME);
});
});
3 changes: 0 additions & 3 deletions src/utils/remove-notification.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { READ_NOTIFICATION_CLASS_NAME } from '../styles/gitify';
import type { AccountNotifications, SettingsState } from '../types';
import type { Notification } from '../typesGitHub';
import { getAccountUUID } from './auth/utils';
Expand All @@ -9,8 +8,6 @@ export const removeNotification = (
notifications: AccountNotifications[],
): AccountNotifications[] => {
if (settings.delayNotificationState) {
const notificationRow = document.getElementById(notification.id);
notificationRow.className += ` ${READ_NOTIFICATION_CLASS_NAME}`;
return notifications;
}

Expand Down

0 comments on commit 2163a49

Please sign in to comment.