Skip to content

Commit

Permalink
fix: broken link on tutorial previous button (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
fpasquet committed Apr 25, 2024
1 parent 52525ed commit f4e332b
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -13,9 +13,10 @@ export const useTutorialPageContainer = (tutorial: TutorialPageData): PostPagePr
const postPageProps = usePostPage(tutorial);
const { slug, step: currentStep } = useParams<{ slug: string; step: string }>();

const firstStep = tutorial.steps[0];
const [currentTutorialStepIndex, currentTutorialStep] = Object.entries(tutorial.steps).find(
([, step]) => step.slug === currentStep
) ?? [0, tutorial.steps[0]];
) ?? [0, firstStep];
const previousStep = tutorial.steps[Number(currentTutorialStepIndex) - 1];
const nextStep = tutorial.steps[Number(currentTutorialStepIndex) + 1];

Expand All @@ -29,7 +30,7 @@ export const useTutorialPageContainer = (tutorial: TutorialPageData): PostPagePr
label: step.title,
href: generatePath(PATHS.POST, { lang: i18n.language, slug, step: index > 0 ? step.slug : undefined }),
})),
sectionActive: currentTutorialStep?.slug ?? tutorial.steps[0].slug,
sectionActive: currentTutorialStep?.slug ?? firstStep.slug,
},
children: <Box dangerouslySetInnerHTML={{ __html: currentTutorialStep?.content ?? tutorial.steps[0].content }} />,
previousLink: previousStep
Expand All @@ -38,7 +39,7 @@ export const useTutorialPageContainer = (tutorial: TutorialPageData): PostPagePr
href: generatePath(PATHS.POST, {
lang: i18n.language,
slug,
step: previousStep.slug === 'introduction' ? '' : previousStep.slug,
step: previousStep.slug !== firstStep.slug ? previousStep.slug : undefined,
}),
}
: undefined,
Expand Down

0 comments on commit f4e332b

Please sign in to comment.