Skip to content

refactor: error page fallback #1765

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

Merged
merged 1 commit into from
Jan 23, 2025
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
8 changes: 7 additions & 1 deletion src/renderer/components/Oops.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render } from '@testing-library/react';
import { Oops } from './Oops';

describe('renderer/components/Oops.tsx', () => {
it('should render itself & its children', () => {
it('should render itself & its children - specified error', () => {
const mockError = {
title: 'Error title',
descriptions: ['Error description'],
Expand All @@ -12,4 +12,10 @@ describe('renderer/components/Oops.tsx', () => {

expect(tree).toMatchSnapshot();
});

it('should render itself & its children - fallback to unknown error', () => {
const tree = render(<Oops error={null} />);

expect(tree).toMatchSnapshot();
});
});
11 changes: 7 additions & 4 deletions src/renderer/components/Oops.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type FC, useMemo } from 'react';

import type { GitifyError } from '../types';
import { Errors } from '../utils/errors';
import { EmojiSplash } from './layout/EmojiSplash';

interface IOops {
Expand All @@ -9,16 +10,18 @@ interface IOops {
}

export const Oops: FC<IOops> = ({ error, fullHeight = true }: IOops) => {
const err = error ?? Errors.UNKNOWN;

const emoji = useMemo(
() => error.emojis[Math.floor(Math.random() * error.emojis.length)],
[error],
() => err.emojis[Math.floor(Math.random() * err.emojis.length)],
[err],
);

return (
<EmojiSplash
emoji={emoji}
heading={error.title}
subHeadings={error.descriptions}
heading={err.title}
subHeadings={err.descriptions}
fullHeight={fullHeight}
/>
);
Expand Down
163 changes: 162 additions & 1 deletion src/renderer/components/__snapshots__/Oops.test.tsx.snap

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

3 changes: 1 addition & 2 deletions src/renderer/routes/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Oops } from '../components/Oops';
import { AccountNotifications } from '../components/notifications/AccountNotifications';
import { AppContext } from '../context/App';
import { getAccountUUID } from '../utils/auth/utils';
import { Errors } from '../utils/errors';
import { getNotificationCount } from '../utils/notifications/notifications';

export const NotificationsRoute: FC = () => {
Expand All @@ -28,7 +27,7 @@ export const NotificationsRoute: FC = () => {
);

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

if (!hasNotifications && hasNoAccountErrors) {
Expand Down
Loading