From 8bdda89fe34028df1815ffe943d1483e2498c162 Mon Sep 17 00:00:00 2001 From: Mohd Mawan Ahmad Date: Thu, 14 Mar 2024 03:50:07 +0530 Subject: [PATCH] Mark as complete UI inconsistency issue resolved --- src/components/Sidebar.tsx | 30 +++++++++++++++++++++++++----- src/store/atoms/markAsComplete.ts | 12 ++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 src/store/atoms/markAsComplete.ts diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index d2e9fe06d..079ab21c3 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -1,5 +1,5 @@ 'use client'; -import { useRouter } from 'next/navigation'; +import { usePathname, useRouter } from 'next/navigation'; import { Accordion, AccordionContent, @@ -13,6 +13,7 @@ import { useRecoilState } from 'recoil'; import { sidebarOpen as sidebarOpenAtom } from '@/store/atoms/sidebar'; import { useEffect, useState } from 'react'; import { handleMarkAsCompleted } from '@/lib/utils'; +import { markAsCompleteAtom } from '@/store/atoms/markAsComplete'; export function Sidebar({ courseId, @@ -58,9 +59,19 @@ export function Sidebar({ const pathArray = findPathToContent(fullCourseContent, contentId); if (pathArray) { const path = `/courses/${courseId}/${pathArray.join('/')}`; + console.log(`Path is this ${path}`); + router.push(path); } }; + const getContentPath = (contentId: any) => { + const pathArray = findPathToContent(fullCourseContent, contentId); + if (pathArray) { + return `/courses/${courseId}/${pathArray.join('/')}`; + + } + }; + const renderContent = (contents: any) => { return contents.map((content: any) => { @@ -101,7 +112,7 @@ export function Sidebar({ {content.type === 'video' ? (
- +
) : null} @@ -232,17 +243,26 @@ function NotionIcon() { } // Todo: Fix types here -function Check({ content }: { content: any }) { +function Check({ content , pathCheck } : { content: any , pathCheck : any}) { const [completed, setCompleted] = useState( content?.videoProgress?.markAsCompleted || false, - ); + ); + const [currentPath] = useState(usePathname()); + const [markAsComplete , setMarkAsComplete] = useRecoilState(markAsCompleteAtom); + + return ( <> { setCompleted(!completed); handleMarkAsCompleted(!completed, content.id); + setMarkAsComplete({ + isValid : true, + path : currentPath, + isCompleted : !completed + }) e.stopPropagation(); }} type="checkbox" diff --git a/src/store/atoms/markAsComplete.ts b/src/store/atoms/markAsComplete.ts new file mode 100644 index 000000000..cc4c88a81 --- /dev/null +++ b/src/store/atoms/markAsComplete.ts @@ -0,0 +1,12 @@ +import {atom} from "recoil"; + +interface markAsCompleteParams { + isValid : boolean + path? : string, + isCompleted? : boolean +} + +export const markAsCompleteAtom = atom({ + key : "markAsCompleteAtom", + default : {isValid : false} +}) \ No newline at end of file