Skip to content

Commit

Permalink
fix bookmark and view of bookmark (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
paahaad authored Oct 4, 2024
1 parent 700e6b1 commit 59a4586
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/actions/bookmark/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export type ReturnTypeDeleteBookmark = ActionState<
export type TBookmarkWithContent = Bookmark & {
content: Content & {
parent: { id: number; courses: CourseContent[] } | null;
courses: CourseContent[];
};
};
4 changes: 2 additions & 2 deletions src/components/CourseView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const CourseView = ({
description: courseContent?.value?.description || '',
markAsCompleted:
courseContent?.value?.videoProgress?.markAsCompleted || false,
bookmark: courseContent?.value.bookmark ?? null,
bookmark: courseContent?.value.bookmark || null,
}}
/>
) : null}
Expand Down Expand Up @@ -95,7 +95,7 @@ export const CourseView = ({
percentComplete: getFolderPercentCompleted(x?.children),
videoFullDuration: x?.videoProgress?.videoFullDuration || 0,
duration: x?.videoProgress?.duration || 0,
bookmark: null,
bookmark: x.bookmark || null,
}))}
courseId={parseInt(course.id, 10)}
/>
Expand Down
20 changes: 18 additions & 2 deletions src/components/bookmark/BookmarkList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,29 @@ const BookmarkList = ({
{bookmarkData.map((bookmark) => {
const {
contentId,
content: { type, parent, title, hidden, thumbnail },
content: { type, parent, title, hidden, thumbnail, courses },
} = bookmark;
if (type === 'video' && parent && !hidden) {
if ((type === 'video' || type === 'notion') && parent && !hidden) {
const { id: folderId, courses } = parent;
const courseId = courses[0].courseId;
const videoUrl = `/courses/${courseId}/${folderId}/${contentId}`;

return (
<ContentCard
type={type}
key={contentId}
title={title}
image={thumbnail || ''}
onClick={() => {
router.push(videoUrl);
}}
bookmark={bookmark}
contentId={contentId}
/>
);
} else if (type === 'folder' && !parent) {
const videoUrl = `/courses/${courses[0].courseId}/${courses[0].contentId}`;

return (
<ContentCard
type={type}
Expand Down
6 changes: 6 additions & 0 deletions src/db/bookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export const getBookmarkDataWithContent = async (): Promise<
courses: true,
},
},
courses: {
select: {
courseId: true,
contentId: true,
},
},
},
},
},
Expand Down

0 comments on commit 59a4586

Please sign in to comment.