Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: broken link on tutorial previous button #1119

Merged
merged 1 commit into from Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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