Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions src/components/Loading.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ describe('components/Loading.tsx', () => {
jest.clearAllMocks();
});

it('should check that NProgress is getting called in when isFetching changes (loading)', () => {
it('should check that NProgress is getting called in when status changes (loading)', () => {
const { container } = render(
<AppContext.Provider value={{ isFetching: true }}>
<AppContext.Provider value={{ status: 'loading' }}>
<Loading />
</AppContext.Provider>,
);
Expand All @@ -28,9 +28,9 @@ describe('components/Loading.tsx', () => {
expect(NProgress.start).toHaveBeenCalledTimes(1);
});

it('should check that NProgress is getting called in when isFetching changes (not loading)', () => {
it('should check that NProgress is getting called in when status changes (not loading)', () => {
const { container } = render(
<AppContext.Provider value={{ isFetching: false }}>
<AppContext.Provider value={{ status: 'success' }}>
<Loading />
</AppContext.Provider>,
);
Expand All @@ -42,7 +42,7 @@ describe('components/Loading.tsx', () => {

it('should remove NProgress on unmount', () => {
const { unmount } = render(
<AppContext.Provider value={{ isFetching: true }}>
<AppContext.Provider value={{ status: 'loading' }}>
<Loading />
</AppContext.Provider>,
);
Expand Down
6 changes: 3 additions & 3 deletions src/components/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useContext, useEffect } from 'react';
import { AppContext } from '../context/App';

export const Loading = () => {
const { isFetching } = useContext(AppContext);
const { status } = useContext(AppContext);

useEffect(() => {
NProgress.configure({
Expand All @@ -17,12 +17,12 @@ export const Loading = () => {
}, []);

useEffect(() => {
if (isFetching) {
if (status === 'loading') {
NProgress.start();
} else {
NProgress.done();
}
}, [isFetching]);
}, [status]);

return null;
};
7 changes: 3 additions & 4 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const Sidebar: FC = () => {
const navigate = useNavigate();
const location = useLocation();

const { notifications, fetchNotifications, isLoggedIn, isFetching } =
const { notifications, fetchNotifications, isLoggedIn, status } =
useContext(AppContext);

const onOpenBrowser = useCallback(() => {
Expand Down Expand Up @@ -81,15 +81,14 @@ export const Sidebar: FC = () => {
navigate('/', { replace: true });
fetchNotifications();
}}
disabled={isFetching}
disabled={status === 'loading'}
>
<SyncIcon
size={16}
aria-label="Refresh Notifications"
className={isFetching ? 'animate-spin' : undefined}
className={status === 'loading' ? 'animate-spin' : undefined}
/>
</button>

<button
type="button"
className={sidebarButtonClasses}
Expand Down
10 changes: 4 additions & 6 deletions src/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
type AuthTokenOptions,
type GitifyError,
type SettingsState,
type Status,
Theme,
} from '../types';
import { headNotifications } from '../utils/api/client';
Expand Down Expand Up @@ -54,8 +55,7 @@ interface AppContextState {
logout: () => void;

notifications: AccountNotifications[];
isFetching: boolean;
requestFailed: boolean;
status: Status;
errorDetails: GitifyError;
removeNotificationFromState: (id: string, hostname: string) => void;
fetchNotifications: () => Promise<void>;
Expand All @@ -80,9 +80,8 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
const {
fetchNotifications,
notifications,
requestFailed,
errorDetails,
isFetching,
status,
removeNotificationFromState,
markNotificationRead,
markNotificationDone,
Expand Down Expand Up @@ -239,8 +238,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
logout,

notifications,
isFetching,
requestFailed,
status,
errorDetails,
removeNotificationFromState,
fetchNotifications: fetchNotificationsWithAccounts,
Expand Down
Loading