From 40b3cf49f56dcb336465a613404c429a168748bb Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 11:13:49 -0700 Subject: [PATCH 01/66] doc: add BrowserRouter to main index file --- src/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 2cb1087..b6c3aee 100644 --- a/src/index.js +++ b/src/index.js @@ -1,11 +1,14 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; +import { BrowserRouter } from 'react-router-dom'; import './index.css'; -import App from './App'; +import App from './components/App'; const root = ReactDOM.createRoot(document.getElementById('root')); root.render( - - - + + + + + ); From 385b3b0e92a39de8932e82defb94fb1b2e287c3d Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 11:14:14 -0700 Subject: [PATCH 02/66] file: create components directory and add app.jsx into the directory --- src/{App.js => components/App.jsx} | 2 -- 1 file changed, 2 deletions(-) rename src/{App.js => components/App.jsx} (75%) diff --git a/src/App.js b/src/components/App.jsx similarity index 75% rename from src/App.js rename to src/components/App.jsx index ae86e51..28280a9 100644 --- a/src/App.js +++ b/src/components/App.jsx @@ -1,5 +1,3 @@ -import './App.css'; - function App() { return ( <> From e7a6717c47e019f012fbfabd0c99765005cd87d4 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 11:16:52 -0700 Subject: [PATCH 03/66] file: create styles.js and add @mui/styles within makeStyles --- src/styles.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/styles.js diff --git a/src/styles.js b/src/styles.js new file mode 100644 index 0000000..b4d4746 --- /dev/null +++ b/src/styles.js @@ -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', + }, +})); From 32090e4a617b0d300e2285ecf787736bf98f4221 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 11:18:29 -0700 Subject: [PATCH 04/66] file: remove App.css and index.css --- src/App.css | 38 -------------------------------------- src/index.css | 13 ------------- 2 files changed, 51 deletions(-) delete mode 100644 src/App.css delete mode 100644 src/index.css diff --git a/src/App.css b/src/App.css deleted file mode 100644 index 74b5e05..0000000 --- a/src/App.css +++ /dev/null @@ -1,38 +0,0 @@ -.App { - text-align: center; -} - -.App-logo { - height: 40vmin; - pointer-events: none; -} - -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } -} - -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; -} - -.App-link { - color: #61dafb; -} - -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} diff --git a/src/index.css b/src/index.css deleted file mode 100644 index ec2585e..0000000 --- a/src/index.css +++ /dev/null @@ -1,13 +0,0 @@ -body { - margin: 0; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', - 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', - sans-serif; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; -} - -code { - font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', - monospace; -} From f4674b516d53cc5a969965c220f73121d2af526c Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 11:19:54 -0700 Subject: [PATCH 05/66] file: create index.css with different styles --- src/index.css | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/index.css diff --git a/src/index.css b/src/index.css new file mode 100644 index 0000000..c5e3f73 --- /dev/null +++ b/src/index.css @@ -0,0 +1,15 @@ +::-webkit-scrollbar { + width: 7px; +} + +::-webkit-scrollbar-track { + background: #cfcfcf; +} + +::-webkit-scrollbar-thumb { + background: #a5a5a5; +} + +* { + text-decoration: none; +} \ No newline at end of file From 9b8e92cf23b80b7c72d03b0b999683879b0514c4 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 11:20:34 -0700 Subject: [PATCH 06/66] file: move styles.js from src directory into components directory --- src/{ => components}/styles.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{ => components}/styles.js (100%) diff --git a/src/styles.js b/src/components/styles.js similarity index 100% rename from src/styles.js rename to src/components/styles.js From 281b48d60a68abf210e7335c4c946fc3ae9d91dc Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 11:24:04 -0700 Subject: [PATCH 07/66] file: create index.js file in the components directory that contains all the export from the components directory --- src/components/index.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/components/index.js diff --git a/src/components/index.js b/src/components/index.js new file mode 100644 index 0000000..e69de29 From 79f313d4a8730cc13ad15d7059bccad3a5155a3d Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 11:29:25 -0700 Subject: [PATCH 08/66] file: create styles.js in Navbar directory --- src/components/Navbar/styles.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/components/Navbar/styles.js diff --git a/src/components/Navbar/styles.js b/src/components/Navbar/styles.js new file mode 100644 index 0000000..e69de29 From 9c11425609db6a2dcb2148a3756d8658953b9f5c Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 11:38:37 -0700 Subject: [PATCH 09/66] file: add ToggleColorMode component into utils directory --- src/utils/ToggleColorMode.jsx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/utils/ToggleColorMode.jsx diff --git a/src/utils/ToggleColorMode.jsx b/src/utils/ToggleColorMode.jsx new file mode 100644 index 0000000..b7d191d --- /dev/null +++ b/src/utils/ToggleColorMode.jsx @@ -0,0 +1,28 @@ +import { useState, useMemo, createContext } from 'react'; +import { ThemeProvider, createTheme } from "@mui/material/styles"; + +export const ColorModeContext = createContext(); + +function ToggleColorMode({ children }) { + const [mode, setMode] = useState('light'); + + const toggleColorMode = () => { + setMode((prevMode) => (prevMode === 'light' ? 'dark' : 'light')); + }; + + const theme = useMemo(() => createTheme({ + palette: { + mode, + }, + }), [mode]); + + return ( + + + {children} + + + ); +} + +export default ToggleColorMode; \ No newline at end of file From ee858f8aa41594c81527afafe61ea26e3099e554 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 11:42:46 -0700 Subject: [PATCH 10/66] doc: add styles into styles.js --- src/components/Navbar/styles.js | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/components/Navbar/styles.js b/src/components/Navbar/styles.js index e69de29..eb69bf1 100644 --- a/src/components/Navbar/styles.js +++ b/src/components/Navbar/styles.js @@ -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', + }, + }, +})); From c0345b9e85f4f9201e0ce50023625d2d51ad2a0f Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 11:53:07 -0700 Subject: [PATCH 11/66] file: create Search component in Search directory with its own stylesheet --- src/components/Search/Search.jsx | 13 +++++++++++++ src/components/Search/styles.js | 0 2 files changed, 13 insertions(+) create mode 100644 src/components/Search/Search.jsx create mode 100644 src/components/Search/styles.js diff --git a/src/components/Search/Search.jsx b/src/components/Search/Search.jsx new file mode 100644 index 0000000..4def947 --- /dev/null +++ b/src/components/Search/Search.jsx @@ -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; \ No newline at end of file diff --git a/src/components/Search/styles.js b/src/components/Search/styles.js new file mode 100644 index 0000000..e69de29 From ce47e04191ca0a03d2761c50e933ad466093f150 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 11:53:35 -0700 Subject: [PATCH 12/66] doc: add searchContainer and input styles into the stylesheet --- src/components/Search/styles.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/components/Search/styles.js b/src/components/Search/styles.js index e69de29..03682b2 100644 --- a/src/components/Search/styles.js +++ b/src/components/Search/styles.js @@ -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', + }, + }, +})); From 8cadd72b1818f81812b047289a407618ba94d826 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 11:56:57 -0700 Subject: [PATCH 13/66] doc: add ToogleColorMode from utils directory --- src/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index b6c3aee..c9181f9 100644 --- a/src/index.js +++ b/src/index.js @@ -1,14 +1,17 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; import { BrowserRouter } from 'react-router-dom'; -import './index.css'; +import ToggleColorMode from "./utils/ToggleColorMode"; import App from './components/App'; +import './index.css'; const root = ReactDOM.createRoot(document.getElementById('root')); root.render( + + ); From 8a9e92ea5a3673112e88db3dd6668d3ac4147fad Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:02:52 -0700 Subject: [PATCH 14/66] doc: add Navbar to component's main index file --- src/components/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/index.js b/src/components/index.js index e69de29..4b94a51 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -0,0 +1 @@ +export { default as Navbar } from './Navbar/Navbar'; From 4f9104e3a8f533c240e2e3f1e7c9bf195ada62dd Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:03:13 -0700 Subject: [PATCH 15/66] doc: add Search and Sidebar to component's main index file --- src/components/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/index.js b/src/components/index.js index 4b94a51..0b3d730 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -1 +1,3 @@ export { default as Navbar } from './Navbar/Navbar'; +export { default as Search } from './Search/Search'; +export { default as Sidebar } from './Sidebar/Sidebar'; \ No newline at end of file From 6d672f76d8651072c4d93671a8acdb96791cb014 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:05:50 -0700 Subject: [PATCH 16/66] doc: add navbar functions --- src/components/Navbar/Navbar.jsx | 73 ++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/components/Navbar/Navbar.jsx diff --git a/src/components/Navbar/Navbar.jsx b/src/components/Navbar/Navbar.jsx new file mode 100644 index 0000000..91ea5bb --- /dev/null +++ b/src/components/Navbar/Navbar.jsx @@ -0,0 +1,73 @@ +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 { ColorModeContext } from "../../utils/ToggleColorMode"; + +function Navbar() { + const classes = useStyles(); + const isMobile = useMediaQuery('(max-width:600px)'); + const theme = useTheme(); + + const [ mobileOpen, setMobileOpen ] = useState(false); + + const colorMode = useContext(ColorModeContext); + + const token = localStorage.getItem('request_token'); + const sessionIdFromLocalStorage = localStorage.getItem('session_id'); + + return( + <> + + + {isMobile && ( + setMobileOpen((prevMobileOpen) => !prevMobileOpen)} + className={classes.menuButton} + > + + + )} + + {theme.palette.mode === 'dark' ? : } + + {!isMobile && } + + +
+ +
+ + ) +} + +export default Navbar; \ No newline at end of file From 476d78b3b8e44b444b02da513bae5080991d56e3 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:07:08 -0700 Subject: [PATCH 17/66] file: create Sidebar directory with Sidebar component and its stylesheet --- src/components/Sidebar/Sidebar.jsx | 15 +++++++++++++++ src/components/Sidebar/styles.js | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/components/Sidebar/Sidebar.jsx create mode 100644 src/components/Sidebar/styles.js diff --git a/src/components/Sidebar/Sidebar.jsx b/src/components/Sidebar/Sidebar.jsx new file mode 100644 index 0000000..0c78fef --- /dev/null +++ b/src/components/Sidebar/Sidebar.jsx @@ -0,0 +1,15 @@ +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'; + +function Sidebar() { + return ( + <> + ) +} + +export default Sidebar; \ No newline at end of file diff --git a/src/components/Sidebar/styles.js b/src/components/Sidebar/styles.js new file mode 100644 index 0000000..e2103e0 --- /dev/null +++ b/src/components/Sidebar/styles.js @@ -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, + }, +})); From 1837dd18af4e8b1011a3dd61ae517e2018460977 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:08:02 -0700 Subject: [PATCH 18/66] doc: add App function with styles and components --- src/components/App.jsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index 28280a9..48232ea 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -1,6 +1,22 @@ +import { useRef } from 'react'; +import { CssBaseline} from "@mui/material"; +import { Routes, Route } from 'react-router-dom'; + +import useStyles from './styles' + +import { Navbar } from './index' + function App() { + const classes = useStyles(); return ( - <> +
+ + +
+
+
+
+
); } From f2dcbc88f4795768c421f29fa269b2e3204d666c Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:09:03 -0700 Subject: [PATCH 19/66] file: create store file in app directory --- src/app/store.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/app/store.js diff --git a/src/app/store.js b/src/app/store.js new file mode 100644 index 0000000..e69de29 From fcb9344b3ba3a81db200fc9dbd617953ac0cacfe Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:10:28 -0700 Subject: [PATCH 20/66] file: create services directory with TMDB api --- src/services/TMDB.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/services/TMDB.js diff --git a/src/services/TMDB.js b/src/services/TMDB.js new file mode 100644 index 0000000..e69de29 From e7486cf0c9d33085d86a53917dd3ef00a4053dd6 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:11:30 -0700 Subject: [PATCH 21/66] doc: add tmdbApi function --- src/services/TMDB.js | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/services/TMDB.js b/src/services/TMDB.js index e69de29..7187e66 100644 --- a/src/services/TMDB.js +++ b/src/services/TMDB.js @@ -0,0 +1,73 @@ +import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'; + +const tmdbApiKey = process.env.REACT_APP_TMDB_KEY; + +export const tmdbApi = createApi({ + reducerPath: 'tmdbApi', + baseQuery: fetchBaseQuery({ baseUrl: 'https://api.themoviedb.org/3' }), + endpoints: (builder) => ({ + + // Get Genres + getGenres: builder.query({ + query: () => `/genre/movie/list?api_key=${tmdbApiKey}`, + }), + + // Get Movies by [Type] + getMovies: builder.query({ + query: ({ genreIdOrCategoryName, page, searchQuery }) => { + // Get Movies by Search + if (searchQuery) { + return `/search/movie?query=${searchQuery}&page=${page}&api_key=${tmdbApiKey}`; + } + + // Get Movies by Category + if (genreIdOrCategoryName && typeof genreIdOrCategoryName === 'string') { + return `/movie/${genreIdOrCategoryName}?page=${page}&api_key=${tmdbApiKey}`; + } + + // Get Movies by Genre + if (genreIdOrCategoryName && typeof genreIdOrCategoryName === 'number') { + return `discover/movie?with_genres=${genreIdOrCategoryName}&page=${page}&api_key=${tmdbApiKey}`; + } + + // Get popular movies by default + return `/movie/popular?page=${page}&api_key=${tmdbApiKey}`; + }, + }), + + // Get Movie + getMovie: builder.query({ + query: (id) => `/movie/${id}?append_to_response=videos,credits&api_key=${tmdbApiKey}`, + }), + + // Get Recommendations + getRecommendations: builder.query({ + query: ({ movie_id, list }) => `/movie/${movie_id}/${list}?api_key=${tmdbApiKey}`, + }), + + // Get Actor + getActor: builder.query({ + query: (id) => `person/${id}?api_key=${tmdbApiKey}`, + }), + + // Get Movies by Actor + getMoviesByActorId: builder.query({ + query: ({ id, page }) => `/discover/movie?with_cast=${id}&page=${page}&api_key=${tmdbApiKey}`, + }), + + // Get User Specific Lists + getList: builder.query({ + query: ({ listName, accountId, sessionId, page }) => `/account/${accountId}/${listName}?api_key=${tmdbApiKey}&session_id=${sessionId}&page=${page}`, + }), + }), +}); + +export const { + useGetGenresQuery, + useGetMoviesQuery, + useGetMovieQuery, + useGetRecommendationsQuery, + useGetActorQuery, + useGetMoviesByActorIdQuery, + useGetListQuery, +} = tmdbApi; From b7b256b56e1d850cf13c03062c9bf258d36012bb Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:12:17 -0700 Subject: [PATCH 22/66] doc: add index file into utils directory --- src/utils/index.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/utils/index.js diff --git a/src/utils/index.js b/src/utils/index.js new file mode 100644 index 0000000..09ced50 --- /dev/null +++ b/src/utils/index.js @@ -0,0 +1,40 @@ +import axios from 'axios'; + +export const moviesApi = axios.create({ + baseURL: 'https://api.themoviedb.org/3', + params: { + api_key: process.env.REACT_APP_TMDB_KEY, + }, +}); + +export const fetchToken = async () => { + try { + const { data } = await moviesApi.get('/authentication/token/new'); + + const token = data.request_token; + + if (data.success) { + localStorage.setItem('request_token', token); + window.location.href = `https://www.themoviedb.org/authenticate/${token}?redirect_to=${window.location.origin}/approved`; + } + } catch (error) { + console.log('Sorry, your token could not be created.'); + } +}; + +export const createSessionId = async () => { + const token = localStorage.getItem('request_token'); + + if (token) { + try { + const { data: { session_id } } = await moviesApi.post('authentication/session/new', { + request_token: token, + }); + localStorage.setItem('session_id', session_id); + + return session_id; + } catch (error) { + console.log(error); + } + } +}; From 86720b1be4fe945469be909f4e019b309fa3e53f Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:13:04 -0700 Subject: [PATCH 23/66] file: add auth file into features directory --- src/features/auth.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/features/auth.js diff --git a/src/features/auth.js b/src/features/auth.js new file mode 100644 index 0000000..e69de29 From dc68b05303ab19bb1481a8eaffb99ae518be21ea Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:13:32 -0700 Subject: [PATCH 24/66] file: add currentGenreOrCategory file in features directory --- src/features/currentGenreOrCategory.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/features/currentGenreOrCategory.js diff --git a/src/features/currentGenreOrCategory.js b/src/features/currentGenreOrCategory.js new file mode 100644 index 0000000..e69de29 From 6320ee8578c658c27d34160200b9bf2cefbaf810 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:14:12 -0700 Subject: [PATCH 25/66] doc: add initialState and authSlice in auth file --- src/features/auth.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/features/auth.js b/src/features/auth.js index e69de29..2e8e7f4 100644 --- a/src/features/auth.js +++ b/src/features/auth.js @@ -0,0 +1,25 @@ +import { createSlice } from '@reduxjs/toolkit'; + +const initialState = { + user: {}, + isAuthenticated: false, + sessionId: '', +}; + +const authSlice = createSlice({ + name: 'user', + initialState, + reducers: { + setUser: (state, action) => { + state.user = action.payload; + state.isAuthenticated = true; + state.sessionId = localStorage.getItem('session_id'); + + localStorage.setItem('accountId', action.payload.id); + }, + }, +}); + +export const { setUser } = authSlice.actions; + +export default authSlice.reducer; From ac35bb1c1bf51ff578546571617b44a35fa03b6f Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:14:49 -0700 Subject: [PATCH 26/66] doc: add genreOrCategory function --- src/features/currentGenreOrCategory.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/features/currentGenreOrCategory.js b/src/features/currentGenreOrCategory.js index e69de29..233d1fb 100644 --- a/src/features/currentGenreOrCategory.js +++ b/src/features/currentGenreOrCategory.js @@ -0,0 +1,23 @@ +import { createSlice } from '@reduxjs/toolkit'; + +export const genreOrCategory = createSlice({ + name: 'genreOrCategory', + initialState: { + genreIdOrCategoryName: '', + page: 1, + searchQuery: '', + }, + reducers: { + selectGenreOrCategory: (state, action) => { + state.genreIdOrCategoryName = action.payload; + state.searchQuery = ''; + }, + searchMovie: (state, action) => { + state.searchQuery = action.payload; + }, + }, +}); + +export const { selectGenreOrCategory, searchMovie } = genreOrCategory.actions; + +export default genreOrCategory.reducer; From 5f737dc8246184972ba31f1ed104e3c735fc7079 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:16:27 -0700 Subject: [PATCH 27/66] doc: import Provider from react-redux and store from store directory --- src/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.js b/src/index.js index c9181f9..1cc3537 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,8 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; import { BrowserRouter } from 'react-router-dom'; +import { Provider } from 'react-redux'; +import store from './app/store'; import ToggleColorMode from "./utils/ToggleColorMode"; import App from './components/App'; import './index.css'; From cdbccd35cf6881513a18c6468bb2614a453bb56f Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:17:50 -0700 Subject: [PATCH 28/66] doc: add Provider to render function and move the rest of the components into the Provider tag --- src/index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 1cc3537..90d6ec3 100644 --- a/src/index.js +++ b/src/index.js @@ -9,11 +9,12 @@ import './index.css'; const root = ReactDOM.createRoot(document.getElementById('root')); root.render( - - - - - - - + + + + + + + + ); From de55bfa2fa4e74961e7ab768d1324caa790eb131 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:23:36 -0700 Subject: [PATCH 29/66] doc: add configureStore function to store file --- src/app/store.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/app/store.js b/src/app/store.js index e69de29..2155458 100644 --- a/src/app/store.js +++ b/src/app/store.js @@ -0,0 +1,12 @@ +import { configureStore } from '@reduxjs/toolkit'; +import { tmdbApi } from '../services/TMDB'; +import genreOrCategoryReducer from '../features/currentGenreOrCategory'; +import userReducer from '../features/auth'; + +export default configureStore({ + reducer: { + [tmdbApi.reducerPath]: tmdbApi.reducer, + currentGenreOrCategory: genreOrCategoryReducer, + user: userReducer, + }, +}); From 4f30c1d43439f804dcdbd732c10ba5848383364b Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:32:37 -0700 Subject: [PATCH 30/66] file: create Alan AI file --- src/Alan.jsx | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/Alan.jsx diff --git a/src/Alan.jsx b/src/Alan.jsx new file mode 100644 index 0000000..03f7db7 --- /dev/null +++ b/src/Alan.jsx @@ -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; From 2ca1a190e7b7f6fe11fdde37f8003c7882a792fc Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:33:40 -0700 Subject: [PATCH 31/66] doc: move Alan from root directory into components directory --- src/{ => components}/Alan.jsx | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{ => components}/Alan.jsx (100%) diff --git a/src/Alan.jsx b/src/components/Alan.jsx similarity index 100% rename from src/Alan.jsx rename to src/components/Alan.jsx From 540c90e693739a112ebe66495037ed5f95e88f71 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:34:47 -0700 Subject: [PATCH 32/66] doc: import useAlan and use it within the App.jsx --- src/components/App.jsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index 48232ea..b813de4 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -2,12 +2,17 @@ import { useRef } from 'react'; import { CssBaseline} from "@mui/material"; import { Routes, Route } from 'react-router-dom'; -import useStyles from './styles' +import useStyles from './styles'; +import useAlan from './Alan'; import { Navbar } from './index' function App() { const classes = useStyles(); + const alanBtnContainer = useRef(); + + useAlan(); + return (
@@ -16,6 +21,7 @@ function App() {
+
); } From 0f6d36f7777e43d14108ce7a7ed00daf0e2c3c53 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:36:11 -0700 Subject: [PATCH 33/66] file: create Movies component in Movies directory --- src/components/Movies/Movies.jsx | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/components/Movies/Movies.jsx diff --git a/src/components/Movies/Movies.jsx b/src/components/Movies/Movies.jsx new file mode 100644 index 0000000..e69de29 From 1afd40fae5ccae6da53d274136be51518faeb50a Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:36:40 -0700 Subject: [PATCH 34/66] doc: create Movies function --- src/components/Movies/Movies.jsx | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/components/Movies/Movies.jsx b/src/components/Movies/Movies.jsx index e69de29..57cff1c 100644 --- a/src/components/Movies/Movies.jsx +++ b/src/components/Movies/Movies.jsx @@ -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 ( + + + + ); + } + + if (!data.results.length) { + return ( + + + No movies that match that name. +
+ Please searh for something else. +
+
+ ); + } + + if (error) return 'An error has occured.'; + + return ( +
+ + + +
+ ); +} + +export default Movies; From b780f788b39ac3668068c8d4cf6332fa9376edcf Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:37:44 -0700 Subject: [PATCH 35/66] file: create MovieList component in MovieList directory --- src/components/MovieList/MovieList.jsx | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/components/MovieList/MovieList.jsx diff --git a/src/components/MovieList/MovieList.jsx b/src/components/MovieList/MovieList.jsx new file mode 100644 index 0000000..e69de29 From dbf3ee2897438c99b4f82b0db1e1e93009290580 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:38:27 -0700 Subject: [PATCH 36/66] file: create styles for MoveList component --- src/components/MovieList/styles.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/components/MovieList/styles.js diff --git a/src/components/MovieList/styles.js b/src/components/MovieList/styles.js new file mode 100644 index 0000000..e69de29 From 9687230690405f487a30b24b17e9d55afb94173e Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:38:53 -0700 Subject: [PATCH 37/66] doc: create MovieList function --- src/components/MovieList/MovieList.jsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/components/MovieList/MovieList.jsx b/src/components/MovieList/MovieList.jsx index e69de29..c4f5dda 100644 --- a/src/components/MovieList/MovieList.jsx +++ b/src/components/MovieList/MovieList.jsx @@ -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 ( + + {movies.results.slice(startFrom, numberOfMovies).map((movie, i) => ( + + ))} + + ); +} + +export default MovieList; From 3ae38b61e4ccd7f53af3c71055d3706e9fb64a8b Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:40:02 -0700 Subject: [PATCH 38/66] file: create MoviesInfo and its stylesheet into the MovieInfo directory --- src/components/MovieInfo/MovieInfo.jsx | 0 src/components/MovieInfo/styles.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/components/MovieInfo/MovieInfo.jsx create mode 100644 src/components/MovieInfo/styles.js diff --git a/src/components/MovieInfo/MovieInfo.jsx b/src/components/MovieInfo/MovieInfo.jsx new file mode 100644 index 0000000..e69de29 diff --git a/src/components/MovieInfo/styles.js b/src/components/MovieInfo/styles.js new file mode 100644 index 0000000..e69de29 From 2fad796632486e3cd5c631576bc9311e86f6e736 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sat, 3 Sep 2022 12:40:49 -0700 Subject: [PATCH 39/66] doc: create MovieInfo function --- src/components/MovieInfo/MovieInfo.jsx | 181 +++++++++++++++++++++++++ 1 file changed, 181 insertions(+) diff --git a/src/components/MovieInfo/MovieInfo.jsx b/src/components/MovieInfo/MovieInfo.jsx index e69de29..aca05b3 100644 --- a/src/components/MovieInfo/MovieInfo.jsx +++ b/src/components/MovieInfo/MovieInfo.jsx @@ -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 ( + + + + ); + } + + if (error) { + return ( + + Something went wrong - Go back. + + ); + } + + return ( + + + {data?.title} + + + + {data?.title} ({data.release_date.split('-')[0]}) + + + {data?.tagline} + + + + + + {data?.vote_average} / 10 + + + {data?.runtime}min + + + {data?.genres?.map((genre) => ( + dispatch(selectGenreOrCategory(genre.id))}> + + {genre?.name} + + ))} + + Overview + {data?.overview} + Top Cast + + {data && data?.credits?.cast?.map((character, i) => ( + character.profile_path && ( + + {character.name} + {character?.name} + + {character.character.split('/')[0]} + + + ) + )).slice(0, 6)} + + +
+ + + + + + + + + + + + + + +
+
+
+ + + You might also like + + {recommendations + ? + : Sorry, nothing was found.} + + setOpen(false)} + > + {data?.videos?.results?.length > 0 && ( +