file: create index.js file in the components directory that contains all the...
This commit is contained in:
1 parent
6cea768210
commit
2d6884389f
69 files changed
+1341
-61
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import { useState } from 'react';
|
||||
import { Box, Button, CircularProgress, Grid, Typography } from '@mui/material';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { ArrowBack } from '@mui/icons-material';
|
||||
|
||||
import useStyles from './styles';
|
||||
import { useGetActorQuery, useGetMoviesByActorIdQuery } from '../../services/TMDB';
|
||||
import { MovieList, Pagination } from '../index';
|
||||
|
||||
function Actors() {
|
||||
const classes = useStyles();
|
||||
const [page, setPage] = useState(1);
|
||||
const navigate = useNavigate();
|
||||
const { id } = useParams();
|
||||
const { data, isFetching, error } = useGetActorQuery(id);
|
||||
const { data: movies } = useGetMoviesByActorIdQuery({ id, page });
|
||||
|
||||
if (isFetching) {
|
||||
return (
|
||||
<Box display="flex" alignItems="center" justifyContent="center">
|
||||
<CircularProgress size="8rem" />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<Box display="flex" alignItems="center" justifyContent="center">
|
||||
<Button startIcon={<ArrowBack />} onClick={() => navigate(-1)} color="primary">
|
||||
Go Back
|
||||
</Button>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Grid container spacing={3}>
|
||||
<Grid item lg={5} xl={4}>
|
||||
<img
|
||||
className={classes.image}
|
||||
src={`https://image.tmdb.org/t/p/w780/${data?.profile_path}`}
|
||||
alt={data.name}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item lg={7} xl={8} style={{ display: 'flex', justifyContent: 'center', flexDirection: 'column' }}>
|
||||
<Typography variant="h2" gutterBottom>{data?.name}</Typography>
|
||||
<Typography variant="h5" gutterBottom>Born: {new Date(data?.birthday).toDateString()}</Typography>
|
||||
<Typography variant="body1" align="justify" paragraph>{data?.biography || 'Sorry, no biography yet...'}</Typography>
|
||||
<Box className={classes.btns}>
|
||||
<Button variant="contained" color="primary" target="_blank" href={`https://www.imdb.com/name/${data?.imdb_id}`}>IMDB</Button>
|
||||
<Button startIcon={<ArrowBack />} onClick={() => navigate(-1)} color="primary">Back</Button>
|
||||
</Box>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Box margin="2rem 0">
|
||||
<Typography variant="h2" gutterBottom align="center">Movies</Typography>
|
||||
{movies && <MovieList movies={movies} numberOfMovies={12} />}
|
||||
<Pagination currentPage={page} setPage={setPage} totalPages={movies?.total_pages} />
|
||||
</Box>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Actors;
|
||||
@@ -0,0 +1,15 @@
|
||||
import { makeStyles } from '@mui/styles';
|
||||
|
||||
export default makeStyles(() => ({
|
||||
image: {
|
||||
maxWidth: '90%',
|
||||
borderRadius: '20px',
|
||||
objectFit: 'cover',
|
||||
boxShadow: '0.5em 0.5em 1em',
|
||||
},
|
||||
btns: {
|
||||
marginTop: '2rem',
|
||||
display: 'flex',
|
||||
justifyContent: 'space-around',
|
||||
},
|
||||
}));
|
||||
@@ -0,0 +1,48 @@
|
||||
import { useEffect, useContext } from 'react';
|
||||
import alanBtn from '@alan-ai/alan-sdk-web';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
import { ColorModeContext } from '../utils/ToggleColorMode';
|
||||
import { fetchToken } from '../utils/index';
|
||||
import { selectGenreOrCategory, searchMovie } from '../features/currentGenreOrCategory';
|
||||
|
||||
function useAlan() {
|
||||
const { setMode } = useContext(ColorModeContext);
|
||||
const dispatch = useDispatch();
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
alanBtn({
|
||||
key: process.env.REACT_APP_ALAN_SDK_KEY,
|
||||
onCommand: ({ command, mode, genres, genreOrCategory, query }) => {
|
||||
if (command === 'chooseGenre') {
|
||||
const foundGenre = genres.find((g) => g.name.toLowerCase() === genreOrCategory.toLowerCase());
|
||||
if (foundGenre) {
|
||||
navigate('/');
|
||||
dispatch(selectGenreOrCategory(foundGenre.id));
|
||||
} else {
|
||||
const category = genreOrCategory.startsWith('top') ? 'top_rated' : genreOrCategory;
|
||||
navigate('/');
|
||||
dispatch(selectGenreOrCategory(category));
|
||||
}
|
||||
} else if (command === 'changeMode') {
|
||||
if (mode === 'light') {
|
||||
setMode('light');
|
||||
} else {
|
||||
setMode('dark');
|
||||
}
|
||||
} else if (command === 'login') {
|
||||
fetchToken();
|
||||
} else if (command === 'logout') {
|
||||
localStorage.clear();
|
||||
navigate('/');
|
||||
} else if (command === 'search') {
|
||||
dispatch(searchMovie(query));
|
||||
}
|
||||
},
|
||||
});
|
||||
}, []);
|
||||
}
|
||||
|
||||
export default useAlan;
|
||||
@@ -0,0 +1,36 @@
|
||||
import { useRef } from 'react';
|
||||
import { CssBaseline} from "@mui/material";
|
||||
import { Routes, Route } from 'react-router-dom';
|
||||
|
||||
import useStyles from './styles';
|
||||
import useAlan from './Alan';
|
||||
|
||||
import { Actors, Movies, MovieInfo, Navbar, Profile } from './index'
|
||||
|
||||
function App() {
|
||||
const classes = useStyles();
|
||||
const alanBtnContainer = useRef();
|
||||
|
||||
useAlan();
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<CssBaseline />
|
||||
<Navbar />
|
||||
<main className={classes.content}>
|
||||
<div className={classes.toolbar}>
|
||||
<Routes>
|
||||
<Route exact path={'/'} element={<Movies />}/>
|
||||
<Route exact path={'/approved'} element={<Movies />}/>
|
||||
<Route exact path={'/movie/:id'} element={<MovieInfo />}/>
|
||||
<Route exact path={'/actors/:id'} element={<Actors />}/>
|
||||
<Route exact path={'/profile/:id'} element={<Profile />}/>
|
||||
</Routes>
|
||||
</div>
|
||||
</main>
|
||||
<div ref={alanBtnContainer}/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
@@ -0,0 +1,32 @@
|
||||
import { Box, Typography, Card, CardContent, CardMedia } from '@mui/material';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import useStyles from './styles';
|
||||
|
||||
function FeaturedMovie({ movie }) {
|
||||
const classes = useStyles();
|
||||
|
||||
if (!movie) return null;
|
||||
|
||||
return (
|
||||
<Box component={Link} to={`/movie/${movie.id}`} className={classes.featuredCardContainer}>
|
||||
<Card className={classes.card} classes={{ root: classes.cardRoot }}>
|
||||
<CardMedia
|
||||
media="picture"
|
||||
alt={movie.title}
|
||||
image={`https://image.tmdb.org/t/p/original/${movie?.backdrop_path}`}
|
||||
title={movie.title}
|
||||
className={classes.cardMedia}
|
||||
/>
|
||||
<Box padding="20px">
|
||||
<CardContent className={classes.cardContent} classes={{ root: classes.cardContentRoot }}>
|
||||
<Typography variant="h5" gutterBottom>{movie.title}</Typography>
|
||||
<Typography variant="body2">{movie.overview}</Typography>
|
||||
</CardContent>
|
||||
</Box>
|
||||
</Card>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default FeaturedMovie;
|
||||
@@ -0,0 +1,40 @@
|
||||
import { makeStyles } from '@mui/styles';
|
||||
|
||||
export default makeStyles((theme) => ({
|
||||
featuredCardContainer: {
|
||||
marginBottom: '20px',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
height: '490px',
|
||||
textDecoration: 'none',
|
||||
},
|
||||
card: {
|
||||
width: '100%',
|
||||
display: 'flex',
|
||||
justifyContent: 'flex-end',
|
||||
flexDirection: 'column',
|
||||
},
|
||||
cardRoot: {
|
||||
position: 'relative',
|
||||
},
|
||||
cardMedia: {
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
right: 0,
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
backgroundColor: 'rgba(0,0,0,0.575)',
|
||||
backgroundBlendMode: 'darken',
|
||||
},
|
||||
cardContent: {
|
||||
color: '#fff',
|
||||
width: '40%',
|
||||
[theme.breakpoints.down('sm')]: {
|
||||
width: '100%',
|
||||
},
|
||||
},
|
||||
cardContentRoot: {
|
||||
position: 'relative',
|
||||
backgroundColor: 'transparent',
|
||||
},
|
||||
}));
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Typography, Grid, Grow, Tooltip, Rating } from '@mui/material';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import useStyles from './styles';
|
||||
|
||||
function Movie({ movie, i }) {
|
||||
const classes = useStyles();
|
||||
|
||||
return (
|
||||
<Grid item xs={12} sm={6} md={4} lg={3} xl={2} className={classes.movie}>
|
||||
<Grow in key={i} timeout={(i + 1) * 250}>
|
||||
<Link className={classes.links} to={`/movie/${movie.id}`}>
|
||||
<img
|
||||
src={movie.poster_path ? `https://image.tmdb.org/t/p/w500/${movie.poster_path}` : 'https://www.fillmurray.com/200/300'}
|
||||
alt={movie.title}
|
||||
className={classes.image}
|
||||
/>
|
||||
<Typography className={classes.title} variant="h5">{movie.title}</Typography>
|
||||
<Tooltip disableTouchListener title={`${movie.vote_average} / 10`}>
|
||||
<div>
|
||||
<Rating readOnly value={movie.vote_average / 2} precision={0.1} />
|
||||
</div>
|
||||
</Tooltip>
|
||||
</Link>
|
||||
</Grow>
|
||||
</Grid>
|
||||
);
|
||||
}
|
||||
|
||||
export default Movie;
|
||||
@@ -0,0 +1,37 @@
|
||||
import { makeStyles } from '@mui/styles';
|
||||
|
||||
export default makeStyles((theme) => ({
|
||||
movie: {
|
||||
padding: '10px',
|
||||
},
|
||||
title: {
|
||||
color: theme.palette.text.primary,
|
||||
textOverflow: 'ellipsis',
|
||||
width: '230px',
|
||||
overflow: 'hidden',
|
||||
whiteSpace: 'nowrap',
|
||||
marginTop: '10px',
|
||||
marginBottom: 0,
|
||||
textAlign: 'center',
|
||||
},
|
||||
links: {
|
||||
alignItems: 'center',
|
||||
fontWeight: 'bolder',
|
||||
textDecoration: 'none',
|
||||
[theme.breakpoints.up('xs')]: {
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
},
|
||||
'&:hover': {
|
||||
cursor: 'pointer',
|
||||
},
|
||||
},
|
||||
image: {
|
||||
borderRadius: '20px',
|
||||
height: '300px',
|
||||
marginBottom: '10px',
|
||||
'&:hover': {
|
||||
transform: 'scale(1.05)',
|
||||
},
|
||||
},
|
||||
}));
|
||||
@@ -0,0 +1,181 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Modal, Typography, Button, ButtonGroup, Grid, Box, CircularProgress, Rating } from '@mui/material';
|
||||
import { Movie as MovieIcon, Theaters, Language, PlusOne, Favorite, FavoriteBorderOutlined, Remove, ArrowBack } from '@mui/icons-material';
|
||||
import { Link, useParams } from 'react-router-dom';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import axios from 'axios';
|
||||
|
||||
import useStyles from './styles';
|
||||
import { MovieList } from '../index';
|
||||
import { useGetMovieQuery, useGetRecommendationsQuery, useGetListQuery } from '../../services/TMDB';
|
||||
import { selectGenreOrCategory } from '../../features/currentGenreOrCategory';
|
||||
import genreIcons from '../../assets/genres';
|
||||
|
||||
function MovieInfo() {
|
||||
const classes = useStyles();
|
||||
const dispatch = useDispatch();
|
||||
const { user } = useSelector((state) => state.user);
|
||||
const { id } = useParams();
|
||||
|
||||
const { data, error, isFetching } = useGetMovieQuery(id);
|
||||
const { data: favoriteMovies } = useGetListQuery({ listName: 'favorite/movies', accountId: user.id, sessionId: localStorage.getItem('session_id'), page: 1 });
|
||||
const { data: watchlistMovies } = useGetListQuery({ listName: 'watchlist/movies', accountId: user.id, sessionId: localStorage.getItem('session_id'), page: 1 });
|
||||
const { data: recommendations } = useGetRecommendationsQuery({ list: '/recommendations', movie_id: id });
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
const [isMovieFavorited, setIsMovieFavorited] = useState(false);
|
||||
const [isMovieWatchlisted, setIsMovieWatchlisted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setIsMovieFavorited(!!favoriteMovies?.results?.find((movie) => movie?.id === data?.id));
|
||||
}, [favoriteMovies, data]);
|
||||
useEffect(() => {
|
||||
setIsMovieWatchlisted(!!watchlistMovies?.results?.find((movie) => movie?.id === data?.id));
|
||||
}, [watchlistMovies, data]);
|
||||
|
||||
const addToFavorites = async () => {
|
||||
await axios.post(`https://api.themoviedb.org/3/account/${user.id}/favorite?api_key=${process.env.REACT_APP_TMDB_KEY}&session_id=${localStorage.getItem('session_id')}`, {
|
||||
media_type: 'movie',
|
||||
media_id: id,
|
||||
favorite: !isMovieFavorited,
|
||||
});
|
||||
|
||||
setIsMovieFavorited((prev) => !prev);
|
||||
};
|
||||
|
||||
const addToWatchList = async () => {
|
||||
await axios.post(`https://api.themoviedb.org/3/account/${user.id}/watchlist?api_key=${process.env.REACT_APP_TMDB_KEY}&session_id=${localStorage.getItem('session_id')}`, {
|
||||
media_type: 'movie',
|
||||
media_id: id,
|
||||
watchlist: !isMovieWatchlisted,
|
||||
});
|
||||
|
||||
setIsMovieWatchlisted((prev) => !prev);
|
||||
};
|
||||
|
||||
if (isFetching) {
|
||||
return (
|
||||
<Box display="flex" alignItems="center" justifyContent="center">
|
||||
<CircularProgress size="8rem" />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<Box display="flex" alignItems="center" justifyContent="center">
|
||||
<Link to="/">Something went wrong - Go back.</Link>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Grid container className={classes.containerSpaceAround}>
|
||||
<Grid item sm={12} lg={4} align="center">
|
||||
<img
|
||||
src={`https://image.tmdb.org/t/p/w500/${data?.poster_path}`}
|
||||
className={classes.poster}
|
||||
alt={data?.title}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item container direction="column" lg={7}>
|
||||
<Typography variant="h3" align="center" gutterBottom>
|
||||
{data?.title} ({data.release_date.split('-')[0]})
|
||||
</Typography>
|
||||
<Typography variant="h5" align="center" gutterBottom>
|
||||
{data?.tagline}
|
||||
</Typography>
|
||||
<Grid item className={classes.containerSpaceAround}>
|
||||
<Box display="flex" align="center">
|
||||
<Rating readOnly value={data.vote_average / 2} />
|
||||
<Typography gutterBottom variant="subtitle1" style={{ marginLeft: '10px' }}>
|
||||
{data?.vote_average} / 10
|
||||
</Typography>
|
||||
</Box>
|
||||
<Typography gutterBottom variant="h6" align="center">{data?.runtime}min</Typography>
|
||||
</Grid>
|
||||
<Grid item className={classes.genresContainer}>
|
||||
{data?.genres?.map((genre) => (
|
||||
<Link className={classes.links} key={genre.name} to="/" onClick={() => dispatch(selectGenreOrCategory(genre.id))}>
|
||||
<img src={genreIcons[genre.name.toLowerCase()]} className={classes.genreImage} height={30} />
|
||||
<Typography color="textPrimary" variant="subtitle1">{genre?.name}</Typography>
|
||||
</Link>
|
||||
))}
|
||||
</Grid>
|
||||
<Typography variant="h5" gutterBottom style={{ marginTop: '20px' }}>Overview</Typography>
|
||||
<Typography style={{ marginBottom: '2rem' }}>{data?.overview}</Typography>
|
||||
<Typography variant="h5" gutterBottom>Top Cast</Typography>
|
||||
<Grid item container spacing={2}>
|
||||
{data && data?.credits?.cast?.map((character, i) => (
|
||||
character.profile_path && (
|
||||
<Grid key={i} item xs={4} md={2} component={Link} to={`/actors/${character.id}`} style={{ textDecoration: 'none' }}>
|
||||
<img
|
||||
className={classes.castImage}
|
||||
src={`https://image.tmdb.org/t/p/w500/${character.profile_path}`}
|
||||
alt={character.name}
|
||||
/>
|
||||
<Typography color="textPrimary" align="center">{character?.name}</Typography>
|
||||
<Typography color="textSecondary" align="center">
|
||||
{character.character.split('/')[0]}
|
||||
</Typography>
|
||||
</Grid>
|
||||
)
|
||||
)).slice(0, 6)}
|
||||
</Grid>
|
||||
<Grid item container style={{ marginTop: '2rem' }}>
|
||||
<div className={classes.buttonContainer}>
|
||||
<Grid item xs={12} sm={6} className={classes.buttonContainer}>
|
||||
<ButtonGroup size="small" variant="outlined">
|
||||
<Button target="_blank" rel="noopener noreferrer" href={data?.homepage} endIcon={<Language />}>Website</Button>
|
||||
<Button target="_blank" rel="noopener noreferrer" href={`https://www.imdb.com/title/${data?.imdb_id}`} endIcon={<MovieIcon />}>IMDB</Button>
|
||||
<Button onClick={() => setOpen(true)} href="#" endIcon={<Theaters />}>Trailer</Button>
|
||||
</ButtonGroup>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6} className={classes.buttonContainer}>
|
||||
<ButtonGroup size="small" variant="outlined">
|
||||
<Button onClick={addToFavorites} endIcon={isMovieFavorited ? <FavoriteBorderOutlined /> : <Favorite />}>
|
||||
{isMovieFavorited ? 'Unfavorite' : 'Favorite'}
|
||||
</Button>
|
||||
<Button onClick={addToWatchList} endIcon={isMovieWatchlisted ? <Remove /> : <PlusOne />}>
|
||||
Watchlist
|
||||
</Button>
|
||||
<Button endIcon={<ArrowBack />} sx={{ borderColor: 'primary.main' }}>
|
||||
<Typography variant="subtitle2" component={Link} to="/" color="inherit" sx={{ textDecoration: 'none' }}>
|
||||
Back
|
||||
</Typography>
|
||||
</Button>
|
||||
</ButtonGroup>
|
||||
</Grid>
|
||||
</div>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Box marginTop="5rem" width="100%">
|
||||
<Typography variant="h3" gutterBottom align="center">
|
||||
You might also like
|
||||
</Typography>
|
||||
{recommendations
|
||||
? <MovieList movies={recommendations} numberOfMovies={12} />
|
||||
: <Box>Sorry, nothing was found.</Box>}
|
||||
</Box>
|
||||
<Modal
|
||||
closeAfterTransition
|
||||
className={classes.modal}
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
>
|
||||
{data?.videos?.results?.length > 0 && (
|
||||
<iframe
|
||||
autoPlay
|
||||
className={classes.video}
|
||||
frameBorder="0"
|
||||
title="Trailer"
|
||||
src={`https://www.youtube.com/embed/${data.videos.results[0].key}`}
|
||||
allow="autoplay"
|
||||
/>
|
||||
)}
|
||||
</Modal>
|
||||
</Grid>
|
||||
);
|
||||
}
|
||||
|
||||
export default MovieInfo;
|
||||
@@ -0,0 +1,75 @@
|
||||
import { makeStyles } from '@mui/styles';
|
||||
|
||||
export default makeStyles((theme) => ({
|
||||
containerSpaceAround: {
|
||||
display: 'flex',
|
||||
justifyContent: 'space-around',
|
||||
margin: '10px 0 !important',
|
||||
[theme.breakpoints.down('sm')]: {
|
||||
flexDirection: 'column',
|
||||
flexWrap: 'wrap',
|
||||
},
|
||||
},
|
||||
poster: {
|
||||
borderRadius: '20px',
|
||||
boxShadow: '0.5em 1em 1em rgb(64, 64, 70)',
|
||||
width: '80%',
|
||||
[theme.breakpoints.down('md')]: {
|
||||
margin: '0 auto !imporatant',
|
||||
width: '50%',
|
||||
},
|
||||
[theme.breakpoints.down('sm')]: {
|
||||
margin: '0 auto !imporatant',
|
||||
width: '100%',
|
||||
height: '350px',
|
||||
marginBottom: '30px',
|
||||
},
|
||||
},
|
||||
genresContainer: {
|
||||
margin: '10px 0 !imaportant',
|
||||
display: 'flex',
|
||||
justifyContent: 'space-around',
|
||||
flexWrap: 'wrap',
|
||||
},
|
||||
genreImage: {
|
||||
filter: theme.palette.mode === 'dark' && 'invert(1)',
|
||||
marginRight: '10px',
|
||||
},
|
||||
links: {
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
textDecoration: 'none',
|
||||
[theme.breakpoints.down('sm')]: {
|
||||
padding: '0.5rem 1rem',
|
||||
},
|
||||
},
|
||||
castImage: {
|
||||
width: '100%',
|
||||
maxWidth: '7em',
|
||||
height: '8em',
|
||||
objectFit: 'cover',
|
||||
borderRadius: '10px',
|
||||
},
|
||||
buttonContainer: {
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
width: '100%',
|
||||
[theme.breakpoints.down('sm')]: {
|
||||
flexDirection: 'column',
|
||||
},
|
||||
},
|
||||
modal: {
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
},
|
||||
video: {
|
||||
width: '50%',
|
||||
height: '50%',
|
||||
[theme.breakpoints.down('sm')]: {
|
||||
width: '90%',
|
||||
height: '90%',
|
||||
},
|
||||
},
|
||||
}));
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Grid } from '@mui/material';
|
||||
|
||||
import useStyles from './styles';
|
||||
import { Movie } from '../index';
|
||||
|
||||
function MovieList({ movies, numberOfMovies, excludeFirst }) {
|
||||
const classes = useStyles();
|
||||
const startFrom = excludeFirst ? 1 : 0;
|
||||
|
||||
return (
|
||||
<Grid container className={classes.moviesContainer}>
|
||||
{movies.results.slice(startFrom, numberOfMovies).map((movie, i) => (
|
||||
<Movie key={i} movie={movie} i={i} />
|
||||
))}
|
||||
</Grid>
|
||||
);
|
||||
}
|
||||
|
||||
export default MovieList;
|
||||
@@ -0,0 +1,13 @@
|
||||
import { makeStyles } from '@mui/styles';
|
||||
|
||||
export default makeStyles((theme) => ({
|
||||
movieContainer: {
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
overflow: 'auto',
|
||||
flexWrap: 'wrap',
|
||||
[theme.breakpoints.down('sm')]: {
|
||||
justifyContent: 'center',
|
||||
},
|
||||
},
|
||||
}));
|
||||
@@ -0,0 +1,47 @@
|
||||
import { useState } from 'react';
|
||||
import { Box, CircularProgress, useMediaQuery, Typography } from '@mui/material';
|
||||
import { useSelector } from 'react-redux';
|
||||
|
||||
import { MovieList, Pagination, FeaturedMovie } from '../index';
|
||||
import { useGetMoviesQuery } from '../../services/TMDB';
|
||||
|
||||
function Movies() {
|
||||
const [page, setPage] = useState(1);
|
||||
const { genreIdOrCategoryName, searchQuery } = useSelector((state) => state.currentGenreOrCategory);
|
||||
const { data, error, isFetching } = useGetMoviesQuery({ genreIdOrCategoryName, page, searchQuery });
|
||||
|
||||
const lg = useMediaQuery((theme) => theme.breakpoints.only('lg'));
|
||||
const numberOfMovies = lg ? 17 : 19;
|
||||
|
||||
if (isFetching) {
|
||||
return (
|
||||
<Box display="flex" justifyContent="center">
|
||||
<CircularProgress size="4rem" />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
if (!data.results.length) {
|
||||
return (
|
||||
<Box display="flex" justifyContent="center" alignItems="center" mt="20px">
|
||||
<Typography variant="h4">
|
||||
No movies that match that name.
|
||||
<br />
|
||||
Please searh for something else.
|
||||
</Typography>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) return 'An error has occured.';
|
||||
|
||||
return (
|
||||
<div>
|
||||
<FeaturedMovie movie={data.results[0]} />
|
||||
<MovieList movies={data} numberOfMovies={numberOfMovies} excludeFirst />
|
||||
<Pagination currentPage={page} setPage={setPage} totalPages={data.total_pages} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Movies;
|
||||
@@ -0,0 +1,115 @@
|
||||
import { useState, useEffect, useContext } from 'react';
|
||||
import { AppBar, IconButton, Toolbar, Drawer, Button, Avatar, useMediaQuery } from '@mui/material';
|
||||
import { Menu, AccountCircle, Brightness4, Brightness7 } from '@mui/icons-material';
|
||||
import { useTheme } from '@mui/material/styles';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
|
||||
import useStyles from './styles';
|
||||
import { Search, Sidebar } from '../index';
|
||||
import { setUser } from '../../features/auth';
|
||||
import { fetchToken, createSessionId, moviesApi } from '../../utils/index';
|
||||
import { ColorModeContext } from '../../utils/ToggleColorMode';
|
||||
|
||||
function Navbar() {
|
||||
const classes = useStyles();
|
||||
const isMobile = useMediaQuery('(max-width:600px)');
|
||||
const theme = useTheme();
|
||||
const dispatch = useDispatch();
|
||||
const { isAuthenticated, user } = useSelector((state) => state.user);
|
||||
const [mobileOpen, setMobileOpen] = useState(false);
|
||||
|
||||
const colorMode = useContext(ColorModeContext);
|
||||
|
||||
const token = localStorage.getItem('request_token');
|
||||
const sessionIdFromLocalStorage = localStorage.getItem('session_id');
|
||||
|
||||
useEffect(() => {
|
||||
const logInUser = async () => {
|
||||
if (token) {
|
||||
if (sessionIdFromLocalStorage) {
|
||||
const { data: userData } = await moviesApi.get(`/account?session_id=${sessionIdFromLocalStorage}`);
|
||||
dispatch(setUser(userData));
|
||||
} else {
|
||||
const sessionId = await createSessionId();
|
||||
const { data: userData } = await moviesApi.get(`/account?session_id=${sessionId}`);
|
||||
dispatch(setUser(userData));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
logInUser();
|
||||
}, [token]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<AppBar position="fixed">
|
||||
<Toolbar className={classes.toolbar}>
|
||||
{isMobile && (
|
||||
<IconButton
|
||||
color="inherit"
|
||||
edge="start"
|
||||
style={{ outline: 'none' }}
|
||||
onClick={() => setMobileOpen((prevMobileOpen) => !prevMobileOpen)}
|
||||
className={classes.menuButton}
|
||||
>
|
||||
<Menu />
|
||||
</IconButton>
|
||||
)}
|
||||
<IconButton
|
||||
color="inherit"
|
||||
sx={{ ml: 1 }}
|
||||
onClick={colorMode.toggleColorMode}
|
||||
>
|
||||
{theme.palette.mode === 'dark' ? <Brightness7 /> : <Brightness4 />}
|
||||
</IconButton>
|
||||
{!isMobile && <Search />}
|
||||
<div>
|
||||
{!isAuthenticated ? (
|
||||
<Button color="inherit" onClick={fetchToken}>
|
||||
Login <AccountCircle />
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
color="inherit"
|
||||
component={Link}
|
||||
to={`/profile/${user.id}`}
|
||||
className={classes.linkButton}
|
||||
>
|
||||
{!isMobile && <>My Movies </>}
|
||||
<Avatar
|
||||
style={{ width: 30, height: 30 }}
|
||||
alt="Profile"
|
||||
src={`https://www.themoviedb.org/t/p/w64_and_h64_face${user?.avatar?.tmdb?.avatar?.avatar_path}`}
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{isMobile && <Search />}
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
<div>
|
||||
<nav className={classes.drawer}>
|
||||
{isMobile ? (
|
||||
<Drawer
|
||||
variant="temporary"
|
||||
anchor="left"
|
||||
open={mobileOpen}
|
||||
onClose={() => setMobileOpen((prevMobileOpen) => !prevMobileOpen)}
|
||||
classes={{ paper: classes.drawerPaper }}
|
||||
ModalProps={{ keepMounted: true }}
|
||||
>
|
||||
<Sidebar setMobileOpen={setMobileOpen} />
|
||||
</Drawer>
|
||||
) : (
|
||||
<Drawer classes={{ paper: classes.drawerPaper }} variant="permanent" open>
|
||||
<Sidebar setMobileOpen={setMobileOpen} />
|
||||
</Drawer>
|
||||
)}
|
||||
</nav>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Navbar;
|
||||
@@ -0,0 +1,37 @@
|
||||
import { makeStyles } from '@mui/styles';
|
||||
|
||||
const drawerWidth = 240;
|
||||
|
||||
export default makeStyles((theme) => ({
|
||||
toolbar: {
|
||||
height: '80px',
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
marginLeft: '240px',
|
||||
[theme.breakpoints.down('sm')]: {
|
||||
marginLeft: 0,
|
||||
flexWrap: 'wrap',
|
||||
},
|
||||
},
|
||||
menuButton: {
|
||||
marginRight: theme.spacing(2),
|
||||
[theme.breakpoints.up('sm')]: {
|
||||
display: 'none',
|
||||
},
|
||||
},
|
||||
drawer: {
|
||||
[theme.breakpoints.up('sm')]: {
|
||||
width: drawerWidth,
|
||||
flexShrink: 0,
|
||||
},
|
||||
},
|
||||
drawerPaper: {
|
||||
width: drawerWidth,
|
||||
},
|
||||
linkButton: {
|
||||
'&:hover': {
|
||||
color: 'white !important',
|
||||
textDecoration: 'none',
|
||||
},
|
||||
},
|
||||
}));
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Typography, Button } from '@mui/material';
|
||||
|
||||
import useStyles from './styles';
|
||||
|
||||
function Pagination({ currentPage, setPage, totalPages }) {
|
||||
const classes = useStyles();
|
||||
|
||||
const handlePrev = () => {
|
||||
if (currentPage !== 1) { setPage((prevPage) => prevPage - 1); }
|
||||
};
|
||||
const handleNext = () => {
|
||||
if (currentPage !== totalPages) { setPage((prevPage) => prevPage + 1); }
|
||||
};
|
||||
|
||||
if (totalPages === 0) return null;
|
||||
|
||||
return (
|
||||
<div className={classes.container}>
|
||||
<Button onClick={handlePrev} variant="contained" className={classes.button} color="primary" type="button">Prev</Button>
|
||||
<Typography variant="h4" className={classes.pageNumber}>{currentPage}</Typography>
|
||||
<Button onClick={handleNext} variant="contained" className={classes.button} color="primary" type="button">Next</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Pagination;
|
||||
@@ -0,0 +1,16 @@
|
||||
import { makeStyles } from '@mui/styles';
|
||||
|
||||
export default makeStyles((theme) => ({
|
||||
container: {
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
},
|
||||
button: {
|
||||
margin: '30px 2px',
|
||||
},
|
||||
pageNumber: {
|
||||
margin: '0 20px !important',
|
||||
color: theme.palette.text.primary,
|
||||
},
|
||||
}));
|
||||
@@ -0,0 +1,44 @@
|
||||
import { useEffect } from 'react';
|
||||
import { Box, Button, Typography } from '@mui/material';
|
||||
import { ExitToApp } from '@mui/icons-material';
|
||||
import { useSelector } from 'react-redux';
|
||||
|
||||
import { useGetListQuery } from '../../services/TMDB';
|
||||
import { RatedCards } from '../index';
|
||||
|
||||
function Profile() {
|
||||
const { user } = useSelector((state) => state.user);
|
||||
const { data: favoriteMovies, refetch: refetchFavorites } = useGetListQuery({ listName: 'favorite/movies', accountId: user.id, sessionId: localStorage.getItem('session_id'), page: 1 });
|
||||
const { data: watchlistMovies, refetch: refetchWatchlisted } = useGetListQuery({ listName: 'watchlist/movies', accountId: user.id, sessionId: localStorage.getItem('session_id'), page: 1 });
|
||||
|
||||
useEffect(() => {
|
||||
refetchFavorites();
|
||||
refetchWatchlisted();
|
||||
}, []);
|
||||
|
||||
const logout = () => {
|
||||
localStorage.clear();
|
||||
window.location.href = '/';
|
||||
};
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Box display="flex" justifyContent="space-between">
|
||||
<Typography variant="h4" gutterBottom>My Profile</Typography>
|
||||
<Button color="inherit" onClick={logout}>
|
||||
Logout <ExitToApp />
|
||||
</Button>
|
||||
</Box>
|
||||
{!favoriteMovies?.results?.length && !watchlistMovies?.results?.length
|
||||
? <Typography variant="h5">Add favourite or watchlist same movies to see them here!</Typography>
|
||||
: (
|
||||
<Box>
|
||||
<RatedCards title="Favorite Movies" movies={favoriteMovies} />
|
||||
<RatedCards title="Watchlist" movies={watchlistMovies} />
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default Profile;
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Typography, Box } from '@mui/material';
|
||||
|
||||
import useStyles from './styles';
|
||||
import { Movie } from '../index';
|
||||
|
||||
function RatedCards({ title, movies }) {
|
||||
const classes = useStyles();
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Typography variant="h5" gutterBottom>{title}</Typography>
|
||||
<Box display="flex" flexWrap="wrap" className={classes.container}>
|
||||
{movies?.results.map((movie, i) => (
|
||||
<Movie key={movie.id} movie={movie} i={i} />
|
||||
))}
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default RatedCards;
|
||||
@@ -0,0 +1,7 @@
|
||||
import { makeStyles } from '@mui/styles';
|
||||
|
||||
export default makeStyles(() => ({
|
||||
container: {
|
||||
margin: '20px 0',
|
||||
},
|
||||
}));
|
||||
@@ -0,0 +1,13 @@
|
||||
import { useState} from "react";
|
||||
import { TextField, InputAdornment } from '@mui/material';
|
||||
import { Search as SearchIcon } from '@mui/icons-material';
|
||||
|
||||
import useStyles from './styles';
|
||||
|
||||
function Search() {
|
||||
return (
|
||||
<></>
|
||||
)
|
||||
}
|
||||
|
||||
export default Search;
|
||||
@@ -0,0 +1,19 @@
|
||||
import { makeStyles } from '@mui/styles';
|
||||
|
||||
export default makeStyles((theme) => ({
|
||||
searchContainer: {
|
||||
[theme.breakpoints.down('sm')]: {
|
||||
display: 'flex',
|
||||
justifyContainer: 'center',
|
||||
width: '100%',
|
||||
},
|
||||
},
|
||||
input: {
|
||||
color: theme.palette.mode === 'light' && 'dark',
|
||||
filter: theme.palette.mode === 'light' && 'invert(1)',
|
||||
[theme.breakpoints.down('sm')]: {
|
||||
marginTop: '-10px',
|
||||
marginBottom: '10px',
|
||||
},
|
||||
},
|
||||
}));
|
||||
@@ -0,0 +1,78 @@
|
||||
import { useEffect } from 'react';
|
||||
import { Divider, List, ListItem, ListItemText, ListSubheader, ListItemIcon, Box, CircularProgress } from '@mui/material';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { useTheme } from '@mui/styles';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
|
||||
import useStyles from './styles';
|
||||
import { useGetGenresQuery } from '../../services/TMDB';
|
||||
import { selectGenreOrCategory } from '../../features/currentGenreOrCategory';
|
||||
import genreIcons from '../../assets/genres';
|
||||
|
||||
const redLogo = 'https://fontmeme.com/permalink/210930/8531c658a743debe1e1aa1a2fc82006e.png';
|
||||
const blueLogo = 'https://fontmeme.com/permalink/210930/6854ae5c7f76597cf8680e48a2c8a50a.png';
|
||||
|
||||
const categories = [
|
||||
{ label: 'Popular', value: 'popular' },
|
||||
{ label: 'Top Rated', value: 'top_rated' },
|
||||
{ label: 'Upcoming', value: 'upcoming' },
|
||||
];
|
||||
|
||||
function Sidebar({ setMobileOpen }) {
|
||||
const theme = useTheme();
|
||||
const classes = useStyles();
|
||||
const dispatch = useDispatch();
|
||||
const { data, isFetching } = useGetGenresQuery();
|
||||
const { genreIdOrCategoryName } = useSelector((state) => state.currentGenreOrCategory);
|
||||
|
||||
useEffect(() => {
|
||||
setMobileOpen(false);
|
||||
}, [genreIdOrCategoryName]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Link to="/" className={classes.imageLink}>
|
||||
<img
|
||||
className={classes.image}
|
||||
src={theme.palette.mode === 'light' ? redLogo : blueLogo}
|
||||
alt="Filmpire Logo"
|
||||
/>
|
||||
</Link>
|
||||
<Divider />
|
||||
<List>
|
||||
<ListSubheader>Categories</ListSubheader>
|
||||
{categories.map(({ label, value }) => (
|
||||
<Link key={value} className={classes.links} to="/">
|
||||
<ListItem button onClick={() => dispatch(selectGenreOrCategory(value))}>
|
||||
<ListItemIcon>
|
||||
<img src={genreIcons[label.toLowerCase()]} className={classes.genreImages} height={30} />
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={label} />
|
||||
</ListItem>
|
||||
</Link>
|
||||
))}
|
||||
</List>
|
||||
<Divider />
|
||||
<List>
|
||||
<ListSubheader>Genres</ListSubheader>
|
||||
{isFetching ? (
|
||||
<Box display="flex" justifyContent="center">
|
||||
<CircularProgress size="4rem" />
|
||||
</Box>
|
||||
)
|
||||
: data?.genres?.map(({ name, id }) => (
|
||||
<Link key={name} className={classes.links} to="/">
|
||||
<ListItem button onClick={() => dispatch(selectGenreOrCategory(id))}>
|
||||
<ListItemIcon>
|
||||
<img src={genreIcons[name.toLowerCase()]} className={classes.genreImages} height={30} />
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={name} />
|
||||
</ListItem>
|
||||
</Link>
|
||||
))}
|
||||
</List>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Sidebar;
|
||||
@@ -0,0 +1,23 @@
|
||||
import { makeStyles } from '@mui/styles';
|
||||
|
||||
export default makeStyles((theme) => ({
|
||||
imageLink: {
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
padding: '10% 0',
|
||||
},
|
||||
image: {
|
||||
width: '70%',
|
||||
},
|
||||
links: {
|
||||
color: theme.palette.text.primary,
|
||||
textDecoration: 'none',
|
||||
},
|
||||
genreImages: {
|
||||
filter: theme.palette.mode === 'dark' ? 'invert(1)' : 'dark',
|
||||
},
|
||||
bigText: {
|
||||
color: 'primary',
|
||||
fontSize: 30,
|
||||
},
|
||||
}));
|
||||
@@ -0,0 +1,12 @@
|
||||
export { default as Actors } from './Actors/Actors';
|
||||
export { default as Movies } from './Movies/Movies';
|
||||
export { default as MovieInfo } from './MovieInfo/MovieInfo';
|
||||
export { default as Profile } from './Profile/Profile';
|
||||
export { default as Navbar } from './Navbar/Navbar';
|
||||
export { default as Sidebar } from './Sidebar/Sidebar';
|
||||
export { default as MovieList } from './MovieList/MovieList';
|
||||
export { default as Movie } from './Movie/Movie';
|
||||
export { default as Search } from './Search/Search';
|
||||
export { default as Pagination } from './Pagination/Pagination';
|
||||
export { default as RatedCards } from './RatedCards/RatedCards';
|
||||
export { default as FeaturedMovie } from './FeaturedMovie/FeaturedMovie';
|
||||
@@ -0,0 +1,15 @@
|
||||
import { makeStyles } from '@mui/styles';
|
||||
|
||||
export default makeStyles(() => ({
|
||||
root: {
|
||||
display: 'flex',
|
||||
height: '100%',
|
||||
},
|
||||
content: {
|
||||
flexGrow: 1,
|
||||
padding: '6em 2em 2em',
|
||||
},
|
||||
toolkit: {
|
||||
height: '70px',
|
||||
},
|
||||
}));
|
||||
Reference in new issue
Block a user