Skip to content

Commit

Permalink
Simplify with Katrine comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MaPoKen committed Jan 31, 2025
1 parent 23d0ac2 commit 1c73441
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/components/Learningpath/Learningpath.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ const Learningpath = ({
<LearningpathMenu
resourcePath={resourcePath}
learningpath={learningpath}
currentStep={learningpathStep}
currentIndex={index}
context={context}
/>
),
[context, learningpath, learningpathStep, resourcePath],
[context, index, learningpath, resourcePath],
);
const parents = resource?.context?.parents || [];
const root = parents[0];
Expand Down
14 changes: 6 additions & 8 deletions src/components/Learningpath/LearningpathMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ import { SafeLink } from "@ndla/safelink";
import { styled } from "@ndla/styled-system/jsx";
import { ArticleByline } from "@ndla/ui";
import { LearningpathContext } from "./learningpathUtils";
import {
GQLLearningpathMenu_LearningpathFragment,
GQLLearningpathMenu_LearningpathStepFragment,
} from "../../graphqlTypes";
import { GQLLearningpathMenu_LearningpathFragment } from "../../graphqlTypes";
import { routes, toLearningPath } from "../../routeHelpers";

interface Props {
resourcePath: string | undefined;
learningpath: GQLLearningpathMenu_LearningpathFragment;
currentStep: GQLLearningpathMenu_LearningpathStepFragment;
currentIndex: number;
context?: LearningpathContext;
}

Expand Down Expand Up @@ -167,11 +164,11 @@ const ListItem = styled("li", {

const LEARNING_PATHS_STORAGE_KEY = "LEARNING_PATHS_COOKIES_KEY";

const LearningpathMenu = ({ resourcePath, learningpath, currentStep, context }: Props) => {
const LearningpathMenu = ({ resourcePath, learningpath, currentIndex, context }: Props) => {
const [viewedSteps, setViewedSteps] = useState<Record<string, boolean>>({});
const { t } = useTranslation();

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

const lastUpdatedString = `${lastUpdatedDate.getDate()}.${lastUpdatedDate.getMonth() + 1 < 10 ? "0" : ""}${
Expand All @@ -192,7 +189,7 @@ const LearningpathMenu = ({ resourcePath, learningpath, currentStep, context }:
useEffect(() => {
updateViewedSteps();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentStep.id]);
}, [currentStep?.id]);

return (
<>
Expand Down Expand Up @@ -254,6 +251,7 @@ LearningpathMenu.fragments = {
learningsteps {
id
title
seqNo
}
}
`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import { Heading } from "@ndla/primitives";
import { ArticleWrapper, ArticleContent, ArticleHeader, LicenseLink } from "@ndla/ui";
import { BaseStepProps, EmbedPageContent } from "./LearningpathStep";

interface DescriptionStepProps extends BaseStepProps {}

export const LearningpathStepTitle = ({ learningpathStep, skipToContentId }: DescriptionStepProps) => {
export const LearningpathStepTitle = ({ learningpathStep, skipToContentId }: BaseStepProps) => {
const { i18n } = useTranslation();
return learningpathStep.showTitle || learningpathStep.description ? (
<EmbedPageContent variant="content">
Expand Down
2 changes: 1 addition & 1 deletion src/graphqlTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2659,7 +2659,7 @@ export type GQLLearningpathMenu_LearningpathFragment = {
license: { __typename?: "License"; license: string };
contributors: Array<{ __typename?: "Contributor"; type: string; name: string }>;
};
learningsteps: Array<{ __typename?: "LearningpathStep"; id: number; title: string }>;
learningsteps: Array<{ __typename?: "LearningpathStep"; id: number; title: string; seqNo: number }>;
};

export type GQLLearningpathMenu_LearningpathStepFragment = {
Expand Down

0 comments on commit 1c73441

Please sign in to comment.