Skip to content

Commit

Permalink
Merge branch 'lesson-page'
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelRajodiya committed Jul 6, 2024
2 parents b887bd5 + 5219f6a commit 2f9828f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 16 deletions.
21 changes: 20 additions & 1 deletion app/components/EditorNOutput/EditorNOutput.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
height: 100%;
display: flex;
flex-direction: column;
gap: 4px;

max-width: 50%;
}

.outputWrapper {
width: 100%;

/* padding: 16px; */
display: flex;
flex-direction: column;
align-items: flex-start;
border: 1px solid hsl(var(--border-color));
overflow-y: hidden;
border-left: none;
height: 100%;
}
.divider {
width: 100%;
height: 6px;
background-color: hsl(var(--border-color));
cursor: row-resize;
}
58 changes: 53 additions & 5 deletions app/components/EditorNOutput/EditorNOutput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import React, { useState, useReducer } from "react";
import React, { useState, useReducer, useRef } from "react";
import CodeEditor from "../CodeEditor";
import styles from "./EditorNOutput.module.css";
import { Box } from "@chakra-ui/react";
Expand All @@ -24,10 +24,49 @@ export default function EditorNOutput({
errors: "",
testCaseResults: [],
});
const [topWidth, setTopWidth] = useState(400); // Initial width of the left div
const dividerRef = useRef<HTMLDivElement>(null);

const containerRef = useRef<HTMLDivElement>(null);
const isDraggingRef = useRef<HTMLDivElement | boolean>(false);

const handleMouseDown = () => {
isDraggingRef.current = true;
};

const handleMouseUp = () => {
isDraggingRef.current = false;
};

const handleMouseMove = (
e: React.MouseEvent<HTMLDivElement, MouseEvent> | MouseEvent
) => {
if (!isDraggingRef.current) return;

const containerRect = containerRef.current!.getBoundingClientRect();
const newTopWidth = e.clientY - containerRect.top;

if (newTopWidth > 32) {
setTopWidth(newTopWidth);
} else {
setTopWidth(containerRect.top);
}
};

return (
<div className={styles.codeEditorNOutput}>
<Box flex={6} position={"relative"}>
<div
className={styles.codeEditorNOutput}
onMouseMove={handleMouseMove}
onMouseUp={handleMouseUp}
onMouseLeave={handleMouseUp}
ref={containerRef}
>
<Box
flex={6}
height={`${topWidth}px`}
position={"relative"}
className="top"
>
<CodeEditor
codeString={codeString}
setCodeString={setCodeString}
Expand All @@ -36,8 +75,17 @@ export default function EditorNOutput({
nextStepPath={nextStepPath}
/>
</Box>

<Output outputResult={output} flex={4} />
<div
ref={dividerRef}
className={styles.divider}
onMouseDown={handleMouseDown}
></div>
<div
className={styles.outputWrapper}
style={{ height: `calc(100% - ${topWidth}px - 6px)` }}
>
<Output outputResult={output} />
</div>
</div>
);
}
4 changes: 3 additions & 1 deletion app/components/Output/Output.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
border: 1px solid hsl(var(--border-color));
overflow-y: hidden;
border-left: none;
height: 100%;
}

.title {
font-size: small;
padding: 0.5em 1em;
padding: 0.2em 1em;
}

.header {
Expand All @@ -22,6 +23,7 @@
display: flex;
flex-direction: row;
justify-content: space-between;
user-select: none;
}
.invalid {
color: red;
Expand Down
12 changes: 3 additions & 9 deletions app/components/Output/Output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ import SmallBtn from "../SmallBtn/SmallBtn";
import { InvalidSchemaError } from "@hyperjump/json-schema/draft-2020-12";
import { schemaUrl } from "@/lib/validators";

function Output({
outputResult,
flex,
}: {
outputResult: OutputResult;
flex: number;
}) {
function Output({ outputResult }: { outputResult: OutputResult }) {
let outputBodyContent;

if (outputResult.validityStatus == "neutral") {
Expand Down Expand Up @@ -64,12 +58,12 @@ function Output({
}

return (
<div className={classnames(styles.output)} style={{ flex: flex }}>
<>
<div className={styles.header}>
<div className={styles.title}>Output </div>
</div>
<div className={classnames(styles.outputBody)}>{outputBodyContent}</div>
</div>
</>
);
}

Expand Down

0 comments on commit 2f9828f

Please sign in to comment.