Skip to content

Commit 43b47a6

Browse files
feat: settings button toggle between settings and notifications (#553)
Co-authored-by: Afonso Jorge Ramos <[email protected]>
1 parent e35c68b commit 43b47a6

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

src/components/Sidebar.tsx

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as Octicons from '@primer/octicons-react';
22
import { ipcRenderer, shell } from 'electron';
33
import React, { useCallback, useContext, useMemo } from 'react';
4-
import { useHistory } from 'react-router-dom';
4+
import { useHistory, useLocation } from 'react-router-dom';
55

66
import { Logo } from '../components/Logo';
77
import { AppContext } from '../context/App';
@@ -12,6 +12,7 @@ import { Constants } from '../utils/constants';
1212

1313
export const Sidebar: React.FC = () => {
1414
const history = useHistory();
15+
const location = useLocation();
1516

1617
const { isLoggedIn } = useContext(AppContext);
1718
const { notifications, fetchNotifications } = useContext(AppContext);
@@ -64,15 +65,24 @@ export const Sidebar: React.FC = () => {
6465
<>
6566
<button
6667
className={footerButtonClasses}
67-
onClick={fetchNotifications}
68+
onClick={() => {
69+
history.replace('/');
70+
fetchNotifications();
71+
}}
6872
aria-label="Refresh Notifications"
6973
>
7074
<IconRefresh className="w-3.5 h-3.5" />
7175
</button>
7276

7377
<button
7478
className={footerButtonClasses}
75-
onClick={() => history.push('/settings')}
79+
onClick={() => {
80+
if (location.pathname.startsWith('/settings')) {
81+
history.replace('/');
82+
} else {
83+
history.push('/settings');
84+
}
85+
}}
7686
aria-label="Settings"
7787
>
7888
<IconCog className="w-4 h-4" />

src/hooks/useNotifications.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ export const useNotifications = (): NotificationsState => {
5757
if (!isGitHubLoggedIn) {
5858
return;
5959
}
60-
const url = `${generateGitHubAPIUrl(Constants.DEFAULT_AUTH_OPTIONS.hostname)}${endpointSuffix}`;
60+
const url = `${generateGitHubAPIUrl(
61+
Constants.DEFAULT_AUTH_OPTIONS.hostname
62+
)}${endpointSuffix}`;
6163
return apiRequestAuth(url, 'GET', accounts.token);
6264
}
6365

6466
function getEnterpriseNotifications() {
6567
return accounts.enterpriseAccounts.map((account) => {
66-
const url = `${generateGitHubAPIUrl(account.hostname)}${endpointSuffix}`;
68+
const url = `${generateGitHubAPIUrl(
69+
account.hostname
70+
)}${endpointSuffix}`;
6771
return apiRequestAuth(url, 'GET', account.token);
6872
});
6973
}

src/routes/LoginWithToken.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ export const LoginWithToken: React.FC = () => {
6363
To generate a token, go to GitHub,{' '}
6464
<a
6565
className="underline hover:text-gray-500 dark:hover:text-gray-300 cursor-pointer"
66-
onClick={() => openLink('https://github.com/settings/tokens/new?scopes=notifications,read:user&description=gitify_token')}
66+
onClick={() =>
67+
openLink(
68+
'https://github.com/settings/tokens/new?scopes=notifications,read:user&description=gitify_token'
69+
)
70+
}
6771
>
6872
personal access tokens
6973
</a>{' '}

src/routes/Settings.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe('routes/Settings.tsx', () => {
127127
</AppContext.Provider>
128128
);
129129

130-
fireEvent.click(getByLabelText('On Click, Mark as Read'), {
130+
fireEvent.click(getByLabelText('Mark as read on click'), {
131131
target: { checked: true },
132132
});
133133

src/routes/__snapshots__/Settings.test.tsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ exports[`routes/Settings.tsx should render itself & its children 1`] = `
214214
className="font-medium text-gray-700 dark:text-gray-200"
215215
htmlFor="onClickMarkAsRead"
216216
>
217-
On Click, Mark as Read
217+
Mark as read on click
218218
</label>
219219
</div>
220220
</div>

src/utils/auth.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { generateGitHubAPIUrl } from "./helpers";
1+
import { generateGitHubAPIUrl } from './helpers';
22

33
const { remote } = require('electron');
44
const BrowserWindow = remote.BrowserWindow;

0 commit comments

Comments
 (0)