Repository: gitify-app/gitify
Pull request #1306 (2024-06-21 15:56:43)

refactor: remove null ternaries


Patch:
diff --git a/src/components/AccountNotifications.tsx b/src/components/AccountNotifications.tsx
index 518e94d8..5d9f1552 100644
--- a/src/components/AccountNotifications.tsx
+++ b/src/components/AccountNotifications.tsx
@@ -101,26 +101,28 @@ export const AccountNotifications: FC<IAccountNotifications> = (
         </div>
       )}
 
-      {showAccountNotifications
-        ? groupByRepository
-          ? Object.values(groupedNotifications).map((repoNotifications) => {
-              const repoSlug = repoNotifications[0].repository.full_name;
+      {showAccountNotifications && (
+        <>
+          {groupByRepository
+            ? Object.values(groupedNotifications).map((repoNotifications) => {
+                const repoSlug = repoNotifications[0].repository.full_name;
 
-              return (
-                <RepositoryNotifications
-                  key={repoSlug}
-                  repoName={repoSlug}
-                  repoNotifications={repoNotifications}
+                return (
+                  <RepositoryNotifications
+                    key={repoSlug}
+                    repoName={repoSlug}
+                    repoNotifications={repoNotifications}
+                  />
+                );
+              })
+            : notifications.map((notification) => (
+                <NotificationRow
+                  key={notification.id}
+                  notification={notification}
                 />
-              );
-            })
-          : notifications.map((notification) => (
-              <NotificationRow
-                key={notification.id}
-                notification={notification}
-              />
-            ))
-        : null}
+              ))}
+        </>
+      )}
     </>
   );
 };
diff --git a/src/components/icons/AuthMethodIcon.tsx b/src/components/icons/AuthMethodIcon.tsx
index 85021bfb..90251bd7 100644
--- a/src/components/icons/AuthMethodIcon.tsx
+++ b/src/components/icons/AuthMethodIcon.tsx
@@ -11,11 +11,9 @@ export interface IAuthMethodIcon {
 export const AuthMethodIcon: FC<IAuthMethodIcon> = (props: IAuthMethodIcon) => {
   return (
     <span title={props.type} className="mr-1">
-      {props.type === 'GitHub App' ? <AppsIcon size={props.size} /> : null}
-      {props.type === 'Personal Access Token' ? (
-        <KeyIcon size={props.size} />
-      ) : null}
-      {props.type === 'OAuth App' ? <PersonIcon size={props.size} /> : null}
+      {props.type === 'GitHub App' && <AppsIcon size={props.size} />}
+      {props.type === 'Personal Access Token' && <KeyIcon size={props.size} />}
+      {props.type === 'OAuth App' && <PersonIcon size={props.size} />}
     </span>
   );
 };
diff --git a/src/components/icons/PlatformIcon.tsx b/src/components/icons/PlatformIcon.tsx
index 3fb34104..7fb50501 100644
--- a/src/components/icons/PlatformIcon.tsx
+++ b/src/components/icons/PlatformIcon.tsx
@@ -11,12 +11,10 @@ export interface IPlatformIcon {
 export const PlatformIcon: FC<IPlatformIcon> = (props: IPlatformIcon) => {
   return (
     <span title={props.type} className="mr-1">
-      {props.type === 'GitHub Cloud' ? (
-        <MarkGithubIcon size={props.size} />
-      ) : null}
-      {props.type === 'GitHub Enterprise Server' ? (
+      {props.type === 'GitHub Cloud' && <MarkGithubIcon size={props.size} />}
+      {props.type === 'GitHub Enterprise Server' && (
         <ServerIcon size={props.size} />
-      ) : null}
+      )}
     </span>
   );
 };
diff --git a/src/utils/auth/utils.ts b/src/utils/auth/utils.ts
index fec3e572..b15b8455 100644
--- a/src/utils/auth/utils.ts
+++ b/src/utils/auth/utils.ts
@@ -28,13 +28,15 @@ export function authGitHub(
       show: true,
     });
 
-    const githubUrl = `https://${authOptions.hostname}/login/oauth/authorize`;
-    const authUrl = `${githubUrl}?client_id=${authOptions.clientId}&scope=${Constants.AUTH_SCOPE}`;
+    const authUrl = new URL(`https://${authOptions.hostname}`);
+    authUrl.pathname = '/login/oauth/authorize';
+    authUrl.searchParams.append('client_id', authOptions.clientId);
+    authUrl.searchParams.append('scope', Constants.AUTH_SCOPE.toString());
 
     const session = authWindow.webContents.session;
     session.clearStorageData();
 
-    authWindow.loadURL(authUrl);
+    authWindow.loadURL(authUrl.toString());
 
     const handleCallback = (url: Link) => {
       const raw_code = /code=([^&]*)/.exec(url) || null;


Test patch:
diff --git a/src/utils/auth/utils.test.ts b/src/utils/auth/utils.test.ts
index 9f839959..914e90de 100644
--- a/src/utils/auth/utils.test.ts
+++ b/src/utils/auth/utils.test.ts
@@ -47,7 +47,7 @@ describe('utils/auth/utils.ts', () => {
 
       expect(loadURLMock).toHaveBeenCalledTimes(1);
       expect(loadURLMock).toHaveBeenCalledWith(
-        'https://github.com/login/oauth/authorize?client_id=FAKE_CLIENT_ID_123&scope=read:user,notifications,repo',
+        'https://github.com/login/oauth/authorize?client_id=FAKE_CLIENT_ID_123&scope=read%3Auser%2Cnotifications%2Crepo',
       );
 
       expect(browserWindow.destroy).toHaveBeenCalledTimes(1);