Skip to content

Commit d1b03b1

Browse files
committed
add aditional check to validate that current lesson is last lesson
1 parent 3673524 commit d1b03b1

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

app/components/CodeEditor/CodeEditor.tsx

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import Editor, { Monaco } from "@monaco-editor/react";
77
import { Flex, useColorMode } from "@chakra-ui/react";
88
import { useEffect, useState, useRef } from "react";
99
import MyBtn from "../MyBtn";
10-
import { tryFormattingCode, validateCode } from "@/lib/client-functions";
10+
import {
11+
isTheTourCompleted,
12+
tryFormattingCode,
13+
validateCode,
14+
} from "@/lib/client-functions";
1115
import FiChevronRight from "@/app/styles/icons/HiChevronRightGreen";
1216
import { useRouter } from "next/navigation";
1317
import { useUserSolutionStore, useEditorStore } from "@/lib/stores";
@@ -109,6 +113,11 @@ const EditorControls = ({
109113
outputResult: OutputResult;
110114
}) => {
111115
const router = useRouter();
116+
const [isTheTourCompletedState, setIsTheTourCompletedState] =
117+
useState(isTheTourCompleted());
118+
useEffect(() => {
119+
setIsTheTourCompletedState(isTheTourCompleted());
120+
}, [isTheTourCompleted()]);
112121

113122
return (
114123
<div className={styles.buttonsWrapper}>
@@ -128,27 +137,27 @@ const EditorControls = ({
128137
Reset
129138
</MyBtn>
130139
</Flex>
131-
{nextStepPath ? (
140+
{!nextStepPath || isTheTourCompletedState ? (
132141
<>
133-
<MyBtn
134-
onClick={() => router.push("/" + nextStepPath)}
135-
variant={
136-
outputResult.validityStatus === "valid" ? "default" : "success"
137-
}
138-
size={outputResult.validityStatus === "valid" ? "sm" : "xs"}
139-
>
140-
Next <span style={{ marginLeft: "4px" }}></span>
141-
<FiChevronRight
142-
color={
143-
outputResult.validityStatus === "valid"
144-
? "white"
145-
: "hsl(var(--success))"
146-
}
147-
/>
148-
</MyBtn>
142+
<CertificateButton />
149143
</>
150144
) : (
151-
<CertificateButton />
145+
<MyBtn
146+
onClick={() => router.push("/" + nextStepPath)}
147+
variant={
148+
outputResult.validityStatus === "valid" ? "default" : "success"
149+
}
150+
size={outputResult.validityStatus === "valid" ? "sm" : "xs"}
151+
>
152+
Next <span style={{ marginLeft: "4px" }}></span>
153+
<FiChevronRight
154+
color={
155+
outputResult.validityStatus === "valid"
156+
? "white"
157+
: "hsl(var(--success))"
158+
}
159+
/>
160+
</MyBtn>
152161
)}
153162
</div>
154163
);

0 commit comments

Comments
 (0)