Skip to content

Commit

Permalink
[fix] playlist modal conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamdrive committed May 13, 2022
1 parent c15e23b commit 94b532e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/pages/watch/Watch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
RelatedVideoCard,
SingleVideoCard,
} from "../../components";
import { useParams } from "react-router-dom";
import { useNavigate, useParams } from "react-router-dom";
import { useAuth, useVideo } from "../../context";

export const Watch = () => {
Expand All @@ -28,6 +28,7 @@ export const Watch = () => {
setModal,
} = useAuth();

const navigate = useNavigate()
const currentVideo = videos?.find((video) => video._id === slug);

const relatedVideos = videos?.filter(
Expand Down Expand Up @@ -61,9 +62,15 @@ export const Watch = () => {
deleteFromWatchLater(token, videoId, videoDispatch);
};

const handleModalOpen = (video) => {
setplaylistVideo(video);
setModal((s) => !s);
const handlePlaylist = (video) => {
if (token) {
setplaylistVideo(video);
setModal((s) => !s);
} else {
navigate("/login", {
replace: true,
});
}
};

return (
Expand All @@ -90,7 +97,7 @@ export const Watch = () => {
: () => updateWatchLater(currentVideo)
}
isWatchLater={isWatchLater}
handlePlaylistModal={handleModalOpen}
handlePlaylistModal={handlePlaylist}
/>
</Grid>
<Grid
Expand Down

0 comments on commit 94b532e

Please sign in to comment.