1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

Merge remote-tracking branch 'origin/master'

This commit is contained in:
Fedor Katurov 2022-02-25 14:08:13 +07:00
commit ec5e796f32
2 changed files with 35 additions and 18 deletions

7
src/pages/500.tsx Normal file
View file

@ -0,0 +1,7 @@
import { NotFoundLayout } from '~/layouts/NotFoundLayout';
const InternalServerErrorPage = () => {
return <NotFoundLayout />;
};
export default InternalServerErrorPage;

View file

@ -1,7 +1,7 @@
import React, { FC } from 'react';
import { observer } from 'mobx-react-lite';
import { InferGetStaticPropsType } from 'next';
import { GetStaticPropsResult, InferGetStaticPropsType } from 'next';
import { RouteComponentProps } from 'react-router';
import { apiGetNode, getNodeDiff } from '~/api/node';
@ -14,6 +14,7 @@ import { useNodePageParams } from '~/hooks/node/useNodePageParams';
import { useNodePermissions } from '~/hooks/node/useNodePermissions';
import { useNodeTags } from '~/hooks/node/useNodeTags';
import { NodeLayout } from '~/layouts/NodeLayout';
import { ApiGetNodeResponse } from '~/types/node';
import { CommentContextProvider } from '~/utils/context/CommentContextProvider';
import { NodeContextProvider } from '~/utils/context/NodeContextProvider';
import { TagsContextProvider } from '~/utils/context/TagsContextProvider';
@ -42,15 +43,18 @@ export const getStaticPaths = async () => {
};
};
export const getStaticProps = async context => {
export const getStaticProps = async (
context
): Promise<GetStaticPropsResult<{ fallbackData: ApiGetNodeResponse }>> => {
try {
if (!context.params?.id) {
return { props: {} };
return { notFound: true };
}
const id = parseInt(context.params.id, 10);
if (!id) {
return { props: {} };
return { notFound: true };
}
const fallbackData = await apiGetNode({ id });
@ -64,6 +68,12 @@ export const getStaticProps = async context => {
},
revalidate: 7 * 86400, // every week
};
} catch (error) {
console.warn(`[NEXT] can't generate node: `, error);
return {
notFound: true,
};
}
};
type Props = RouteComponentProps<{ id: string }> & InferGetStaticPropsType<typeof getStaticProps>;