Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: regression in delay notification state behavior #1241

Merged
merged 6 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 4 additions & 16 deletions src/components/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ import {
ReadIcon,
TagIcon,
} from '@primer/octicons-react';
import {
type FC,
type MouseEvent,
useCallback,
useContext,
useState,
} from 'react';
import { type FC, type MouseEvent, useCallback, useContext } from 'react';
import { AppContext } from '../context/App';
import { IconColor } from '../types';
import type { Notification } from '../typesGitHub';
Expand Down Expand Up @@ -44,10 +38,8 @@ export const NotificationRow: FC<IProps> = ({ notification }) => {
markNotificationDone,
unsubscribeNotification,
} = useContext(AppContext);
const [animateExit, setAnimateExit] = useState(false);

const handleNotification = useCallback(() => {
setAnimateExit(true);
openNotification(notification);

if (settings.markAsDoneOnOpen) {
Expand Down Expand Up @@ -98,11 +90,9 @@ export const NotificationRow: FC<IProps> = ({ notification }) => {
return (
<div
id={notification.id}
className={cn(
'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',
)}
className={
'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'
}
>
<div
className={cn('mr-3 flex w-5 items-center justify-center', iconColor)}
Expand Down Expand Up @@ -218,7 +208,6 @@ export const NotificationRow: FC<IProps> = ({ notification }) => {
className="h-full hover:text-green-500 focus:outline-none"
title="Mark as Done"
onClick={() => {
setAnimateExit(true);
markNotificationDone(notification);
}}
>
Expand All @@ -239,7 +228,6 @@ export const NotificationRow: FC<IProps> = ({ notification }) => {
className="h-full hover:text-green-500 focus:outline-none"
title="Mark as Read"
onClick={() => {
setAnimateExit(true);
markNotificationRead(notification);
}}
>
Expand Down
1 change: 1 addition & 0 deletions src/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
settings.participating,
settings.showBots,
settings.detailedNotifications,
settings.delayNotificationState,
auth.accounts.length,
]);

Expand Down
5 changes: 5 additions & 0 deletions src/hooks/useNotifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { act, renderHook, waitFor } from '@testing-library/react';
import axios, { AxiosError } from 'axios';
import nock from 'nock';

import { mockSingleAccountNotifications } from '../__mocks__/notifications-mocks';
import {
mockAuth,
mockGitHubCloudAccount,
Expand Down Expand Up @@ -299,6 +300,10 @@ describe('hooks/useNotifications.ts', () => {

describe('removeNotificationFromState', () => {
it('should remove a notification from state', async () => {
const mockElement = document.createElement('div');
mockElement.id = mockSingleAccountNotifications[0].notifications[0].id;
jest.spyOn(document, 'getElementById').mockReturnValue(mockElement);

const notifications = [
{ id: 1, title: 'This is a notification.' },
{ id: 2, title: 'This is another one.' },
Expand Down
3 changes: 3 additions & 0 deletions src/styles/gitify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ 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';

export const ANIMATE_NOTIFICATION_CLASS_NAME =
'translate-x-full opacity-0 transition duration-[350ms] ease-in-out';
4 changes: 4 additions & 0 deletions src/utils/remove-notification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { removeNotification } from './remove-notification';

describe('utils/remove-notification.ts', () => {
it('should remove a notification if it exists', () => {
const mockElement = document.createElement('div');
mockElement.id = mockSingleAccountNotifications[0].notifications[0].id;
jest.spyOn(document, 'getElementById').mockReturnValue(mockElement);

expect(mockSingleAccountNotifications[0].notifications.length).toBe(1);

const result = removeNotification(
Expand Down
8 changes: 7 additions & 1 deletion src/utils/remove-notification.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { READ_NOTIFICATION_CLASS_NAME } from '../styles/gitify';
import {
ANIMATE_NOTIFICATION_CLASS_NAME,
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 @@ -14,6 +17,9 @@ export const removeNotification = (
return notifications;
}

const notificationRow = document.getElementById(notification.id);
notificationRow.className += ` ${ANIMATE_NOTIFICATION_CLASS_NAME}`;
afonsojramos marked this conversation as resolved.
Show resolved Hide resolved

const notificationId = notification.id;

const accountIndex = notifications.findIndex(
Expand Down