Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clear global error state on fetch #1443

Merged
merged 2 commits into from
Aug 7, 2024
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
1 change: 1 addition & 0 deletions src/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const useNotifications = (): NotificationsState => {
const fetchNotifications = useCallback(
async (state: GitifyState) => {
setStatus('loading');
setGlobalError(null);

const fetchedNotifications = await getAllNotifications(state);

Expand Down
8 changes: 5 additions & 3 deletions src/routes/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { AllRead } from '../components/AllRead';
import { Oops } from '../components/Oops';
import { AppContext } from '../context/App';
import { getAccountUUID } from '../utils/auth/utils';
import { Errors } from '../utils/constants';
import { getNotificationCount } from '../utils/notifications';

export const NotificationsRoute: FC = () => {
const { notifications, globalError, settings } = useContext(AppContext);
const { notifications, status, globalError, settings } =
useContext(AppContext);

const hasMultipleAccounts = useMemo(
() => notifications.length > 1,
Expand All @@ -24,8 +26,8 @@ export const NotificationsRoute: FC = () => {
[notifications],
);

if (globalError) {
return <Oops error={globalError} />;
if (status === 'error') {
return <Oops error={globalError ?? Errors.UNKNOWN} />;
}

if (!hasNotifications && hasNoAccountErrors) {
Expand Down
4 changes: 2 additions & 2 deletions src/routes/__snapshots__/Notifications.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.