diff --git a/src/components/AbstractRefList/AbstractRefList.tsx b/src/components/AbstractRefList/AbstractRefList.tsx index 87f87d15c..3e84ecb5b 100644 --- a/src/components/AbstractRefList/AbstractRefList.tsx +++ b/src/components/AbstractRefList/AbstractRefList.tsx @@ -28,6 +28,10 @@ export const AbstractRefList = (props: IAbstractRefListProps): ReactElement => { void router.push({ pathname: router.pathname, search: stringifySearchParams({ ...router.query, p: page }) }); }; + if (!docs) { + return null; + } + return ( diff --git a/src/middleware.ts b/src/middleware.ts index 9f06e1ca3..a5090b7e3 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -161,7 +161,7 @@ export const config = { matcher: [ { source: - '/((?!api|_next/static|light|dark|_next/image|favicon|android|images|mockServiceWorker|site.webmanifest|error|feedback|classic-form|paper-form).*)', + '/((?!api|_next/static|_next/data|light|dark|_next/image|favicon|android|images|mockServiceWorker|site.webmanifest|error|feedback|classic-form|paper-form).*)', missing: [ { type: 'header', key: 'next-router-prefetch' }, { type: 'header', key: 'purpose', value: 'prefetch' }, diff --git a/src/pages/abs/[id]/citations.tsx b/src/pages/abs/[id]/citations.tsx index 69d127733..d6c87b778 100644 --- a/src/pages/abs/[id]/citations.tsx +++ b/src/pages/abs/[id]/citations.tsx @@ -7,10 +7,16 @@ import { NextPage } from 'next'; import { useRouter } from 'next/router'; import { path } from 'ramda'; import { APP_DEFAULTS } from '@/config'; +import { ItemsSkeleton } from '@/components'; const CitationsPage: NextPage = () => { const router = useRouter(); - const { data: abstractDoc, error: abstractError } = useGetAbstract({ id: router.query.id as string }); + const { + data: abstractDoc, + error: abstractError, + isLoading: absLoading, + isFetching: absFetching, + } = useGetAbstract({ id: router.query.id as string }); const doc = path(['docs', 0], abstractDoc); const pageIndex = router.query.p ? parseInt(router.query.p as string) - 1 : 0; const { getParams, onPageChange } = useGetAbstractParams(doc?.bibcode); @@ -20,11 +26,16 @@ const CitationsPage: NextPage = () => { data, isSuccess, error: citationsError, + isLoading: citLoading, + isFetching: citFetching, } = useGetCitations({ ...getParams(), start: pageIndex * APP_DEFAULTS.RESULT_PER_PAGE }, { keepPreviousData: true }); + + const isLoading = absLoading || absFetching || citLoading || citFetching; const citationsParams = getCitationsParams(doc?.bibcode, 0); return ( + {isLoading ? : null} {(abstractError || citationsError) && ( diff --git a/src/pages/abs/[id]/coreads.tsx b/src/pages/abs/[id]/coreads.tsx index a70d1df4e..19df0ffa2 100644 --- a/src/pages/abs/[id]/coreads.tsx +++ b/src/pages/abs/[id]/coreads.tsx @@ -1,10 +1,11 @@ import { getCoreadsParams, useGetAbstract, useGetCoreads } from '@/api'; -import { AbstractRefList } from '@/components'; +import { AbstractRefList, ItemsSkeleton, StandardAlertMessage } from '@/components'; import { AbsLayout } from '@/components/Layout/AbsLayout'; import { useGetAbstractParams } from '@/lib/useGetAbstractParams'; import { NextPage } from 'next'; import { useRouter } from 'next/router'; import { APP_DEFAULTS } from '@/config'; +import { parseAPIError } from '@/utils'; const CoreadsPage: NextPage = () => { const router = useRouter(); @@ -14,7 +15,7 @@ const CoreadsPage: NextPage = () => { const { getParams, onPageChange } = useGetAbstractParams(doc?.bibcode); - const { data, isSuccess } = useGetCoreads( + const { data, isSuccess, isLoading, isFetching, error, isError } = useGetCoreads( { ...getParams(), start: pageIndex * APP_DEFAULTS.RESULT_PER_PAGE }, { keepPreviousData: true }, ); @@ -22,7 +23,9 @@ const CoreadsPage: NextPage = () => { return ( - {isSuccess && ( + {isLoading || isFetching ? : null} + {isError ? : null} + {isSuccess ? ( { onPageChange={onPageChange} searchLinkParams={coreadsParams} /> - )} + ) : null} ); }; diff --git a/src/pages/abs/[id]/references.tsx b/src/pages/abs/[id]/references.tsx index 2d2692147..bfd68620d 100644 --- a/src/pages/abs/[id]/references.tsx +++ b/src/pages/abs/[id]/references.tsx @@ -7,10 +7,16 @@ import { NextPage } from 'next'; import { useRouter } from 'next/router'; import { path } from 'ramda'; import { APP_DEFAULTS } from '@/config'; +import { ItemsSkeleton } from '@/components'; const ReferencesPage: NextPage = () => { const router = useRouter(); - const { data: abstractDoc, error: abstractError } = useGetAbstract({ id: router.query.id as string }); + const { + data: abstractDoc, + error: abstractError, + isLoading: absLoading, + isFetching: absFetching, + } = useGetAbstract({ id: router.query.id as string }); const doc = path(['docs', 0], abstractDoc); const pageIndex = router.query.p ? parseInt(router.query.p as string) - 1 : 0; @@ -18,12 +24,17 @@ const ReferencesPage: NextPage = () => { const { data, isSuccess, + isLoading: refLoading, + isFetching: refFetching, error: referencesError, } = useGetReferences({ ...getParams(), start: pageIndex * APP_DEFAULTS.RESULT_PER_PAGE }, { keepPreviousData: true }); + + const isLoading = refLoading || refFetching || absLoading || absFetching; const referencesParams = getReferencesParams(doc?.bibcode, 0); return ( + {isLoading ? : null} {(abstractError || referencesError) && ( diff --git a/src/pages/abs/[id]/similar.tsx b/src/pages/abs/[id]/similar.tsx index d386ae8f8..26e5d8c53 100644 --- a/src/pages/abs/[id]/similar.tsx +++ b/src/pages/abs/[id]/similar.tsx @@ -1,11 +1,12 @@ import { getSimilarParams, IDocsEntity, useGetAbstract, useGetSimilar } from '@/api'; -import { AbstractRefList } from '@/components'; +import { AbstractRefList, ItemsSkeleton, StandardAlertMessage } from '@/components'; import { AbsLayout } from '@/components/Layout/AbsLayout'; import { useGetAbstractParams } from '@/lib/useGetAbstractParams'; import { NextPage } from 'next'; import { path } from 'ramda'; import { useRouter } from 'next/router'; import { APP_DEFAULTS } from '@/config'; +import { parseAPIError } from '@/utils'; const SimilarPage: NextPage = () => { const router = useRouter(); @@ -14,7 +15,7 @@ const SimilarPage: NextPage = () => { const pageIndex = router.query.p ? parseInt(router.query.p as string) - 1 : 0; const { getParams, onPageChange } = useGetAbstractParams(doc?.bibcode); - const { data, isSuccess } = useGetSimilar( + const { data, isSuccess, isLoading, isFetching, isError, error } = useGetSimilar( { ...getParams(), start: pageIndex * APP_DEFAULTS.RESULT_PER_PAGE }, { keepPreviousData: true }, ); @@ -22,7 +23,9 @@ const SimilarPage: NextPage = () => { return ( - {isSuccess && ( + {isLoading || isFetching ? : null} + {isError ? : null} + {isSuccess ? ( { onPageChange={onPageChange} searchLinkParams={similarParams} /> - )} + ) : null} ); }; diff --git a/src/pages/abs/[id]/toc.tsx b/src/pages/abs/[id]/toc.tsx index 2ba1b7a03..078a7ec33 100644 --- a/src/pages/abs/[id]/toc.tsx +++ b/src/pages/abs/[id]/toc.tsx @@ -6,6 +6,8 @@ import { NextPage } from 'next'; import { useMemo } from 'react'; import { useRouter } from 'next/router'; import { path } from 'ramda'; +import { ItemsSkeleton, StandardAlertMessage } from '@/components'; +import { parseAPIError } from '@/utils'; const VolumePage: NextPage = () => { const router = useRouter(); @@ -14,7 +16,7 @@ const VolumePage: NextPage = () => { const { getParams, onPageChange } = useGetAbstractParams(doc?.bibcode); - const { data, isSuccess } = useGetToc(getParams(), { + const { data, isSuccess, isLoading, isFetching, isError, error } = useGetToc(getParams(), { enabled: !!getParams && !!doc?.bibcode, keepPreviousData: true, }); @@ -27,7 +29,9 @@ const VolumePage: NextPage = () => { return ( - {isSuccess && ( + {isLoading || isFetching ? : null} + {isError ? : null} + {isSuccess ? ( { onPageChange={onPageChange} searchLinkParams={tocParams} /> - )} + ) : null} ); };