Skip to content

Commit

Permalink
fix: Fixed typecheeck errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei committed Jan 16, 2024
1 parent dacad10 commit 2370fd2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/components/Component/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,22 @@ export const Component: React.FC<ComponentProps> = ({
);

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;
return currentSection.subSections[nextIndex];
}, [currentIndex, currentSection]);

const prevSection = useMemo(() => {
if (!currentSection) {
if (!currentSection || !currentSection.subSections || !currentIndex) {
return null;
}
const prevIndex =
Expand All @@ -116,11 +116,17 @@ export const Component: React.FC<ComponentProps> = ({
}, []);

const onNextHandler = () => {
if (!nextSection) {
return;
}
router.push(nextSection.url);
scrollTop();
};

const onPrevHandler = () => {
if (!prevSection) {
return;
}
router.push(prevSection.url);
scrollTop();
};
Expand Down Expand Up @@ -199,7 +205,7 @@ export const Component: React.FC<ComponentProps> = ({
rewriteLinks={rewriteLinks}
withComponents
/>
{typeof window !== 'undefined' ? (
{typeof window !== 'undefined' && prevSection && nextSection ? (
<div className={b('navigation')}>
<ArticleNavigations
prevHandler={onPrevHandler}
Expand Down
16 changes: 11 additions & 5 deletions src/pages/design/[sectionId]/[articleId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@ export const ArticlePage = ({sectionId, articleId}: {sectionId: string; articleI
);

const currentIndex = useMemo(() => {
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;
return currentSection.subSections[nextIndex];
}, [currentIndex, currentSection]);

const prevSection = useMemo(() => {
if (!currentSection) {
if (!currentSection || !currentSection.subSections || !currentIndex) {
return null;
}
const prevIndex =
Expand All @@ -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();
};
Expand All @@ -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 : ''}
/>
</DesignLayout>
</Layout>
Expand Down

0 comments on commit 2370fd2

Please sign in to comment.