Skip to content

Commit

Permalink
Merge branch 'main' into discussions-url-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsojramos committed Sep 14, 2023
2 parents aa7bba3 + 43b47a6 commit c2321cc
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 13 deletions.
16 changes: 13 additions & 3 deletions src/components/Sidebar.tsx
@@ -1,7 +1,7 @@
import * as Octicons from '@primer/octicons-react';
import { ipcRenderer, shell } from 'electron';
import React, { useCallback, useContext, useMemo } from 'react';
import { useHistory } from 'react-router-dom';
import { useHistory, useLocation } from 'react-router-dom';

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

export const Sidebar: React.FC = () => {
const history = useHistory();
const location = useLocation();

const { isLoggedIn } = useContext(AppContext);
const { notifications, fetchNotifications } = useContext(AppContext);
Expand Down Expand Up @@ -64,15 +65,24 @@ export const Sidebar: React.FC = () => {
<>
<button
className={footerButtonClasses}
onClick={fetchNotifications}
onClick={() => {
history.replace('/');
fetchNotifications();
}}
aria-label="Refresh Notifications"
>
<IconRefresh className="w-3.5 h-3.5" />
</button>

<button
className={footerButtonClasses}
onClick={() => history.push('/settings')}
onClick={() => {
if (location.pathname.startsWith('/settings')) {
history.replace('/');
} else {
history.push('/settings');
}
}}
aria-label="Settings"
>
<IconCog className="w-4 h-4" />
Expand Down
3 changes: 2 additions & 1 deletion src/context/App.tsx
Expand Up @@ -22,6 +22,7 @@ import { setAutoLaunch } from '../utils/comms';
import { useInterval } from '../hooks/useInterval';
import { useNotifications } from '../hooks/useNotifications';
import Constants from '../utils/constants';
import { generateGitHubAPIUrl } from '../utils/helpers';

const defaultAccounts: AuthState = {
token: null,
Expand Down Expand Up @@ -134,7 +135,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
const validateToken = useCallback(
async ({ token, hostname }: AuthTokenOptions) => {
await apiRequestAuth(
`https://api.${hostname}/notifications`,
`${generateGitHubAPIUrl(hostname)}notifications`,
'HEAD',
token
);
Expand Down
12 changes: 7 additions & 5 deletions src/hooks/useNotifications.ts
Expand Up @@ -57,16 +57,18 @@ export const useNotifications = (): NotificationsState => {
if (!isGitHubLoggedIn) {
return;
}
const url = `https://api.${Constants.DEFAULT_AUTH_OPTIONS.hostname}/${endpointSuffix}`;
const url = `${generateGitHubAPIUrl(
Constants.DEFAULT_AUTH_OPTIONS.hostname
)}${endpointSuffix}`;
return apiRequestAuth(url, 'GET', accounts.token);
}

function getEnterpriseNotifications() {
return accounts.enterpriseAccounts.map((account) => {
const hostname = account.hostname;
const token = account.token;
const url = `https://${hostname}/api/v3/${endpointSuffix}`;
return apiRequestAuth(url, 'GET', token);
const url = `${generateGitHubAPIUrl(
account.hostname
)}${endpointSuffix}`;
return apiRequestAuth(url, 'GET', account.token);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/routes/Settings.test.tsx
Expand Up @@ -127,7 +127,7 @@ describe('routes/Settings.tsx', () => {
</AppContext.Provider>
);

fireEvent.click(getByLabelText('On Click, Mark as Read'), {
fireEvent.click(getByLabelText('Mark as read on click'), {
target: { checked: true },
});

Expand Down
2 changes: 1 addition & 1 deletion src/routes/Settings.tsx
Expand Up @@ -93,7 +93,7 @@ export const SettingsRoute: React.FC = () => {
/>
<FieldCheckbox
name="onClickMarkAsRead"
label="On Click, Mark as Read"
label="Mark as read on click"
checked={settings.markOnClick}
onChange={(evt) => updateSetting('markOnClick', evt.target.checked)}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/__snapshots__/Settings.test.tsx.snap
Expand Up @@ -214,7 +214,7 @@ exports[`routes/Settings.tsx should render itself & its children 1`] = `
className="font-medium text-gray-700 dark:text-gray-200"
htmlFor="onClickMarkAsRead"
>
On Click, Mark as Read
Mark as read on click
</label>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/utils/auth.ts
@@ -1,3 +1,5 @@
import { generateGitHubAPIUrl } from './helpers';

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

Expand Down Expand Up @@ -78,7 +80,7 @@ export const getUserData = async (
hostname: string
): Promise<User> => {
const response = await apiRequestAuth(
`https://api.${hostname}/user`,
`${generateGitHubAPIUrl(hostname)}user`,
'GET',
token
);
Expand Down

0 comments on commit c2321cc

Please sign in to comment.