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

Fetch on refresh for play page #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
8 changes: 3 additions & 5 deletions src/app/containers/movie/content.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import Link from "next/link";
import { useVideoContext } from "../play/context";
import { Crew } from "./crew";
import { Genres } from "./genres";

export const Content = ({data}) => {
const { title, description, genres, cast, video_source: videoSource } = data;
const { setVideoUrl } = useVideoContext();

const { id, title, description, genres, cast} = data;

return <div>
<h2>{title}</h2>
<div>{description}</div>
Expand All @@ -15,6 +13,6 @@ export const Content = ({data}) => {
<div>Role: {castMember.role}</div>
<Crew crew={castMember.crew} />
</div>)}
<Link href={"/play"} onClick={() => setVideoUrl(videoSource)}>Watch Movie</Link>
<Link href={`/play/${id}`}>Watch Movie</Link>
</div>
}
15 changes: 0 additions & 15 deletions src/app/containers/play/context.jsx

This file was deleted.

28 changes: 19 additions & 9 deletions src/app/containers/play/index.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
'use client'

import { useVideoContext } from "./context"
import { useMovie } from "../movie/hooks/useMovie";
import { useParams } from 'next/navigation';


export const Video = () => {
const { videoUrl } = useVideoContext()
console.log(videoUrl)

return <div className="flex justify-center items-center h-full">
<video className="w-[600px] h-[400px]" controls>
<source src={videoUrl} type="video/mp4"></source>
Your browser does not support the video tag.
</video>
const params = useParams();
const { id } = params
const { data, error, isError, isLoading, isSuccess } = useMovie(id)

const videoUrl = data?.video_source;

if(isLoading) return <div>Loading...</div>

if(isError) return <div>{error.message}</div>

if(isSuccess && videoUrl)
return <div className="flex justify-center items-center h-full">
<video className="w-[600px] h-[400px]" controls>
<source src={videoUrl} type="video/mp4"></source>
Your browser does not support the video tag.
</video>
</div>
}
5 changes: 5 additions & 0 deletions src/app/play/[id]/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Video } from "../../containers/play";

const PlayPage = () => <Video/>

export default PlayPage;
5 changes: 0 additions & 5 deletions src/app/play/page.jsx

This file was deleted.

4 changes: 0 additions & 4 deletions src/app/providers/index.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
'use client'

import { useValues, VideoContext } from "../containers/play/context";
import { ReactQueryProvider } from "./reactQueryProvider";

export const Providers = ({ children }) => {
const videoValues = useValues()

return (
<ReactQueryProvider>
<VideoContext.Provider value={videoValues}>
{children}
</VideoContext.Provider>
</ReactQueryProvider>
);
};