Skip to content

Commit

Permalink
fix: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelRajodiya committed Oct 30, 2024
1 parent 3cec64f commit f0fb6ca
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 40 deletions.
21 changes: 10 additions & 11 deletions app/components/CheckPointRedirect/CheckPointRedirect.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
'use client'

import { useEffect } from 'react'
import { useRouter } from 'next/navigation'
import { getCheckPoint } from '@/lib/progressSaving'
"use client";

import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { getCheckPoint } from "@/lib/progressSaving";

export default function CheckpointRedirect() {
const router = useRouter()
const router = useRouter();

useEffect(() => {
const checkpoint = getCheckPoint()
const checkpoint = getCheckPoint();
if (checkpoint) {
router.push(`content/${checkpoint}`)
router.push(`content/${checkpoint}`);
}
}, [router])
}, [router]);

return null
}
return null;
}
2 changes: 1 addition & 1 deletion app/components/CheckPointRedirect/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as default } from "./CheckPointRedirect";
export { default as default } from "./CheckPointRedirect";
6 changes: 2 additions & 4 deletions app/components/CodeEditor/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function CodeEditor({
document.removeEventListener("keydown", handleKeyDown);
};
}, [codeString]);

useEffect(() => {
const savedCode = getCode(chapterIndex, stepIndex);
if (savedCode && savedCode !== codeString) {
Expand All @@ -98,9 +98,7 @@ export default function CodeEditor({
theme={colorMode === "light" ? "light" : "my-theme"}
value={codeString}
height={"100%"}
onChange={(codeString) =>
setCodeString(codeString ? codeString : "")
}
onChange={(codeString) => setCodeString(codeString ? codeString : "")}
options={{ minimap: { enabled: false }, fontSize: 14 }}
onMount={(editor, monaco) => {
setMonaco(monaco);
Expand Down
4 changes: 2 additions & 2 deletions app/components/NavBarMenus/NavBarMenus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function NavBarMenu() {
mt={2}
onClick={() => {
localStorage.removeItem("progress");
localStorage.removeItem("codeData")
localStorage.removeItem("codeData");
setIsOpen(false);
toast({
title: "Progress Cleared",
Expand All @@ -85,7 +85,7 @@ export default function NavBarMenu() {
duration: 3000,
isClosable: true,
});
window.location.reload()
window.location.reload();
}}
>
RESET
Expand Down
2 changes: 1 addition & 1 deletion app/content/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function PageLayout({
params: { markdownPath: string[] };
}) {
const urlPath = usePathname().replace("/content", "").substring(1);
setCheckpoint(urlPath)
setCheckpoint(urlPath);
return (
<div className={styles.wrapper}>
<NavBar urlPath={urlPath} />
Expand Down
4 changes: 2 additions & 2 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import CheckpointRedirect from "./components/CheckPointRedirect/CheckPointRedire
export default function Home() {
return (
<div className={cx(styles.main, outfitFont.className)}>
<CheckpointRedirect/>
<CheckpointRedirect />
<div className={styles.wrapper}>
<div className={styles.backgroundClipWrapper}>
<div className={styles.titleWrapper}>
Expand Down Expand Up @@ -36,4 +36,4 @@ export default function Home() {
</div>
</div>
);
}
}
2 changes: 1 addition & 1 deletion app/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ html {

main {
height: 100%;
}
}
2 changes: 1 addition & 1 deletion app/styles/page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@

.footerText {
font-weight: 700;
}
}
34 changes: 17 additions & 17 deletions lib/progressSaving.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
export function setCheckpoint(path: string) {
if (typeof window === "undefined") return false;
const checkpoint = path
const checkpoint = path;

localStorage.setItem("checkPoint", JSON.stringify(checkpoint));
}

export function getCheckPoint(){
export function getCheckPoint() {
if (typeof window === "undefined") return false;

const checkpoint = localStorage.getItem('checkPoint')
if(checkpoint){
return JSON.parse(checkpoint)
const checkpoint = localStorage.getItem("checkPoint");

if (checkpoint) {
return JSON.parse(checkpoint);
}
return null
return null;
}

export function persistCode(chapter:number, lesson: number, code:string){
const codeData = JSON.parse(localStorage.getItem('codeData') || '{}');
export function persistCode(chapter: number, lesson: number, code: string) {
const codeData = JSON.parse(localStorage.getItem("codeData") || "{}");

const key = `${chapter}.${lesson}`
const key = `${chapter}.${lesson}`;

codeData[key] = code;

localStorage.setItem('codeData',JSON.stringify(codeData))
localStorage.setItem("codeData", JSON.stringify(codeData));
}

export function getCode(chapter: number,lesson:number){
const codeData = JSON.parse(localStorage.getItem('codeData') || '{}');
export function getCode(chapter: number, lesson: number) {
const codeData = JSON.parse(localStorage.getItem("codeData") || "{}");

const key = `${chapter}.${lesson}`;

return codeData[key]
return codeData[key];
}

export function resetCode(chapter: number, lesson: number){
const codeData = JSON.parse(localStorage.getItem('codeData') || '{}');
export function resetCode(chapter: number, lesson: number) {
const codeData = JSON.parse(localStorage.getItem("codeData") || "{}");

const key = `${chapter}.${lesson}`;

codeData[key] = null;
}
}

0 comments on commit f0fb6ca

Please sign in to comment.