Skip to content

Commit

Permalink
Mark as complete UI inconsistency issue resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
Maawan committed Mar 13, 2024
1 parent 2bf6062 commit 8bdda89
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client';
import { useRouter } from 'next/navigation';
import { usePathname, useRouter } from 'next/navigation';
import {
Accordion,
AccordionContent,
Expand All @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -101,7 +112,7 @@ export function Sidebar({
</div>
{content.type === 'video' ? (
<div className="flex flex-col justify-center ml-2">
<Check content={content} />
<Check content={content} pathCheck = {getContentPath}/>
</div>
) : null}
</div>
Expand Down Expand Up @@ -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 (
<>
<input
defaultChecked={completed}
checked={markAsComplete.isValid && markAsComplete?.path === pathCheck(content.id) ? markAsComplete.isCompleted : completed}
onClick={async (e) => {
setCompleted(!completed);
handleMarkAsCompleted(!completed, content.id);
setMarkAsComplete({
isValid : true,
path : currentPath,
isCompleted : !completed
})
e.stopPropagation();
}}
type="checkbox"
Expand Down
12 changes: 12 additions & 0 deletions src/store/atoms/markAsComplete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {atom} from "recoil";

interface markAsCompleteParams {
isValid : boolean
path? : string,
isCompleted? : boolean
}

export const markAsCompleteAtom = atom<markAsCompleteParams>({
key : "markAsCompleteAtom",
default : {isValid : false}
})

0 comments on commit 8bdda89

Please sign in to comment.