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 { useLoadNode } from '~/hooks/node/useLoadNode';
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
import { useNodePageParams } from '~/hooks/node/useNodePageParams';
|
import { useNodePageParams } from '~/hooks/node/useNodePageParams';
|
||||||
import { GetServerSidePropsContext } from 'next';
|
import { InferGetServerSidePropsType } from 'next';
|
||||||
import { apiGetNode } from '~/api/node';
|
import { apiGetNode } from '~/api/node';
|
||||||
import { ApiGetNodeResponse } from '~/types/node';
|
|
||||||
|
|
||||||
export async function getServerSideProps(
|
export const getServerSideProps = async context => {
|
||||||
context: GetServerSidePropsContext<{ id: string }, ApiGetNodeResponse>
|
if (!context.params?.id) {
|
||||||
) {
|
return { props: {} };
|
||||||
const id = parseInt(context.query.id as string, 10);
|
}
|
||||||
|
|
||||||
|
const id = parseInt(context.params.id, 10);
|
||||||
|
|
||||||
if (!id) {
|
if (!id) {
|
||||||
return { props: {} };
|
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 NodePage: FC<Props> = observer(props => {
|
||||||
const id = useNodePageParams();
|
const id = useNodePageParams();
|
||||||
const { node, isLoading, update, lastSeen } = useLoadNode(parseInt(id, 10), props.fallbackData);
|
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 { ModalStore } from '~/store/modal/ModalStore';
|
||||||
import { LabStore } from '~/store/lab/LabStore';
|
import { LabStore } from '~/store/lab/LabStore';
|
||||||
import { AuthStore } from '~/store/auth/AuthStore';
|
import { AuthStore } from '~/store/auth/AuthStore';
|
||||||
import { useStaticRendering } from 'mobx-react-lite';
|
import { enableStaticRendering, useStaticRendering } from 'mobx-react-lite';
|
||||||
|
|
||||||
export class Store {
|
export class Store {
|
||||||
flow = new FlowStore();
|
flow = new FlowStore();
|
||||||
|
@ -24,5 +24,4 @@ const defaultStore = new Store();
|
||||||
|
|
||||||
export const getMOBXStore = () => defaultStore;
|
export const getMOBXStore = () => defaultStore;
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
enableStaticRendering(typeof window === 'undefined');
|
||||||
useStaticRendering(typeof window === 'undefined');
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ export type PostCellViewResult = unknown; // TODO: update it with actual type
|
||||||
export type ApiGetNodeRequest = {
|
export type ApiGetNodeRequest = {
|
||||||
id: string | number;
|
id: string | number;
|
||||||
};
|
};
|
||||||
export type ApiGetNodeResponse = { node: INode; last_seen?: string };
|
export type ApiGetNodeResponse = { node: INode; last_seen?: string | null };
|
||||||
|
|
||||||
export type ApiGetNodeRelatedRequest = {
|
export type ApiGetNodeRelatedRequest = {
|
||||||
id: INode['id'];
|
id: INode['id'];
|
||||||
|
|
|
@ -4,7 +4,7 @@ import React, { createContext, FC, useContext } from 'react';
|
||||||
export interface CommentProviderProps {
|
export interface CommentProviderProps {
|
||||||
comments: IComment[];
|
comments: IComment[];
|
||||||
hasMore: boolean;
|
hasMore: boolean;
|
||||||
lastSeenCurrent?: string;
|
lastSeenCurrent?: string | null;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
onShowImageModal: (images: IFile[], index: number) => void;
|
onShowImageModal: (images: IFile[], index: number) => void;
|
||||||
onLoadMoreComments: () => void;
|
onLoadMoreComments: () => void;
|
||||||
|
@ -16,7 +16,7 @@ const CommentContext = createContext<CommentProviderProps>({
|
||||||
// user: EMPTY_USER,
|
// user: EMPTY_USER,
|
||||||
comments: [],
|
comments: [],
|
||||||
hasMore: false,
|
hasMore: false,
|
||||||
lastSeenCurrent: undefined,
|
lastSeenCurrent: null,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
onSaveComment: async () => {},
|
onSaveComment: async () => {},
|
||||||
onShowImageModal: () => {},
|
onShowImageModal: () => {},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue