Skip to content

Commit

Permalink
fixed required changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pavanydg committed Oct 29, 2024
1 parent 29f2403 commit 3cec64f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/components/CheckPointRedirect/CheckPointRedirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import { useEffect } from 'react'
import { useRouter } from 'next/navigation'
import { getcheckPoint } from '@/lib/progressSaving'
import { getCheckPoint } from '@/lib/progressSaving'


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

useEffect(() => {
const checkpoint = getcheckPoint()
const checkpoint = getCheckPoint()
if (checkpoint) {
router.push(`content/${checkpoint}`)
}
Expand Down
4 changes: 2 additions & 2 deletions app/components/CodeEditor/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import FiChevronRight from "@/app/styles/icons/HiChevronRightGreen";
import { useRouter } from "next/navigation";
import { useEditorStore } from "@/lib/stores";
import { sendGAEvent } from "@next/third-parties/google";
import { getCode, setCode } from "@/lib/progressSaving";
import { getCode, persistCode } from "@/lib/progressSaving";

export default function CodeEditor({
codeString,
Expand Down Expand Up @@ -86,7 +86,7 @@ export default function CodeEditor({
}, [chapterIndex, stepIndex]);

useEffect(() => {
setCode(chapterIndex, stepIndex, codeString);
persistCode(chapterIndex, stepIndex, codeString);
}, [codeString, chapterIndex, stepIndex]);

return (
Expand Down
14 changes: 4 additions & 10 deletions lib/progressSaving.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function setCheckpoint(path: string) {
localStorage.setItem("checkPoint", JSON.stringify(checkpoint));
}

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

const checkpoint = localStorage.getItem('checkPoint')
Expand All @@ -16,9 +16,7 @@ export function getcheckPoint(){
return null
}

export function setCode(chapter:number, lesson: number, code:string){
if (typeof window === "undefined") return false;

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

const key = `${chapter}.${lesson}`
Expand All @@ -28,19 +26,15 @@ export function setCode(chapter:number, lesson: number, code:string){
localStorage.setItem('codeData',JSON.stringify(codeData))
}

export function getCode(chapter: number,lesson:number){
if (typeof window === "undefined") return false;

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

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

return codeData[key]
}

export function resetCode(chapter: number, lesson: number){
if (typeof window === "undefined") return false;

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

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

0 comments on commit 3cec64f

Please sign in to comment.