Skip to content

[FEAT] : Added Adjustable Vertical Seperator between Editor and ContentViewer #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions app/components/ContentViewer/ContentViewer.module.css
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
.content {
display: flex;
flex-direction: column;

overflow-y: auto;
flex: 1;
padding-right: 14px;
padding-bottom: 12px;
padding-left: 14px;
padding: 14px;
height: 100%;
width: 100%;
}

.contentWrapper {
border-right: 1px solid hsl(var(--border-color));

display: flex;
flex-direction: column;

height: 100%;
flex: 1;
height: 100%;
width: 100%;
overflow: hidden;
}
8 changes: 4 additions & 4 deletions app/components/EditorNOutput/EditorNOutput.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
height: 100%;
display: flex;
flex-direction: column;

max-width: 50%;
width: 100%;
overflow: hidden;
}

.outputWrapper {
width: 100%;

/* padding: 16px; */
display: flex;
flex-direction: column;
align-items: flex-start;
Expand All @@ -19,11 +17,13 @@
border-left: none;
height: 100%;
}

.divider {
width: 100%;
height: 6px;
background-color: hsl(var(--border-color));
cursor: row-resize;
flex-shrink: 0;
}

.divider:hover,
Expand Down
81 changes: 81 additions & 0 deletions app/components/ResizableContent.tsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, we are wrapping the EditorNOutput into this new component. however we are importing the styles from the different component file (i.e. page.module.css) .

move current file into a new folder of the same name, and add the css file in that folder to maintain consistent component declaration

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider moving these changes to the page.tsx file (in the /content/[...markdownPath] folder) if you prefer to not to create a new component

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"use client";

import React, { useState, useRef, useEffect } from "react";
import styles from "@/app/content/[...markdownPath]/page.module.css";
import ContentViewer from "./ContentViewer";
import EditorNOutput from "./EditorNOutput";

interface ResizableContentProps {
content: React.ReactNode;
codeFile: any;
Comment on lines +8 to +10
Copy link
Preview

Copilot AI May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 'any' for the codeFile prop may reduce type safety; specifying a more concrete type could help catch potential issues earlier.

Suggested change
interface ResizableContentProps {
content: React.ReactNode;
codeFile: any;
interface CodeFile {
name: string;
content: string;
}
interface ResizableContentProps {
content: React.ReactNode;
codeFile: CodeFile;

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yashwanth1906 Please implement this

nextStepPath: string | undefined;
stepIndex: number;
chapterIndex: number;
}

export default function ResizableContent({
content,
codeFile,
nextStepPath,
stepIndex,
chapterIndex,
}: ResizableContentProps) {
const [leftWidth, setLeftWidth] = useState(600);
const containerRef = useRef<HTMLDivElement>(null);
const isDraggingRef = useRef<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 newLeftWidth = e.clientX - containerRect.left;

const minWidth = 300;
const maxWidth = containerRect.width * 0.7;

if (newLeftWidth >= minWidth && newLeftWidth <= maxWidth) {
setLeftWidth(newLeftWidth);
localStorage.setItem("horizontalLeftWidth", String(newLeftWidth));
}
};

useEffect(() => {
const savedWidth = localStorage.getItem("horizontalLeftWidth");
if (savedWidth) {
setLeftWidth(Number(savedWidth));
}
}, []);

return (
<div
className={styles.mainArea}
ref={containerRef}
onMouseMove={handleMouseMove}
onMouseUp={handleMouseUp}
onMouseLeave={handleMouseUp}
>
<div className={styles.leftPane} style={{ width: `${leftWidth}px` }}>
<ContentViewer>{content}</ContentViewer>
</div>
<div className={styles.divider} onMouseDown={handleMouseDown} />
<div className={styles.rightPane}>
<EditorNOutput
codeFile={codeFile}
nextStepPath={nextStepPath}
stepIndex={stepIndex}
chapterIndex={chapterIndex}
/>
</div>
</div>
);
}
38 changes: 36 additions & 2 deletions app/content/[...markdownPath]/page.module.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
.mainArea {
display: flex;
flex-direction: row;
flex: 12;
height: calc(100vh - 60px);
width: 100%;
overflow: hidden;
position: relative;
}

.leftPane {
height: 100%;
overflow-y: auto;
overflow: hidden;
min-width: 300px;
max-width: 70%;
display: flex;
}

.rightPane {
flex: 1;
height: 100%;
min-width: 300px;
overflow: hidden;
display: flex;
}

.divider {
width: 4px;
height: 100%;
background-color: hsl(var(--border-color));
cursor: col-resize;
transition: background-color 0.2s ease;
flex-shrink: 0;
}

.divider:hover {
background-color: hsl(var(--primary) / 0.75);
}

.divider:active {
background-color: hsl(var(--primary) / 0.75);
}
28 changes: 13 additions & 15 deletions app/content/[...markdownPath]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { contentManager } from "@/lib/contentManager";
import styles from "./page.module.css";
import React from "react";
import { parseLessonFolder } from "@/lib/server-functions";
import ContentViewer from "@/app/components/ContentViewer";
import EditorNOutput from "@/app/components/EditorNOutput";
import ResizableContent from "@/app/components/ResizableContent";

export function generateMetadata({
params,
Expand Down Expand Up @@ -38,28 +36,28 @@ export default async function Content({
contentManager.getPageMeta(urlPath);
const { Page, metadata, codeFile } = parseLessonFolder(mdPath, codePath);

const pageContent = <Page />;

return (
<div className={styles.mainArea}>
<ContentViewer>
<Page />
</ContentViewer>
<EditorNOutput
codeFile={codeFile}
nextStepPath={nextStepPath}
stepIndex={stepIndex}
chapterIndex={chapterIndex}
/>
</div>
<ResizableContent
content={pageContent}
codeFile={codeFile}
nextStepPath={nextStepPath}
stepIndex={stepIndex}
chapterIndex={chapterIndex}
/>
);
}

export async function generateStaticParams() {
const outline = contentManager.getOutline();
const pathList: { markdownPath: string[] }[] = [];

outline.map((item) => {
item.steps.map((step) => {
const pathSegments = step.fullPath.split("/");
pathList.push({
markdownPath: [item.folderName, step.fileName],
markdownPath: pathSegments,
});
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these changes relevant to the issue? Please remove these changes,

Expand Down