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

Feature: Play & Autoplay Next Video #456

Closed
wants to merge 6 commits into from
Closed
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
4 changes: 2 additions & 2 deletions src/app/courses/[courseId]/[...moduleId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QueryParams } from '@/actions/types';
import { CourseView } from '@/components/CourseView';
import { getCourse, getFullCourseContent } from '@/db/course';
import { getCourse, getFullCourseContent, getNextVideo } from '@/db/course';
import findContentById from '@/lib/find-content-by-id';

export default async function Course({
Expand All @@ -22,7 +22,7 @@ export default async function Course({
);
const contentType =
courseContent?.length === 1 ? courseContent[0]?.type : 'folder';
const nextContent = null; //await getNextVideo(Number(rest[rest.length - 1]))
const nextContent = await getNextVideo(Number(rest[rest.length - 1]));

return (
<CourseView
Expand Down
21 changes: 13 additions & 8 deletions src/components/admin/ContentRendererClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ export const ContentRendererClient = ({
setLoadingMarkAs(false);
};

const playNextVideo = () => {
if (nextContent && nextContent.type === 'video') {
const originalPath = window.location.pathname;
const parts = originalPath.split('/');
parts.pop();
parts.push(nextContent.id.toString());
const newPath = parts.join('/');
router.push(newPath);
}
};

return (
<div className="flex flex-col items-start gap-2 semi:flex-row">
<div className="w-full flex-1">
Expand Down Expand Up @@ -116,6 +127,7 @@ export const ContentRendererClient = ({
}}
onVideoEnd={() => {
setContentCompleted(true);
playNextVideo();
}}
/>
<div className="mb-2 flex justify-between">
Expand Down Expand Up @@ -167,14 +179,7 @@ export const ContentRendererClient = ({
<div className="flex flex-row-reverse">
<button
className="ml-4 rounded bg-blue-500 px-4 py-2 font-bold text-white hover:bg-blue-700"
onClick={() => {
const originalPath = window.location.pathname;
const parts = originalPath.split('/');
parts.pop();
parts.push(nextContent.id.toString());
const newPath = parts.join('/');
router.push(newPath);
}}
onClick={playNextVideo}
>
{nextContent.title}
</button>{' '}
Expand Down
10 changes: 5 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"incremental": true,
"plugins": [
{
"name": "next",
},
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"],
"@public/*": ["./public/*"],
},
"@public/*": ["./public/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"],
"exclude": ["node_modules"]
}
Loading