mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
(nextjs) fixed getServerSideProps typings
This commit is contained in:
parent
2d9d88f1a1
commit
d9127e5b7c
4 changed files with 15 additions and 16 deletions
|
@ -13,14 +13,15 @@ import { NodeRelatedProvider } from '~/utils/providers/NodeRelatedProvider';
|
|||
import { useLoadNode } from '~/hooks/node/useLoadNode';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { useNodePageParams } from '~/hooks/node/useNodePageParams';
|
||||
import { GetServerSidePropsContext } from 'next';
|
||||
import { InferGetServerSidePropsType } from 'next';
|
||||
import { apiGetNode } from '~/api/node';
|
||||
import { ApiGetNodeResponse } from '~/types/node';
|
||||
|
||||
export async function getServerSideProps(
|
||||
context: GetServerSidePropsContext<{ id: string }, ApiGetNodeResponse>
|
||||
) {
|
||||
const id = parseInt(context.query.id as string, 10);
|
||||
export const getServerSideProps = async context => {
|
||||
if (!context.params?.id) {
|
||||
return { props: {} };
|
||||
}
|
||||
|
||||
const id = parseInt(context.params.id, 10);
|
||||
|
||||
if (!id) {
|
||||
return { props: {} };
|
||||
|
@ -36,12 +37,11 @@ export async function getServerSideProps(
|
|||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
type Props = RouteComponentProps<{ id: string }> & {
|
||||
fallbackData?: ApiGetNodeResponse;
|
||||
};
|
||||
|
||||
type Props = RouteComponentProps<{ id: string }> &
|
||||
InferGetServerSidePropsType<typeof getServerSideProps>;
|
||||
|
||||
const NodePage: FC<Props> = observer(props => {
|
||||
const id = useNodePageParams();
|
||||
const { node, isLoading, update, lastSeen } = useLoadNode(parseInt(id, 10), props.fallbackData);
|
||||
|
|
|
@ -3,7 +3,7 @@ import { FlowStore } from '~/store/flow/FlowStore';
|
|||
import { ModalStore } from '~/store/modal/ModalStore';
|
||||
import { LabStore } from '~/store/lab/LabStore';
|
||||
import { AuthStore } from '~/store/auth/AuthStore';
|
||||
import { useStaticRendering } from 'mobx-react-lite';
|
||||
import { enableStaticRendering, useStaticRendering } from 'mobx-react-lite';
|
||||
|
||||
export class Store {
|
||||
flow = new FlowStore();
|
||||
|
@ -24,5 +24,4 @@ const defaultStore = new Store();
|
|||
|
||||
export const getMOBXStore = () => defaultStore;
|
||||
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
useStaticRendering(typeof window === 'undefined');
|
||||
enableStaticRendering(typeof window === 'undefined');
|
||||
|
|
|
@ -30,7 +30,7 @@ export type PostCellViewResult = unknown; // TODO: update it with actual type
|
|||
export type ApiGetNodeRequest = {
|
||||
id: string | number;
|
||||
};
|
||||
export type ApiGetNodeResponse = { node: INode; last_seen?: string };
|
||||
export type ApiGetNodeResponse = { node: INode; last_seen?: string | null };
|
||||
|
||||
export type ApiGetNodeRelatedRequest = {
|
||||
id: INode['id'];
|
||||
|
|
|
@ -4,7 +4,7 @@ import React, { createContext, FC, useContext } from 'react';
|
|||
export interface CommentProviderProps {
|
||||
comments: IComment[];
|
||||
hasMore: boolean;
|
||||
lastSeenCurrent?: string;
|
||||
lastSeenCurrent?: string | null;
|
||||
isLoading: boolean;
|
||||
onShowImageModal: (images: IFile[], index: number) => void;
|
||||
onLoadMoreComments: () => void;
|
||||
|
@ -16,7 +16,7 @@ const CommentContext = createContext<CommentProviderProps>({
|
|||
// user: EMPTY_USER,
|
||||
comments: [],
|
||||
hasMore: false,
|
||||
lastSeenCurrent: undefined,
|
||||
lastSeenCurrent: null,
|
||||
isLoading: false,
|
||||
onSaveComment: async () => {},
|
||||
onShowImageModal: () => {},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue