-
-
Notifications
You must be signed in to change notification settings - Fork 45
[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
base: main
Are you sure you want to change the base?
Changes from all commits
240ca79
a6404b8
68ffd14
81b68f6
44a131b
8f4819c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
.mainArea { | ||
display: flex; | ||
flex-direction: row; | ||
height: 100vh; | ||
width: 100%; | ||
overflow: hidden; | ||
position: relative; | ||
} | ||
|
||
.leftPane { | ||
height: 100%; | ||
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) / 0.5); | ||
cursor: col-resize; | ||
transition: all 0.2s ease; | ||
flex-shrink: 0; | ||
user-select: none; | ||
-webkit-user-select: none; | ||
position: relative; | ||
border-left: 1px solid hsl(var(--border-color)); | ||
border-right: 1px solid hsl(var(--border-color)); | ||
} | ||
|
||
.divider::after { | ||
content: ''; | ||
position: absolute; | ||
top: 0; | ||
left: 50%; | ||
transform: translateX(-50%); | ||
width: 2px; | ||
height: 100%; | ||
background-color: hsl(var(--primary) / 0.3); | ||
opacity: 0; | ||
transition: opacity 0.2s ease; | ||
} | ||
|
||
.divider:hover::after, | ||
.divider:active::after { | ||
opacity: 1; | ||
background-color: hsl(var(--primary) / 0.5); | ||
} | ||
|
||
.divider:hover, | ||
.divider:active { | ||
background-color: hsl(var(--primary) / 0.2); | ||
border-left: 1px solid hsl(var(--primary) / 0.4); | ||
border-right: 1px solid hsl(var(--primary) / 0.4); | ||
} | ||
|
||
.mainArea ::-webkit-scrollbar { | ||
width: 8px; | ||
height: 8px; | ||
} | ||
|
||
.mainArea ::-webkit-scrollbar-track { | ||
background: hsl(var(--background)); | ||
} | ||
|
||
.mainArea ::-webkit-scrollbar-thumb { | ||
background: hsl(var(--border-color)); | ||
border-radius: 4px; | ||
} | ||
|
||
.mainArea ::-webkit-scrollbar-thumb:hover { | ||
background: hsl(var(--primary) / 0.5); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,88 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
"use client"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
import React, { useState, useRef, useEffect } from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
import styles from "./ResizableContent.module.css"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
import ContentViewer from "../ContentViewer"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
import EditorNOutput from "../EditorNOutput"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
import { CodeFile } from "@/lib/types"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
interface ResizableContentProps { | ||||||||||||||||||||||||||||||||||||||||||||||||||
content: React.ReactNode; | ||||||||||||||||||||||||||||||||||||||||||||||||||
codeFile: CodeFile; | ||||||||||||||||||||||||||||||||||||||||||||||||||
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)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Writing to localStorage on every mouse move during dragging can cause performance issues. Consider using a debounced approach or only saving the value when dragging ends.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
const savedWidth = localStorage.getItem("horizontalLeftWidth"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
if (savedWidth) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
setLeftWidth(Number(savedWidth)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+49
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accessing localStorage should be wrapped in a try-catch block as it can throw exceptions in private browsing mode or when storage is disabled.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, []); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
<div | ||||||||||||||||||||||||||||||||||||||||||||||||||
className={styles.mainArea} | ||||||||||||||||||||||||||||||||||||||||||||||||||
ref={containerRef} | ||||||||||||||||||||||||||||||||||||||||||||||||||
onMouseMove={handleMouseMove} | ||||||||||||||||||||||||||||||||||||||||||||||||||
onMouseUp={handleMouseUp} | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+64
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The onMouseMove handler will fire continuously even when not dragging, causing unnecessary function calls. Consider adding global mouse event listeners only during drag operations to improve performance.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||||||||||||||||
onMouseLeave={handleMouseUp} | ||||||||||||||||||||||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<div className={styles.leftPane} style={{ width: `${leftWidth}px` }}> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<ContentViewer>{content}</ContentViewer> | ||||||||||||||||||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<div | ||||||||||||||||||||||||||||||||||||||||||||||||||
className={styles.divider} | ||||||||||||||||||||||||||||||||||||||||||||||||||
onMouseDown={handleMouseDown} | ||||||||||||||||||||||||||||||||||||||||||||||||||
role="separator" | ||||||||||||||||||||||||||||||||||||||||||||||||||
aria-orientation="vertical" | ||||||||||||||||||||||||||||||||||||||||||||||||||
aria-label="Resize content" | ||||||||||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<div className={styles.rightPane}> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<EditorNOutput | ||||||||||||||||||||||||||||||||||||||||||||||||||
codeFile={codeFile} | ||||||||||||||||||||||||||||||||||||||||||||||||||
nextStepPath={nextStepPath} | ||||||||||||||||||||||||||||||||||||||||||||||||||
stepIndex={stepIndex} | ||||||||||||||||||||||||||||||||||||||||||||||||||
chapterIndex={chapterIndex} | ||||||||||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||
} |
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); | ||
} |
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/ResizableContent"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The title and description contain a spelling error: 'Seperator' should be 'Separator'. This same error appears in the import path - consider renaming the component to 'ResizableSeparator' or similar to match the corrected spelling.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
export function generateMetadata({ | ||||||
params, | ||||||
|
@@ -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, | ||||||
}); | ||||||
}); | ||||||
}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are these changes relevant to the issue? Please remove these changes, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yashwanth1906 Please reply here |
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the non-null assertion operator (!) without proper null checking is risky. The containerRef.current could be null if the component unmounts during dragging. Add a null check:
if (!containerRef.current) return;
Copilot uses AI. Check for mistakes.