Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes admin dashbaord #918

Merged
merged 4 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/app/admin/content/[courseId]/[...moduleId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ export default async function UpdateCourseContent({
const rest = params.moduleId;
const course = await getCourse(parseInt(courseId, 10));
const fullCourseContent = await getFullCourseContent(parseInt(courseId, 10));

const courseContent = findContentById(
fullCourseContent,
rest.map((x) => parseInt(x, 10)),
);
const contentType =
courseContent?.length === 1 ? courseContent[0]?.type : 'folder';
const contentType = courseContent?.folder
? 'folder'
: courseContent?.value?.type;

if (contentType === 'video') {
return (
<div className="mx-auto max-w-screen-xl justify-between p-4 text-white">
{/* @ts-ignore */}
<UpdateVideoClient content={courseContent[0]} />
<UpdateVideoClient content={courseContent.value} />
</div>
);
}
Expand All @@ -48,8 +50,8 @@ export default async function UpdateCourseContent({
/>
<AdminCourseContent
rest={rest}
//@ts-ignore
courseContent={courseContent?.map((x: any) => ({
// @ts-ignore
courseContent={courseContent?.value?.map((x: any) => ({
title: x?.title || '',
image: x?.thumbnail || '',
id: x?.id || 0,
Expand Down
9 changes: 5 additions & 4 deletions src/app/admin/content/[courseId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export default async function UpdateCourseContent({
fullCourseContent,
rest.map((x) => parseInt(x, 10)),
);
const contentType =
courseContent?.length === 1 ? courseContent[0]?.type : 'folder';
const contentType = courseContent?.folder
? 'folder'
: courseContent?.value.type;

if (contentType === 'video') {
return (
Expand Down Expand Up @@ -45,8 +46,8 @@ export default async function UpdateCourseContent({
/>
<AdminCourseContent
rest={rest}
//@ts-ignore
courseContent={courseContent?.map((x: any) => ({
// @ts-ignore
courseContent={courseContent?.value.map((x: any) => ({
title: x?.title || '',
image: x?.thumbnail || '',
id: x?.id || 0,
Expand Down
3 changes: 0 additions & 3 deletions src/app/courses/[courseId]/[...moduleId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ export default async function Course({
fullCourseContent,
rest.map((x) => parseInt(x, 10)),
);
const contentType =
courseContent?.length === 1 ? courseContent[0]?.type : 'folder';
const nextContent = null; //await getNextVideo(Number(rest[rest.length - 1]))

return (
<CourseView
rest={rest}
course={course}
contentType={contentType}
nextContent={nextContent}
courseContent={courseContent}
fullCourseContent={fullCourseContent}
Expand Down
4 changes: 1 addition & 3 deletions src/app/courses/[courseId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ export default async function Course({
const fullCourseContent = await getFullCourseContent(parseInt(courseId, 10));

const courseContent = findContentById(fullCourseContent, []);
const contentType =
courseContent?.length === 1 ? courseContent[0]?.type : 'folder';

const nextContent = null;

return (
<CourseView
rest={[]}
course={course}
contentType={contentType}
nextContent={nextContent}
courseContent={courseContent}
fullCourseContent={fullCourseContent}
Expand Down
65 changes: 39 additions & 26 deletions src/components/CourseView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FullCourseContent } from '@/db/course';
import { ChildCourseContent, FullCourseContent } from '@/db/course';
import { ContentRenderer } from './admin/ContentRenderer';
import { FolderView } from './FolderView';
import { NotionRenderer } from './NotionRenderer';
Expand All @@ -13,19 +13,29 @@ export const CourseView = ({
fullCourseContent,
courseContent,
nextContent,
contentType,
searchParams,
possiblePath,
}: {
fullCourseContent: FullCourseContent[];
rest: string[];
course: any;
courseContent: any;
courseContent:
| {
folder: true;
value: ChildCourseContent[];
}
| {
folder: false;
value: ChildCourseContent;
}
| null;
nextContent: any;
contentType: any;
searchParams: QueryParams;
possiblePath: string;
}) => {
const contentType = courseContent?.folder
? 'folder'
: courseContent?.value.type;
return (
<div className="no-scrollbar flex h-screen flex-col overflow-y-auto pb-20">
<div className="mb-2 flex max-h-fit min-h-[2.5rem] items-center px-4">
Expand All @@ -37,42 +47,44 @@ export const CourseView = ({
rest={rest}
/>
</div>
{contentType === 'notion' ? (
{!courseContent?.folder && courseContent?.value.type === 'notion' ? (
<div className="m-4">
<NotionRenderer id={courseContent[0]?.id} />
<NotionRenderer id={courseContent?.value?.id?.toString()} />
</div>
) : null}

{contentType === 'video' ? (
{!courseContent?.folder && contentType === 'video' ? (
<ContentRenderer
nextContent={nextContent}
content={{
thumbnail: courseContent[0]?.thumbnail || '',
id: courseContent[0]?.id || 0,
title: courseContent[0]?.title || '',
thumbnail: courseContent?.value?.thumbnail || '',
id: courseContent?.value.id || 0,
title: courseContent?.value?.title || '',
type: contentType || 'video',
description: courseContent[0]?.description || '',
description: courseContent?.value?.description || '',
markAsCompleted:
courseContent[0]?.videoProgress?.markAsCompleted || false,
bookmark: courseContent[0].bookmark,
courseContent?.value?.videoProgress?.markAsCompleted || false,
bookmark: courseContent?.value.bookmark ?? null,
}}
/>
) : null}
{(contentType === 'video' || contentType === 'notion') && (
<Comments
content={{
id: courseContent[0]?.id || 0,
courseId: parseInt(course.id, 10) || 0,
commentCount: courseContent[0]?.commentsCount || 0,
possiblePath,
}}
searchParams={searchParams}
/>
)}
{contentType === 'folder' ? (
{!courseContent?.folder &&
(contentType === 'video' || contentType === 'notion') && (
<Comments
content={{
id: courseContent?.value?.id || 0,
courseId: parseInt(course.id, 10) || 0,
//@ts-ignore
commentCount: courseContent?.value.commentsCount || 0,
possiblePath,
}}
searchParams={searchParams}
/>
)}
{courseContent?.folder ? (
<FolderView
rest={rest}
courseContent={courseContent?.map((x: any) => ({
courseContent={courseContent?.value.map((x: any) => ({
title: x?.title || '',
image: x?.thumbnail || '',
type: x?.type || 'folder',
Expand All @@ -81,6 +93,7 @@ export const CourseView = ({
percentComplete: getFolderPercentCompleted(x?.children),
videoFullDuration: x?.videoProgress?.videoFullDuration || 0,
duration: x?.videoProgress?.duration || 0,
bookmark: null,
}))}
courseId={parseInt(course.id, 10)}
/>
Expand Down
3 changes: 2 additions & 1 deletion src/components/admin/ContentRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { authOptions } from '@/lib/auth';
import { ContentRendererClient } from './ContentRendererClient';
import { Bookmark } from '@prisma/client';

function bunnyUrl(url: string) {
function bunnyUrl(url?: string) {
if (!url) return '';
return url
.replace('https://appxcontent.kaxa.in', 'https://appxcontent.b-cdn.net')
.replace(
Expand Down
10 changes: 6 additions & 4 deletions src/db/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,13 @@ interface VideoProgress {
videoFullDuration: number | null;
}

export type ChildCourseContent = {
videoProgress: VideoProgress | null;
bookmark?: Bookmark;
} & ContentWithMetadata;

export type FullCourseContent = {
children?: ({
videoProgress: VideoProgress | null;
bookmark?: Bookmark;
} & ContentWithMetadata)[];
children?: ChildCourseContent[];
videoProgress: VideoProgress | null;
bookmark?: Bookmark;
} & ContentWithMetadata;
Expand Down
19 changes: 14 additions & 5 deletions src/lib/find-content-by-id.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { FullCourseContent } from '@/db/course';
import { ChildCourseContent, FullCourseContent } from '@/db/course';

export default function findContentById(
contents: FullCourseContent[],
ids: number[],
) {
if (ids.length === 0) return contents;
):
| {
folder: true;
value: ChildCourseContent[];
}
| {
folder: false;
value: ChildCourseContent;
}
| null {
if (ids.length === 0) return { folder: true, value: contents };

const currentId = ids[0];
const remainingIds = ids.slice(1);
Expand All @@ -15,10 +24,10 @@ export default function findContentById(
return null;
} else if (remainingIds.length === 0) {
if (foundContent.type === 'folder') {
return foundContent.children;
return { folder: true, value: foundContent.children ?? [] }; // [Object]
}

return [foundContent];
return { folder: false, value: foundContent };
}

return findContentById(foundContent?.children || [], remainingIds);
Expand Down
Loading