feat(core): add share page error boundary (#4245)

Co-authored-by: JimmFly <yangjinfei001@gmail.com>
This commit is contained in:
Alex Yang
2023-09-06 21:42:47 -07:00
committed by GitHub
parent 10f2e9300a
commit 4d96d2dd02
2 changed files with 53 additions and 1 deletions

View File

@@ -0,0 +1,35 @@
import { Empty } from '@affine/component';
import { Logo1Icon } from '@blocksuite/icons';
export const SharePageNotFoundError = () => {
return (
<div
style={{
width: '100%',
height: '100vh',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
}}
>
<a
href="https://affine.pro/"
target="_blank"
rel="noreferrer"
style={{
position: 'absolute',
top: '16px',
left: '16px',
fontSize: '24px',
cursor: 'pointer',
}}
>
<Logo1Icon />
</a>
<Empty
description={'You do not have access or this content does not exist.'}
/>
</div>
);
};

View File

@@ -9,11 +9,17 @@ import { noop } from 'foxact/noop';
import type { ReactElement } from 'react';
import { useCallback } from 'react';
import type { LoaderFunction } from 'react-router-dom';
import { redirect, useLoaderData } from 'react-router-dom';
import {
isRouteErrorResponse,
redirect,
useLoaderData,
useRouteError,
} from 'react-router-dom';
import { applyUpdate } from 'yjs';
import { PageDetailEditor } from '../../adapters/shared';
import { AppContainer } from '../../components/affine/app-container';
import { SharePageNotFoundError } from '../../components/share-page-not-found-error';
function assertArrayBuffer(value: unknown): asserts value is ArrayBuffer {
if (!(value instanceof ArrayBuffer)) {
@@ -71,3 +77,14 @@ export const Component = (): ReactElement => {
</AppContainer>
);
};
export function ErrorBoundary() {
const error = useRouteError();
return isRouteErrorResponse(error) ? (
<h1>
{error.status} {error.statusText}
</h1>
) : (
<SharePageNotFoundError />
);
}