From 2370fd2d6640b7c1afc9d2e89ba9f4e4def89831 Mon Sep 17 00:00:00 2001 From: Aleksei Date: Tue, 16 Jan 2024 16:55:31 +0300 Subject: [PATCH] fix: Fixed typecheeck errors --- src/components/Component/Component.tsx | 14 ++++++++++---- src/pages/design/[sectionId]/[articleId].tsx | 16 +++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/components/Component/Component.tsx b/src/components/Component/Component.tsx index 5b66a0b4bd15..226650637888 100644 --- a/src/components/Component/Component.tsx +++ b/src/components/Component/Component.tsx @@ -81,14 +81,14 @@ export const Component: React.FC = ({ ); const currentIndex = useMemo(() => { - if (!currentSection) { + if (!currentSection || !currentSection.subSections || !currentIndex) { return null; } return currentSection.subSections.findIndex((item) => item.id === component.id); }, [currentSection, component.id]); const nextSection = useMemo(() => { - if (!currentSection) { + if (!currentSection || !currentSection.subSections || !currentIndex) { return null; } const nextIndex = (currentIndex + 1) % currentSection.subSections.length; @@ -96,7 +96,7 @@ export const Component: React.FC = ({ }, [currentIndex, currentSection]); const prevSection = useMemo(() => { - if (!currentSection) { + if (!currentSection || !currentSection.subSections || !currentIndex) { return null; } const prevIndex = @@ -116,11 +116,17 @@ export const Component: React.FC = ({ }, []); const onNextHandler = () => { + if (!nextSection) { + return; + } router.push(nextSection.url); scrollTop(); }; const onPrevHandler = () => { + if (!prevSection) { + return; + } router.push(prevSection.url); scrollTop(); }; @@ -199,7 +205,7 @@ export const Component: React.FC = ({ rewriteLinks={rewriteLinks} withComponents /> - {typeof window !== 'undefined' ? ( + {typeof window !== 'undefined' && prevSection && nextSection ? (
{ - if (!currentSection) { + if (!currentSection || !currentSection.subSections) { return null; } return currentSection.subSections.findIndex((item) => item.id === articleId); }, [currentSection, articleId]); const nextSection = useMemo(() => { - if (!currentSection) { + if (!currentSection || !currentSection.subSections || !currentIndex) { return null; } const nextIndex = (currentIndex + 1) % currentSection.subSections.length; @@ -75,7 +75,7 @@ export const ArticlePage = ({sectionId, articleId}: {sectionId: string; articleI }, [currentIndex, currentSection]); const prevSection = useMemo(() => { - if (!currentSection) { + if (!currentSection || !currentSection.subSections || !currentIndex) { return null; } const prevIndex = @@ -95,11 +95,17 @@ export const ArticlePage = ({sectionId, articleId}: {sectionId: string; articleI }, []); const onNextHandler = () => { + if (!nextSection) { + return; + } router.push(nextSection.url); scrollTop(); }; const onPrevHandler = () => { + if (!prevSection) { + return; + } router.push(prevSection.url); scrollTop(); }; @@ -112,8 +118,8 @@ export const ArticlePage = ({sectionId, articleId}: {sectionId: string; articleI articleId={articleId} prevHandler={onPrevHandler} nextHandler={onNextHandler} - previousTitle={prevSection.title} - nextTitle={nextSection.title} + previousTitle={prevSection ? prevSection.title : ''} + nextTitle={nextSection ? nextSection.title : ''} />