Skip to content

Commit

Permalink
chore: add view solution button
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelRajodiya committed Jul 6, 2024
1 parent 009aa50 commit 22520bc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
6 changes: 5 additions & 1 deletion app/components/EditorNOutput/EditorNOutput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export default function EditorNOutput({
JSON.stringify(codeFile.code, null, 2)
);

const showSolution = () => {
setCodeString(JSON.stringify(codeFile.solution, null, 2));
};

const [output, dispatchOutput] = useReducer(outputReducer, {
validityStatus: "neutral",
errors: "",
Expand Down Expand Up @@ -93,7 +97,7 @@ export default function EditorNOutput({
className={styles.outputWrapper}
style={{ height: `calc(100% - ${topWidth}px - 6px)` }}
>
<Output outputResult={output} />
<Output outputResult={output} showSolution={showSolution} />
</div>
</div>
);
Expand Down
7 changes: 7 additions & 0 deletions app/components/Output/Output.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
overflow-y: scroll;
height: 100%;
white-space: pre-wrap;
display: flex;
flex-direction: column;
}
.valid {
display: flex;
Expand All @@ -59,3 +61,8 @@
display: flex;
justify-content: center;
}
.footer {
margin-top: auto;
font-size: small;
padding: 0.2em 0.2em;
}
32 changes: 28 additions & 4 deletions app/components/Output/Output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ import SmallBtn from "../SmallBtn/SmallBtn";
import { InvalidSchemaError } from "@hyperjump/json-schema/draft-2020-12";
import { schemaUrl } from "@/lib/validators";

function Output({ outputResult }: { outputResult: OutputResult }) {
function Output({
outputResult,
showSolution,
}: {
outputResult: OutputResult;
showSolution: () => void;
}) {
let outputBodyContent;

if (outputResult.validityStatus == "neutral") {
outputBodyContent = (
<>
<div>
{" "}
Please click the{" "}
<SmallBtn variant="default" onClick={() => {}}>
validate
</SmallBtn>{" "}
button to see the output
</>
</div>
);
} else if (outputResult.validityStatus == "valid") {
outputBodyContent = (
Expand Down Expand Up @@ -62,7 +68,25 @@ function Output({ outputResult }: { outputResult: OutputResult }) {
<div className={styles.header}>
<div className={styles.title}>Output </div>
</div>
<div className={classnames(styles.outputBody)}>{outputBodyContent}</div>

<div className={classnames(styles.outputBody)}>
{outputBodyContent}
{outputResult.validityStatus !== "neutral" &&
outputResult.validityStatus !== "valid" && (
<div className={styles.footer}>
Stuck?{" "}
<button
onClick={showSolution}
style={{
color: "hsl(var(--link-color))",
textDecoration: "underline",
}}
>
View Solution
</button>
</div>
)}
</div>
</>
);
}
Expand Down

0 comments on commit 22520bc

Please sign in to comment.