diff --git a/.gitignore b/.gitignore index a547bf36..7ceb59f8 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ dist-ssr *.njsproj *.sln *.sw? +.env diff --git a/README.md b/README.md index f768e33f..6ab14f11 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,129 @@ -# React + Vite +## Unit Assignment: Flixster -This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. +Submitted by: **Jackson Seifferly** -Currently, two official plugins are available: +Estimated time spent: **20** hours spent in total -- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh -- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh +Deployed Application (**required**): [https://flixster-bs8p.onrender.com/] + +### Application Features + +#### REQUIRED FEATURES + +- [x] **Display Movies** + - [x] Users can view a list of current movies from The Movie Database API in a grid view. + - [x] Movie tiles should be reasonably sized (at least 6 playlists on your laptop when full screen; large enough that the playlist components detailed in the next feature are legible). + - [x] For each movie displayed, users can see the movie's: + - [x] Title + - [x] Poster image + - [x] Vote average + - [x] Users can load more current movies by clicking a button which adds more movies to the grid without reloading the entire page. +- [x] **Search Functionality** + - [x] Users can use a search bar to search for movies by title. + - [x] The search bar should include: + - [x] Text input field + - [x] Submit/Search button + - [x] Clear button + - [x] Movies with a title containing the search query in the text input field are displayed in a grid view when the user either: + - [x] Presses the Enter key + - [x] Clicks the Submit/Search button + - [x] Users can click the Clear button. When clicked: + - [x] Most recent search results are cleared from the text input field and the grid view and all current movies are displayed in a grid view +- [x] **Design Features** + - [x] Website implements all of the following accessibility features: + - [x] Semantic HTML + - [x] [Color contrast](https://webaim.org/resources/contrastchecker/) + - [x] Alt text for images + - [x] Website implements responsive web design. + - [x] Uses CSS Flexbox or CSS Grid + - [x] Movie tiles and images shrink/grow in response to window size + - [x] Users can click on a movie tile to view more details about a movie in a pop-up modal. + - [x] The pop-up window is centered in the screen and does not occupy the entire screen. + - [x] The pop-up window has a shadow to show that it is a pop-up and appears floating on the screen. + - [x] The backdrop of the pop-up appears darker or in a different shade than before. including: + - [x] The pop-up displays additional details about the moving including: + - [x] Runtime in minutes + - [x] Backdrop poster + - [x] Release date + - [x] Genres + - [x] An overview + - [x] Users can use a drop-down menu to sort movies. + - [x] Drop-down allows movies to be sorted by: + - [x] Title (alphabetic, A-Z) + - [x] Release date (chronologically, most recent to oldest) + - [x] Vote average (descending, highest to lowest) + - [x] When a sort option is clicked, movies display in a grid according to selected criterion. + - [x] Website displays: + - [x] Header section + - [x] Banner section + - [x] Search bar + - [x] Movie grid + - [x] Footer section + - [x] **VIDEO WALKTHROUGH SPECIAL INSTRUCTIONS**: To ease the grading process, please use the [color contrast checker](https://webaim.org/resources/contrastchecker/) to demonstrate to the grading team that text and background colors on your website have appropriate contrast. The Contrast Ratio should be above 4.5:1 and should have a green box surrounding it. + - [x] **Deployment** + - [x] Website is deployed via Render. + - [x] **VIDEO WALKTHROUGH SPECIAL INSTRUCTIONS**: For ease of grading, please use the deployed version of your website when creating your walkthrough. + +#### STRETCH FEATURES + + +- [x] **Embedded Movie Trailers** + - [x] Within the pop-up modal displaying a movie's details, the movie trailer is viewable. + -[x] When the trailer is clicked, users can play the movie trailer. +- [x] **Favorite Button** + - [x] For each movie displayed, users can favorite the movie. + - [x] There should be visual element (such as a heart icon) on each movie's tile to show whether or not the movie has been favorited. + - [x] If the movie is not favorited: + - [x] Clicking on the visual element should mark the movie as favorited + - [x] There should be visual feedback (such as the heart turning a different color) to show that the movie has been favorited by the user. + - [x] If the movie is already favorited: + - [x] Clicking on the visual element should mark the movie as *not* favorited. + - [x] There should be visual feedback (such as the heart turning a different color) to show that the movie has been unfavorited. +- [x] **Watched Checkbox** + - [x] For each movie displayed, users can mark the movie as watched. + - [x] There should be visual element (such as an eye icon) on each movie's tile to show whether or not the movie has been watched. + - [x] If the movie has not been watched: + - [x] Clicking on the visual element should mark the movie as watched + - [x] There should be visual feedback (such as the eye turning a different color) to show that the movie has been watched by the user. + - [x] If the movie is already watched: + - [x] Clicking on the visual element should mark the movie as *not* watched. + - [x] There should be visual feedback (such as the eye turning a different color) to show that the movie has not been watched. +- [x] **Sidebar** + - [x] The website includes a side navigation bar. + - [x] The sidebar has three pages: + - [x] Home + - [x] Favorites + - [x] Watched + - [x] The Home page displays all current movies in a grid view, the search bar, and the sort movies drop-down. + - [x] The Favorites page displays all favorited movies in a grid view. + - [x] The Watched page displays all watched movies in a grid view. + +### Walkthrough Video + +[(https://www.loom.com/share/c29c8d99c6b341ce9b32ac4571128836?sid=e821737c-e09b-48e1-9be8-35ce3c17b324)] + +### Reflection + +* Did the topics discussed in your labs prepare you to complete the assignment? Be specific, which features in your weekly assignment did you feel unprepared to complete? + +I felt that almost all of the features that we had to implement in the project were covered by ideas in the labs, I found myself constantly looking back at past labs to refrence code I wrote there for my project. The only thing I felt a little unprepared for was the video embedding but with a bit of web searching it was actually relativly simple to implement. + +* If you had more time, what would you have done differently? Would you have added additional features? Changed the way your project responded to a particular event, etc. + +If I had more time I wish I could add more features to the site, maybe a list of theaters in the area playing the movie for each movie. And maybe some more filtering options for the type of search you can perform, like search for movies within a particular year or by rating. + +* Reflect on your project demo, what went well? Were there things that maybe didn't go as planned? Did you notice something that your peer did that you would like to try next time? + +Talking with my peers a big thing I noticed was that a lot of people started the project by implementing some of the smaller features that were less code intensive which helped them quickly understand the layout of their project and how components would communicate with each other. I started with one of the bigger features which required a lot of inter-connected components which made it hard initially to figure out how the app features would communicate. + +### Open-source libraries used + +- Add any links to open-source libraries used in your project. + +### Shout out + +Give a shout out to somebody from your cohort that especially helped you during your project. This can be a fellow peer, instructor, TA, mentor, etc. + +- First shout out to bravemaster619 at [https://dev.to/bravemaster619/simplest-way-to-embed-a-youtube-video-in-your-react-app-3bk2] for his very good guide on embedding youtube video saved me a lot of headache + +- Shout out to my table mates again Ben, Kevin, and Thomas who all helped me bounce ideas of them and compare our features. \ No newline at end of file diff --git a/src/App.jsx b/src/App.jsx index dfa91584..335311ad 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,10 +1,157 @@ -import { useState } from 'react' +import { useState, useEffect } from 'react' +import Header from './Header' +import Body from './Body' +import SideNav from './components/SideNav' +import Footer from './Footer' +import sort from './utils/utils' import './App.css' +//API Info for fetch +const API_KEY = import.meta.env.VITE_API_KEY +const options = {method: 'GET', headers: {accept: 'application/json', + Authorization: `Bearer ${API_KEY}`}} + const App = () => { + //States to store the current movie data + const [movieData, setMovieData] = useState([]) + const [pageNum, setPageNum] = useState(1) + + //State Arrays for fav and watched movies + const [page,setPage] = useState('Home') + const [favMovies, setFavMovies] = useState([]) + const [watchedMovies, setWatchedMovies] = useState([]) + + //States to store search information + const [searchData, setSearchData] = useState([]) + const [searchPage, setSearchPage] = useState(0) + const [searchString, setSearchString] = useState('') + const [searchTrigger, setSearchTrigger] = useState(0) + + //URL for featching data from API + const nowPlayingURL = `https://api.themoviedb.org/3/movie/now_playing?language=en-US&page=${pageNum}` + const searchURL = `https://api.themoviedb.org/3/search/movie?query=${searchString}&page=${searchPage}` + + //States for sort + const [sortType, setSortType] = useState('none') + + //Rerender movie data whenever url for api call changed and append to movie data + useEffect(() => { + const fetchMovieData = async () => { + try{ + let searching = (searchString !== ''); + let URL = searching ? searchURL : nowPlayingURL; + var res = await fetch(URL, options) + if(res.ok){ + const data = await res.json(); + + //Update movie data to store liked/watched info + data.results.forEach((movie) => { + movie.liked = false + movie.watched = false + }) + + if(searchString === ''){ + setMovieData([...movieData, ...data.results]); + }else { + setSearchData([...searchData, ...data.results]) + } + }else{ + throw new Error("API Not Responding") + } + }catch(error){ + console.error("Error: ", error.message) + } + } + fetchMovieData(); + },[pageNum, searchTrigger]) + + //Load more movie data by updating page num on url + const load = () => { + if(searchString === '') { + setPageNum(pageNum + 1) + }else { + setSearchPage(searchPage + 1) + setSearchTrigger(searchTrigger + 1) + } + } + + //**-----------------Search Function-----------------**// + const clearSearch = () => { + setSearchData([]) + setSearchString('') + setPage('Home') + } + + const search = () => { + if(searchString === ''){ + return; + } + setSearchPage(1, setPage('Search')) + setSearchTrigger(searchTrigger + 1) + } + + const updateSearchTerm = evt => { + setSearchString(evt.target.value) + } + //**--------------------------------------------------**// + + //**------------------Sort Function-------------------**// + + useEffect(() => { + const sortedMovies = sort(movieData,sortType) + setMovieData(sortedMovies) + },[sortType]) + + + const updateSortType = evt => { + setSortType(evt.target.value) + } + + //**--------------------------------------------------**// + + //**---------------Like/Watch Function----------------**// + + const openHome = () => { + setPage('Home') + } + + const updateFavs = (movie) => { + if(movie.liked){ + setFavMovies([...favMovies, movie]) + }else{ + setFavMovies(favMovies.filter(element => element !== movie)); + } + } + + const openFavorites = () => { + setPage('Favorites') + } + + const updateWatched = (movie) => { + if(movie.watched){ + setWatchedMovies([...watchedMovies, movie]) + }else{ + setWatchedMovies(watchedMovies.filter(element => element !== movie)); + } + } + + const openWatched = () => { + setPage('Watched') + } + + //**--------------------------------------------------**// + return (
- +
+ + + + + +
) } diff --git a/src/Body.css b/src/Body.css new file mode 100644 index 00000000..45179581 --- /dev/null +++ b/src/Body.css @@ -0,0 +1,6 @@ +.Body { + background-color: #1C1C1C; + color: #f0ffff; + + min-height: 100vh; +} \ No newline at end of file diff --git a/src/Body.jsx b/src/Body.jsx new file mode 100644 index 00000000..c2ec6de3 --- /dev/null +++ b/src/Body.jsx @@ -0,0 +1,11 @@ +import MovieList from "./components/MovieList"; +import './Body.css' + +export default function Body({data, load, addToFav, addToWatch, display}) { + + return ( +
+ +
+ ); +} \ No newline at end of file diff --git a/src/Footer.css b/src/Footer.css new file mode 100644 index 00000000..c59d3798 --- /dev/null +++ b/src/Footer.css @@ -0,0 +1,6 @@ +.Footer { + background-color: #5AE26A; + color: #1C1C1C; + + margin-top: auto; +} diff --git a/src/Footer.jsx b/src/Footer.jsx new file mode 100644 index 00000000..ac79b7aa --- /dev/null +++ b/src/Footer.jsx @@ -0,0 +1,10 @@ +import './Footer.css' + +export default function Footer() { + + return ( +
+

@https://github.com/jseifferly/flixster

+
+ ); +} diff --git a/src/Header.css b/src/Header.css new file mode 100644 index 00000000..b16c4f66 --- /dev/null +++ b/src/Header.css @@ -0,0 +1,8 @@ +.Header { + background-color: #5AE26A; + color: #1C1C1C; +} + +.Header h1 { + font-size: 300%; +} \ No newline at end of file diff --git a/src/Header.jsx b/src/Header.jsx new file mode 100644 index 00000000..f91cf8c8 --- /dev/null +++ b/src/Header.jsx @@ -0,0 +1,13 @@ +import SearchForm from "./components/SearchForm"; +import './Header.css' + +export default function Header({search,clear,searchTermFunction,searchString, sortFunc, display}) { + return ( +
+

Flixster

+ +
+ ); +} \ No newline at end of file diff --git a/src/Sort.css b/src/Sort.css new file mode 100644 index 00000000..e9ee3e00 --- /dev/null +++ b/src/Sort.css @@ -0,0 +1,13 @@ +.Sort { + border-radius: 20px; + background-color: gray; + color: aliceblue; + + margin: 1vw; + padding: 0.5vw; +} + +.Sort:hover { + cursor: pointer; + background-color: rgb(144, 144, 144); +} \ No newline at end of file diff --git a/src/components/LoadButton.jsx b/src/components/LoadButton.jsx new file mode 100644 index 00000000..ae4bd399 --- /dev/null +++ b/src/components/LoadButton.jsx @@ -0,0 +1,10 @@ +import '../styles/LoadButton.css' + +export default function LoadButton() { + + return ( +
+ +
+ ); +} \ No newline at end of file diff --git a/src/components/Modal.jsx b/src/components/Modal.jsx new file mode 100644 index 00000000..caba9aaf --- /dev/null +++ b/src/components/Modal.jsx @@ -0,0 +1,22 @@ +import '../styles/Modal.css' +import '../styles/Close.css' +import MovieDetails from './MovieDetails'; + +export default function Modal({display, closeModal, movie}){ + + //Make sure modal doesn't close when content is clicked + const handleModalContentClicked = evt => { + evt.stopPropagation(); + } + + return ( +
+
+
+ X + +
+
+
+ ); +} \ No newline at end of file diff --git a/src/components/MovieButtons.jsx b/src/components/MovieButtons.jsx new file mode 100644 index 00000000..81b93b9f --- /dev/null +++ b/src/components/MovieButtons.jsx @@ -0,0 +1,23 @@ +import '../styles/MovieButtons.css' + +export default function MovieButtons({addToFav, addToWatched, movie}) { + + const updateFav= evt => { + evt.stopPropagation(); + movie.liked = !movie.liked + addToFav(movie) + } + + const updateWatch = evt => { + evt.stopPropagation(); + movie.watched = !movie.watched + addToWatched(movie) + } + + return ( +
+ {movie.liked ? '\u{1F49A}':'\u{1F90D}'} + {movie.watched ? '\u{2611}':'\u{2610}'} +
+ ); +} \ No newline at end of file diff --git a/src/components/MovieCard.jsx b/src/components/MovieCard.jsx new file mode 100644 index 00000000..61897909 --- /dev/null +++ b/src/components/MovieCard.jsx @@ -0,0 +1,17 @@ +import MovieButtons from './MovieButtons'; +import '../styles/MovieCard.css' + +const imgURL = 'https://image.tmdb.org/t/p' +const posterSize = '/w500' + +export default function MovieCard({loadModal, addToFavs, addToWatched, movie}) { + + return ( +
+ {movie.title +

{movie.title}

+

Rating: {movie.vote_average}

+ +
+ ); +} \ No newline at end of file diff --git a/src/components/MovieDetails.jsx b/src/components/MovieDetails.jsx new file mode 100644 index 00000000..54113511 --- /dev/null +++ b/src/components/MovieDetails.jsx @@ -0,0 +1,72 @@ +import { useState, useEffect } from "react"; +import YoutubeEmbed from './YoutubeEmbed' + +export default function MovieDetails({movie}) { + + const [movieDetails, setMovieDetails] = useState(null) + const [videoId, setVideoId] = useState('') + + //API Information for call to movie details + const url = `https://api.themoviedb.org/3/movie/${movie.id}?language=en-US`; + const videoUrl = `https://api.themoviedb.org/3/movie/${movie.id}/videos?language=en-US` + const API_KEY = import.meta.env.VITE_API_KEY + const options = {method: 'GET', headers: {accept: 'application/json', + Authorization: `Bearer ${API_KEY}`}} + + //Make API call for extra modal information + useEffect(() => { + const fetchMovieData = async () => { + if(movie.id === undefined){ + return + } + + try{ + var res1 = await fetch(url, options) + var res2 = await fetch(videoUrl, options) + if(res1.ok && res2.ok){ + const data = await res1.json(); + const vidData = await res2.json() + setMovieDetails(data); + const video = vidData.results.find(video => video.type === "Trailer") + setVideoId(video.key) + }else{ + throw new Error("API Not Responding") + } + }catch(error){ + console.error("Error: ", error.message) + } + } + fetchMovieData(); + },[movie]) + + + //Path info for movie posters + const imgURL = 'https://image.tmdb.org/t/p' + const posterSize = '/w500' + + //Function to turn genre array into a string varible + function genreString(genres) { + let ret = '' + for(var i = 0; i < genres.length; ++i){ + ret += (genres[i].name + ', ') + } + return ret.slice(0, -2) + } + + if(movieDetails === null){ + return(

Loading...

) + } + + return ( +
+

{movie.title}

+ {movie.title +

Release Date: {movie.release_date}

+

Overview: {movie.overview}

+

Genres: {genreString(movieDetails.genres)}

+

Runtime: {movieDetails.runtime} minutes

+ + +
+ ); +} \ No newline at end of file diff --git a/src/components/MovieList.jsx b/src/components/MovieList.jsx new file mode 100644 index 00000000..ba825f20 --- /dev/null +++ b/src/components/MovieList.jsx @@ -0,0 +1,39 @@ +import { useState } from "react"; +import Modal from "./Modal"; +import MovieCard from "./MovieCard"; +import '../styles/MovieList.css' +import '../styles/LoadButton.css' + +export default function MovieList({data,load,addToFav, addToWatch, display}) { + //Modal state data + const [mov, setMov] = useState({}) + const [show, setShow] = useState(false); + + const close = () => setShow(false); + const open = id => event => { + setMov(data.find(movie => movie.id === id)) + setShow(true); + } + + if(data.length > 0){ + return ( + <> +
+ {data.map((movie) => { + return + })} +
+ + + + ); + }else { + return ( +
+

No movies here...

+

{'\u{2639}'}

+
+ ); + } +} \ No newline at end of file diff --git a/src/components/SearchForm.jsx b/src/components/SearchForm.jsx new file mode 100644 index 00000000..8131beec --- /dev/null +++ b/src/components/SearchForm.jsx @@ -0,0 +1,20 @@ +import Sort from "./Sort"; +import '../styles/SearchForm.css' + +export default function SearchForm({display, searchFunction, clearFunction, searchTerm, searchTermFunc, sortFunc}) { + + const handleEnter = evt => { + if(evt.key === 'Enter'){ + searchFunction(); + } + } + + return ( +
+ + + + +
+ ); +} \ No newline at end of file diff --git a/src/components/SideNav.jsx b/src/components/SideNav.jsx new file mode 100644 index 00000000..9cc4b0a2 --- /dev/null +++ b/src/components/SideNav.jsx @@ -0,0 +1,12 @@ +import '../styles/SideNav.css' + +export default function SideNav({homeFunc,favFunc,watchFunc}) { + + return ( +
+

{"\u{1F3E0}"}

+

{"\u{1F31F}"}

+

{"\u{1F3C1}"}

+
+ ); +} \ No newline at end of file diff --git a/src/components/Sort.jsx b/src/components/Sort.jsx new file mode 100644 index 00000000..54a048c7 --- /dev/null +++ b/src/components/Sort.jsx @@ -0,0 +1,15 @@ +import '../styles/Sort.css' + +export default function Sort({sort}) { + + return ( +
+ +
+ ); +} \ No newline at end of file diff --git a/src/components/YoutubeEmbed.jsx b/src/components/YoutubeEmbed.jsx new file mode 100644 index 00000000..81eb5513 --- /dev/null +++ b/src/components/YoutubeEmbed.jsx @@ -0,0 +1,22 @@ +import '../styles/YoutubeEmbed.css' +import PropTypes from "prop-types"; + +const YoutubeEmbed = ({ embedId }) => ( +
+