Skip to content

Commit

Permalink
Find step index in list instead of relying on seqno as it can be nega…
Browse files Browse the repository at this point in the history
…tive
  • Loading branch information
MaPoKen committed Jan 29, 2025
1 parent 41c7cf9 commit 1532fd7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/components/Learningpath/Learningpath.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ const Learningpath = ({
const [accordionValue, setAccordionValue] = useState<string[]>();
const accordionRef = useRef<HTMLDivElement>(null);

const previousStep = learningpath.learningsteps[learningpathStep.seqNo - 1];
const nextStep = learningpath.learningsteps[learningpathStep.seqNo + 1];
const index = learningpath.learningsteps.findIndex((step) => step.id === learningpathStep.id);
const previousStep = learningpath.learningsteps[index - 1];
const nextStep = learningpath.learningsteps[index + 1];

const menu = useMemo(
() => (
Expand Down
5 changes: 3 additions & 2 deletions src/components/Learningpath/LearningpathMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ const LearningpathMenu = ({ resourcePath, learningpath, currentStep, context }:
const [viewedSteps, setViewedSteps] = useState<Record<string, boolean>>({});
const { t } = useTranslation();

const currentIndex = learningpath.learningsteps.findIndex((step) => step.id === currentStep.id);
const lastUpdatedDate = new Date(learningpath.lastUpdated);

const lastUpdatedString = `${lastUpdatedDate.getDate()}.${lastUpdatedDate.getMonth() + 1 < 10 ? "0" : ""}${
Expand Down Expand Up @@ -206,7 +207,7 @@ const LearningpathMenu = ({ resourcePath, learningpath, currentStep, context }:
? routes.myNdla.learningpathPreview(learningpath.id, step.id)
: toLearningPath(learningpath.id, step.id, resourcePath)
}
aria-current={index === currentStep.seqNo ? "page" : undefined}
aria-current={index === currentIndex ? "page" : undefined}
data-last={index === learningpath.learningsteps.length - 1}
aria-label={`${step.title}${viewedSteps[step.id] ? `. ${t("learningpathPage.stepCompleted")}` : ""}`}
>
Expand All @@ -217,7 +218,7 @@ const LearningpathMenu = ({ resourcePath, learningpath, currentStep, context }:
aria-hidden
context={context}
>
{viewedSteps[step.id] && index !== currentStep.seqNo ? <CheckLine size="small" /> : index + 1}
{viewedSteps[step.id] && index !== currentIndex ? <CheckLine size="small" /> : index + 1}
</StepIndicator>
</StepIndicatorWrapper>
<span data-link-text="">{step.title}</span>
Expand Down
1 change: 0 additions & 1 deletion src/containers/MyNdla/Learningpath/NewLearningpathPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const NewLearningpathPage = () => {
params: {
language: i18n.language,
coverPhotoMetaUrl: imageUrl,
description: "",
title: title,
copyright: {
license: {
Expand Down

0 comments on commit 1532fd7

Please sign in to comment.