Repository: gitify-app/gitify
Pull request #1202 (2024-06-08 11:26:51)

refactor: rename to markRepoNotificationsRead
rename 
- `markRepoNotifications` to `markRepoNotificationsRead`
- `markRepoNotificationsWithAccounts` to `markRepoNotificationsReadWithAccounts`


Patch:
diff --git a/index.html b/index.html
index 1178f95c..7705d6ee 100644
--- a/index.html
+++ b/index.html
@@ -1,5 +1,5 @@
 <!doctype html>
-<html>
+<html lang="en">
   <head>
     <title>Gitify</title>
     <meta charset="utf-8" />
diff --git a/src/components/Repository.tsx b/src/components/Repository.tsx
index 2b787761..fc66fa33 100644
--- a/src/components/Repository.tsx
+++ b/src/components/Repository.tsx
@@ -17,7 +17,7 @@ export const RepositoryNotifications: FC<IProps> = ({
   repoNotifications,
   hostname,
 }) => {
-  const { markRepoNotifications, markRepoNotificationsDone } =
+  const { markRepoNotificationsRead, markRepoNotificationsDone } =
     useContext(AppContext);
 
   const openBrowser = useCallback(() => {
@@ -27,7 +27,7 @@ export const RepositoryNotifications: FC<IProps> = ({
 
   const markRepoAsRead = useCallback(() => {
     const repoSlug = repoNotifications[0].repository.full_name;
-    markRepoNotifications(repoSlug, hostname);
+    markRepoNotificationsRead(repoSlug, hostname);
   }, [repoNotifications, hostname]);
 
   const markRepoAsDone = useCallback(() => {
diff --git a/src/context/App.tsx b/src/context/App.tsx
index 6f138eae..6ff3a1f1 100644
--- a/src/context/App.tsx
+++ b/src/context/App.tsx
@@ -79,7 +79,7 @@ interface AppContextState {
   markNotificationRead: (id: string, hostname: string) => Promise<void>;
   markNotificationDone: (id: string, hostname: string) => Promise<void>;
   unsubscribeNotification: (id: string, hostname: string) => Promise<void>;
-  markRepoNotifications: (id: string, hostname: string) => Promise<void>;
+  markRepoNotificationsRead: (id: string, hostname: string) => Promise<void>;
   markRepoNotificationsDone: (id: string, hostname: string) => Promise<void>;
 
   settings: SettingsState;
@@ -103,7 +103,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
     markNotificationRead,
     markNotificationDone,
     unsubscribeNotification,
-    markRepoNotifications,
+    markRepoNotificationsRead,
     markRepoNotificationsDone,
   } = useNotifications();
 
@@ -112,7 +112,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
   }, []);
 
   useEffect(() => {
-    setTheme(settings.theme as Theme);
+    setTheme(settings.theme);
   }, [settings.theme]);
 
   // biome-ignore lint/correctness/useExhaustiveDependencies: We only want fetchNotifications to be called for certain account or setting changes.
@@ -248,9 +248,9 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
     [auth, notifications],
   );
 
-  const markRepoNotificationsWithAccounts = useCallback(
+  const markRepoNotificationsReadWithAccounts = useCallback(
     async (repoSlug: string, hostname: string) =>
-      await markRepoNotifications({ auth, settings }, repoSlug, hostname),
+      await markRepoNotificationsRead({ auth, settings }, repoSlug, hostname),
     [auth, notifications],
   );
 
@@ -279,7 +279,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
         markNotificationRead: markNotificationReadWithAccounts,
         markNotificationDone: markNotificationDoneWithAccounts,
         unsubscribeNotification: unsubscribeNotificationWithAccounts,
-        markRepoNotifications: markRepoNotificationsWithAccounts,
+        markRepoNotificationsRead: markRepoNotificationsReadWithAccounts,
         markRepoNotificationsDone: markRepoNotificationsDoneWithAccounts,
 
         settings,
diff --git a/src/hooks/useNotifications.ts b/src/hooks/useNotifications.ts
index 7dd93dff..2dc51884 100644
--- a/src/hooks/useNotifications.ts
+++ b/src/hooks/useNotifications.ts
@@ -45,7 +45,7 @@ interface NotificationsState {
     id: string,
     hostname: string,
   ) => Promise<void>;
-  markRepoNotifications: (
+  markRepoNotificationsRead: (
     state: GitifyState,
     repoSlug: string,
     hostname: string,
@@ -154,7 +154,7 @@ export const useNotifications = (): NotificationsState => {
     [notifications],
   );
 
-  const markRepoNotifications = useCallback(
+  const markRepoNotificationsRead = useCallback(
     async (state: GitifyState, repoSlug: string, hostname: string) => {
       setStatus('loading');
 
@@ -251,7 +251,7 @@ export const useNotifications = (): NotificationsState => {
     markNotificationRead,
     markNotificationDone,
     unsubscribeNotification,
-    markRepoNotifications,
+    markRepoNotificationsRead,
     markRepoNotificationsDone,
   };
 };
diff --git a/src/routes/Settings.tsx b/src/routes/Settings.tsx
index dec907f2..d0ef2e18 100644
--- a/src/routes/Settings.tsx
+++ b/src/routes/Settings.tsx
@@ -59,7 +59,7 @@ export const SettingsRoute: FC = () => {
         setTheme(updatedTheme);
       }
     });
-  }, []);
+  }, [settings.theme]);
 
   const quitApp = useCallback(() => {
     ipcRenderer.send('app-quit');
diff --git a/src/utils/comms.ts b/src/utils/comms.ts
index 3bfa0964..99506975 100644
--- a/src/utils/comms.ts
+++ b/src/utils/comms.ts
@@ -24,7 +24,3 @@ export function updateTrayIcon(notificationsLength = 0): void {
 export function updateTrayTitle(title = ''): void {
   ipcRenderer.send('update-title', title);
 }
-
-export function restoreSetting(setting, value): void {
-  ipcRenderer.send(setting, value);
-}


Test patch:
diff --git a/src/components/Repository.test.tsx b/src/components/Repository.test.tsx
index 888e7658..0e539cc0 100644
--- a/src/components/Repository.test.tsx
+++ b/src/components/Repository.test.tsx
@@ -9,7 +9,7 @@ jest.mock('./NotificationRow', () => ({
 }));
 
 describe('components/Repository.tsx', () => {
-  const markRepoNotifications = jest.fn();
+  const markRepoNotificationsRead = jest.fn();
   const markRepoNotificationsDone = jest.fn();
 
   const props = {
@@ -19,7 +19,7 @@ describe('components/Repository.tsx', () => {
   };
 
   beforeEach(() => {
-    markRepoNotifications.mockReset();
+    markRepoNotificationsRead.mockReset();
 
     jest.spyOn(shell, 'openExternal');
   });
@@ -50,14 +50,14 @@ describe('components/Repository.tsx', () => {
 
   it('should mark a repo as read', () => {
     render(
-      <AppContext.Provider value={{ markRepoNotifications }}>
+      <AppContext.Provider value={{ markRepoNotificationsRead }}>
         <RepositoryNotifications {...props} />
       </AppContext.Provider>,
     );
 
     fireEvent.click(screen.getByTitle('Mark Repository as Read'));
 
-    expect(markRepoNotifications).toHaveBeenCalledWith(
+    expect(markRepoNotificationsRead).toHaveBeenCalledWith(
       'gitify-app/notifications-test',
       'github.com',
     );
diff --git a/src/context/App.test.tsx b/src/context/App.test.tsx
index 5773b80e..23adaed9 100644
--- a/src/context/App.test.tsx
+++ b/src/context/App.test.tsx
@@ -45,7 +45,7 @@ describe('context/App.tsx', () => {
     const markNotificationReadMock = jest.fn();
     const markNotificationDoneMock = jest.fn();
     const unsubscribeNotificationMock = jest.fn();
-    const markRepoNotificationsMock = jest.fn();
+    const markRepoNotificationsReadMock = jest.fn();
     const markRepoNotificationsDoneMock = jest.fn();
 
     const mockDefaultState = {
@@ -59,7 +59,7 @@ describe('context/App.tsx', () => {
         markNotificationRead: markNotificationReadMock,
         markNotificationDone: markNotificationDoneMock,
         unsubscribeNotification: unsubscribeNotificationMock,
-        markRepoNotifications: markRepoNotificationsMock,
+        markRepoNotificationsRead: markRepoNotificationsReadMock,
         markRepoNotificationsDone: markRepoNotificationsDoneMock,
       });
     });
@@ -198,15 +198,15 @@ describe('context/App.tsx', () => {
       );
     });
 
-    it('should call markRepoNotifications', async () => {
+    it('should call markRepoNotificationsRead', async () => {
       const TestComponent = () => {
-        const { markRepoNotifications } = useContext(AppContext);
+        const { markRepoNotificationsRead } = useContext(AppContext);
 
         return (
           <button
             type="button"
             onClick={() =>
-              markRepoNotifications(
+              markRepoNotificationsRead(
                 'gitify-app/notifications-test',
                 'github.com',
               )
@@ -219,12 +219,12 @@ describe('context/App.tsx', () => {
 
       const { getByText } = customRender(<TestComponent />);
 
-      markRepoNotificationsMock.mockReset();
+      markRepoNotificationsReadMock.mockReset();
 
       fireEvent.click(getByText('Test Case'));
 
-      expect(markRepoNotificationsMock).toHaveBeenCalledTimes(1);
-      expect(markRepoNotificationsMock).toHaveBeenCalledWith(
+      expect(markRepoNotificationsReadMock).toHaveBeenCalledTimes(1);
+      expect(markRepoNotificationsReadMock).toHaveBeenCalledWith(
         mockDefaultState,
         'gitify-app/notifications-test',
         'github.com',
diff --git a/src/hooks/useNotifications.test.ts b/src/hooks/useNotifications.test.ts
index 04973282..fe562e38 100644
--- a/src/hooks/useNotifications.test.ts
+++ b/src/hooks/useNotifications.test.ts
@@ -467,7 +467,7 @@ describe('hooks/useNotifications.ts', () => {
     });
   });
 
-  describe('markRepoNotifications', () => {
+  describe('markRepoNotificationsRead', () => {
     const hostname = 'github.com';
     const repoSlug = 'gitify-app/notifications-test';
 
@@ -479,7 +479,7 @@ describe('hooks/useNotifications.ts', () => {
       const { result } = renderHook(() => useNotifications());
 
       act(() => {
-        result.current.markRepoNotifications(mockState, repoSlug, hostname);
+        result.current.markRepoNotificationsRead(mockState, repoSlug, hostname);
       });
 
       await waitFor(() => {
@@ -497,7 +497,7 @@ describe('hooks/useNotifications.ts', () => {
       const { result } = renderHook(() => useNotifications());
 
       act(() => {
-        result.current.markRepoNotifications(mockState, repoSlug, hostname);
+        result.current.markRepoNotificationsRead(mockState, repoSlug, hostname);
       });
 
       await waitFor(() => {
diff --git a/src/utils/comms.test.ts b/src/utils/comms.test.ts
index d00bde6f..478b2af3 100644
--- a/src/utils/comms.test.ts
+++ b/src/utils/comms.test.ts
@@ -1,10 +1,5 @@
 import { ipcRenderer, shell } from 'electron';
-import {
-  openExternalLink,
-  restoreSetting,
-  setAutoLaunch,
-  updateTrayIcon,
-} from './comms';
+import { openExternalLink, setAutoLaunch, updateTrayIcon } from './comms';
 
 describe('utils/comms.ts', () => {
   beforeEach(() => {
@@ -29,12 +24,6 @@ describe('utils/comms.ts', () => {
     expect(ipcRenderer.send).toHaveBeenCalledWith('update-icon');
   });
 
-  it('should restore a setting', () => {
-    restoreSetting('foo', 'bar');
-    expect(ipcRenderer.send).toHaveBeenCalledTimes(1);
-    expect(ipcRenderer.send).toHaveBeenCalledWith('foo', 'bar');
-  });
-
   it('should open an external link', () => {
     openExternalLink('http://www.gitify.io/');
     expect(shell.openExternal).toHaveBeenCalledTimes(1);