-
-
Notifications
You must be signed in to change notification settings - Fork 43
FEAT: Added tabs to easily navigate between description and solution #177
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
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ import { Box } from "@chakra-ui/react"; | |
import Output from "../Output"; | ||
import { CodeFile } from "@/lib/types"; | ||
import { outputReducer } from "@/lib/reducers"; | ||
import { useUserSolutionStore } from "@/lib/stores"; | ||
|
||
export default function EditorNOutput({ | ||
codeFile, | ||
|
@@ -19,9 +20,7 @@ export default function EditorNOutput({ | |
stepIndex: number; | ||
chapterIndex: number; | ||
}) { | ||
const [codeString, setCodeString] = useState( | ||
JSON.stringify(codeFile.code, null, 2), | ||
); | ||
const { setCodeString, codeString } = useUserSolutionStore(); | ||
|
||
const showSolution = () => { | ||
setCodeString(JSON.stringify(codeFile.solution, null, 2)); | ||
|
@@ -64,6 +63,9 @@ export default function EditorNOutput({ | |
}; | ||
|
||
useEffect(() => { | ||
// Load the initial code | ||
setCodeString(JSON.stringify(codeFile.code, null, 2)); | ||
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. Include Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
|
||
const topHeight = localStorage.getItem("verticalTopHeight"); | ||
if (topHeight) { | ||
setTopWidth(Number(topHeight)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,15 @@ export default function MyBtn({ | |
isDisabled, | ||
tooltip, | ||
size = "xs", | ||
position = "right", | ||
}: { | ||
children: React.ReactNode; | ||
variant: "success" | "error" | "default"; | ||
onClick: () => void; | ||
isDisabled?: boolean; | ||
tooltip?: string; | ||
size?: "xs" | "sm" | "md" | "lg"; | ||
position?: "left" | "right"; | ||
}) { | ||
return ( | ||
<Tooltip label={tooltip} aria-label={tooltip} placement="top"> | ||
|
@@ -31,6 +33,7 @@ export default function MyBtn({ | |
textTransform={"uppercase"} | ||
isDisabled={isDisabled} | ||
fontWeight={"bold"} | ||
style={{float: position}} | ||
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. Using inline Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
> | ||
{children} | ||
</Button> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.container { | ||
height: 70vh; | ||
width: 100%; | ||
border: 1px solid #ccc; | ||
margin-bottom: 16px; | ||
padding: 16px 10px; | ||
box-sizing: border-box; | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"use client"; | ||
|
||
import Editor, { Monaco } from "@monaco-editor/react"; | ||
import { useColorMode } from "@chakra-ui/react"; | ||
import { useEffect, useState } from "react"; | ||
import { useUserSolutionStore } from "@/lib/stores"; | ||
import styles from "./SolutionTab.module.css"; | ||
import MyBtn from "../MyBtn/MyBtn"; | ||
|
||
type SolutionTabProps = { | ||
solution: string; | ||
}; | ||
|
||
const useEditorTheme = (monaco: Monaco, colorMode: "dark" | "light") => { | ||
useEffect(() => { | ||
if (monaco) { | ||
monaco.editor.defineTheme("my-theme", { | ||
base: "vs-dark", | ||
inherit: true, | ||
rules: [], | ||
colors: { | ||
"editor.background": "#1f1f1f", | ||
}, | ||
}); | ||
monaco.editor.setTheme(colorMode === "light" ? "light" : "my-theme"); | ||
} | ||
}, [monaco, colorMode]); | ||
}; | ||
|
||
const SolutionTab = ({ solution }: SolutionTabProps) => { | ||
const { colorMode } = useColorMode(); | ||
const [monaco, setMonaco] = useState<any>(null); | ||
|
||
const { setCodeString } = useUserSolutionStore(); | ||
|
||
function useSolution() { | ||
setCodeString(solution); | ||
} | ||
|
||
// Apply custom hooks | ||
useEditorTheme(monaco, colorMode); | ||
return ( | ||
<div className={styles.container}> | ||
<Editor | ||
language="json" | ||
theme={colorMode === "light" ? "light" : "my-theme"} | ||
value={String(solution)} | ||
height="90%" | ||
options={{ | ||
minimap: { enabled: false }, | ||
fontSize: 14, | ||
}} | ||
// dont allow to edit the solution | ||
onMount={(editor, monacoInstance) => { | ||
setMonaco(monacoInstance); | ||
editor.updateOptions({ readOnly: true }); | ||
}} | ||
/> | ||
<MyBtn onClick={useSolution} variant={"default"} size="sm" position="right"> | ||
Use this solution | ||
</MyBtn> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SolutionTab; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as default } from "./SolutionTab"; |
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. Can we just use the chakraUI tabs instead (of course with customized styles) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
.wrapper { | ||
width: 100%; | ||
padding: 12px 16px; | ||
position: fixed; | ||
top: 40px; | ||
margin: 12px 0; | ||
} | ||
|
||
.tabContainer { | ||
display: flex; | ||
gap: 1.5rem; | ||
font-size: 0.875rem; | ||
font-weight: 500; | ||
position: relative; | ||
color: hsl(var(--text)); | ||
} | ||
|
||
.tabButton { | ||
position: relative; | ||
padding-bottom: 8px; | ||
background: none; | ||
font-size: 16px; | ||
border: none; | ||
cursor: pointer; | ||
font-family: Verdana, Geneva, Tahoma, sans-serif; | ||
color: hsl(var(--text)); | ||
} | ||
|
||
.activeTab { | ||
color: hsl(var(--text)); | ||
} | ||
|
||
.underline { | ||
position: absolute; | ||
bottom: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 2px; | ||
background-color:hsl(var(--text)); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||||||||||||||||||||||||||
"use client"; | ||||||||||||||||||||||||||||||
import styles from "./TabHeader.module.css"; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
type TabHeaderProps = { | ||||||||||||||||||||||||||||||
currentSelectedTab: "description" | "solution"; | ||||||||||||||||||||||||||||||
setCurrentSelectedTab: (tab: "description" | "solution") => void; | ||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const TabHeader = ({ | ||||||||||||||||||||||||||||||
currentSelectedTab, | ||||||||||||||||||||||||||||||
setCurrentSelectedTab, | ||||||||||||||||||||||||||||||
}: TabHeaderProps & { | ||||||||||||||||||||||||||||||
currentSelectedTab: "description" | "solution"; | ||||||||||||||||||||||||||||||
setCurrentSelectedTab: (tab: "description" | "solution") => void; | ||||||||||||||||||||||||||||||
}) => { | ||||||||||||||||||||||||||||||
Comment on lines
+12
to
+15
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 inline intersection with
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||
<div className={styles.wrapper}> | ||||||||||||||||||||||||||||||
<div className={styles.tabContainer}> | ||||||||||||||||||||||||||||||
<button | ||||||||||||||||||||||||||||||
onClick={() => setCurrentSelectedTab("description")} | ||||||||||||||||||||||||||||||
className={`${styles.tabButton} ${ | ||||||||||||||||||||||||||||||
currentSelectedTab === "description" ? styles.activeTab : "" | ||||||||||||||||||||||||||||||
}`} | ||||||||||||||||||||||||||||||
Comment on lines
+19
to
+24
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. Consider adding ARIA roles (e.g.,
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||
Description | ||||||||||||||||||||||||||||||
{currentSelectedTab === "description" && ( | ||||||||||||||||||||||||||||||
<div className={styles.underline} /> | ||||||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||||||
</button> | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
<button | ||||||||||||||||||||||||||||||
onClick={() => setCurrentSelectedTab("solution")} | ||||||||||||||||||||||||||||||
className={`${styles.tabButton} ${ | ||||||||||||||||||||||||||||||
currentSelectedTab === "solution" ? styles.activeTab : "" | ||||||||||||||||||||||||||||||
}`} | ||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||
Solution | ||||||||||||||||||||||||||||||
{currentSelectedTab === "solution" && ( | ||||||||||||||||||||||||||||||
<div className={styles.underline} /> | ||||||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||||||
</button> | ||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
export default TabHeader; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as default } from "./TabHeader"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.container { | ||
height: 100%; | ||
width: 100%; | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,31 @@ | ||||||
"use client"; | ||||||
import ContentViewer from "../ContentViewer/ContentViewer"; | ||||||
import { ReactElement, useState } from "react"; | ||||||
import SolutionTab from "../SolutionTab/SolutionTab"; | ||||||
import TabHeader from "../TabHeader/TabHeader"; | ||||||
import { TabType } from "@/lib/types"; | ||||||
import styles from "./Tabs.module.css"; | ||||||
|
||||||
type ContentTabProps = { | ||||||
Page?: ReactElement; | ||||||
solution: string | ||||||
}; | ||||||
|
||||||
function Tabs({ Page,solution}: ContentTabProps) { | ||||||
const [currentSelectedTab,setCurrentSelectedTab] = useState<TabType>("description"); | ||||||
return ( | ||||||
<div className={styles.container}> | ||||||
<TabHeader currentSelectedTab={currentSelectedTab} setCurrentSelectedTab={setCurrentSelectedTab} /> | ||||||
|
||||||
<ContentViewer> | ||||||
{ | ||||||
currentSelectedTab=="description"? | ||||||
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. Use strict equality (
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
Page: | ||||||
<SolutionTab solution={solution}/> | ||||||
} | ||||||
</ContentViewer> | ||||||
</div> | ||||||
); | ||||||
} | ||||||
|
||||||
export default Tabs; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1 @@ | ||||||
export { default as default } from "./Tabs"; | ||||||
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. [nitpick] Simplify the re-export to
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
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.
Please remove these formatting chagnes