├── public ├── favicon.ico ├── logo192.png ├── logo512.png ├── robots.txt ├── manifest.json └── index.html ├── src ├── index.js ├── components │ ├── SearchBar.js │ ├── MovieList.js │ ├── AddMovie.js │ ├── App.js │ └── EditMovie.js └── api │ └── movies.json ├── .gitignore ├── package.json └── README.md /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArinSoftware/my-movies/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArinSoftware/my-movies/HEAD/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArinSoftware/my-movies/HEAD/public/logo512.png -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | 4 | import App from './components/App'; 5 | import '../node_modules/bootstrap/dist/css/bootstrap.min.css'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-movies", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^4.2.4", 7 | "@testing-library/react": "^9.5.0", 8 | "@testing-library/user-event": "^7.2.1", 9 | "axios": "^0.20.0", 10 | "bootstrap": "^4.5.2", 11 | "form-serialize": "^0.7.2", 12 | "json-server": "^0.16.1", 13 | "react": "^16.13.1", 14 | "react-dom": "^16.13.1", 15 | "react-router-dom": "^5.2.0", 16 | "react-scripts": "3.4.3" 17 | }, 18 | "scripts": { 19 | "start": "react-scripts start", 20 | "build": "react-scripts build", 21 | "test": "react-scripts test", 22 | "eject": "react-scripts eject" 23 | }, 24 | "eslintConfig": { 25 | "extends": "react-app" 26 | }, 27 | "browserslist": { 28 | "production": [ 29 | ">0.2%", 30 | "not dead", 31 | "not op_mini all" 32 | ], 33 | "development": [ 34 | "last 1 chrome version", 35 | "last 1 firefox version", 36 | "last 1 safari version" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/components/SearchBar.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Link } from 'react-router-dom'; 3 | 4 | class SearchBar extends React.Component { 5 | 6 | 7 | handleFormSubmit = (event) => { 8 | event.preventDefault(); 9 | } 10 | 11 | render() { 12 | 13 | return ( 14 |
15 |
16 |
17 | 23 |
24 |
25 | Add Movie 30 | 31 |
32 |
33 |
34 | ) 35 | 36 | } 37 | } 38 | 39 | 40 | export default SearchBar; -------------------------------------------------------------------------------- /src/components/MovieList.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Link } from 'react-router-dom'; 3 | 4 | const MovieList = (props) => { 5 | 6 | 7 | 8 | const truncateOverview = (string, maxLength) => { 9 | if (!string) return null; 10 | if (string.length <= maxLength ) return string; 11 | return `${string.substring(0, maxLength)} ...`; 12 | } 13 | 14 | return ( 15 |
16 | 17 | {props.movies.map((movie, i) => ( 18 | 19 |
20 |
21 | Sample Movie 22 |
23 |
{movie.name}
24 |

{truncateOverview(movie.overview, 100)}

25 |
26 | 27 | 28 | Edit 32 | 33 | 34 |

{movie.rating}

35 |
36 |
37 |
38 |
39 | 40 | ))} 41 | 42 |
43 | ) 44 | } 45 | 46 | export default MovieList; -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | My Movies App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/api/movies.json: -------------------------------------------------------------------------------- 1 | { 2 | "movies": [ 3 | { 4 | "name": "The Matrix 3", 5 | "rating": "8.1", 6 | "overview": "Set in the 22nd century, The Matrix tells the story of a computer hacker who joins a group of underground insurgents fighting the vast and powerful computers who now rule the earth.", 7 | "imageURL": "https://image.tmdb.org/t/p/w600_and_h900_bestv2/dXNAPwY7VrqMAo51EKhhCJfaGb5.jpg", 8 | "id": 7 9 | }, 10 | { 11 | "name": "The Matrix Reloaded", 12 | "rating": "6.9", 13 | "imageURL": "https://image.tmdb.org/t/p/w600_and_h900_bestv2/jBegA6V243J6HUnpcOILsRvBnGb.jpg", 14 | "overview": "Six months after the events depicted in The Matrix, Neo has proved to be a good omen for the free humans, as more and more humans are being freed from the matrix and brought to Zion, the one and only stronghold of the Resistance. Neo himself has discovered his superpowers including super speed, ability to see the codes of the things inside the matrix and a certain degree of pre-cognition.", 15 | "id": 8 16 | }, 17 | { 18 | "name": "Saw 3D", 19 | "rating": "7.5", 20 | "overview": "SAW legacy, a group of Jigsaw survivors gathers to seek the support of self-help guru and fellow survivor Bobby Dagen, a man whose own dark secrets unleash a new wave of terror.", 21 | "imageURL": "https://image.tmdb.org/t/p/w600_and_h900_bestv2/qHCZ6LjtmqWDfXXN28TlIC9OppK.jpg", 22 | "id": 11 23 | }, 24 | { 25 | "name": "Blitz 007", 26 | "rating": "11", 27 | "overview": "A tough, renegade cop with a gay sidekick is dispatched to take down a serial killer who has been targeting police officers. AÇIKLAMA AÇIKLAMA", 28 | "imageURL": "https://image.tmdb.org/t/p/w600_and_h900_bestv2/qCPMjT8Ld8tvs1zs7LY2jpKlRIK.jpg", 29 | "id": 12 30 | }, 31 | { 32 | "name": "Hostage", 33 | "rating": "6.3", 34 | "imageURL": "https://image.tmdb.org/t/p/w600_and_h900_bestv2/4hne3v6jN4MlCnhSkxOW7YspJhr.jpg", 35 | "overview": "When a mafia accountant is taken hostage on his beat, a police officer – wracked by guilt from a prior stint as a negotiator – must negotiate the standoff, even as his own family is held captive by the mob.", 36 | "id": 13 37 | } 38 | ] 39 | } -------------------------------------------------------------------------------- /src/components/AddMovie.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import serialize from 'form-serialize'; 3 | 4 | class AddMovie extends React.Component { 5 | 6 | handleFormSubmit = (e) => { 7 | e.preventDefault(); 8 | const newMovie = serialize(e.target, { hash: true }); 9 | //console.log(newMovie); 10 | this.props.onAddMovie(newMovie); 11 | } 12 | 13 | 14 | render() { 15 | 16 | return ( 17 |
18 |
19 | 20 |
21 |
22 | 23 | 26 |
27 |
28 | 29 | 33 |
34 |
35 |
36 |
37 | 38 | 42 |
43 |
44 |
45 |
46 | 47 | 50 |
51 |
52 | 53 |
54 |
55 | ) 56 | 57 | } 58 | } 59 | 60 | 61 | export default AddMovie; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | 46 | ### Code Splitting 47 | 48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 49 | 50 | ### Analyzing the Bundle Size 51 | 52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 53 | 54 | ### Making a Progressive Web App 55 | 56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 57 | 58 | ### Advanced Configuration 59 | 60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 61 | 62 | ### Deployment 63 | 64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 65 | 66 | ### `npm run build` fails to minify 67 | 68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 69 | -------------------------------------------------------------------------------- /src/components/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import MovieList from './MovieList'; 3 | import SearchBar from './SearchBar'; 4 | import AddMovie from './AddMovie'; 5 | import EditMovie from './EditMovie'; 6 | import axios from 'axios'; 7 | import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; 8 | 9 | class App extends React.Component { 10 | 11 | state = { 12 | movies: [], 13 | searchQuery: "" 14 | } 15 | 16 | componentDidMount() { 17 | this.getMovies(); 18 | } 19 | 20 | async getMovies() { 21 | const response = await axios.get("http://localhost:3002/movies"); 22 | this.setState({ movies: response.data }) 23 | } 24 | 25 | 26 | 27 | 28 | // DELETE MOVIE 29 | deleteMovie = async (movie) => { 30 | 31 | axios.delete(`http://localhost:3002/movies/${movie.id}`) 32 | const newMovieList = this.state.movies.filter( 33 | m => m.id !== movie.id 34 | ); 35 | this.setState(state => ({ 36 | movies: newMovieList 37 | })) 38 | } 39 | 40 | 41 | // SEARCH MOVIE 42 | searchMovie = (event) => { 43 | this.setState({ searchQuery: event.target.value }) 44 | } 45 | 46 | 47 | // ADD MOVIE 48 | addMovie = async (movie) => { 49 | await axios.post(`http://localhost:3002/movies/`, movie) 50 | this.setState(state => ({ 51 | movies: state.movies.concat([movie]) 52 | })) 53 | 54 | this.getMovies(); 55 | } 56 | 57 | // EDIT MOVIE 58 | editMovie = async (id, updatedMovie) => { 59 | await axios.put(`http://localhost:3002/movies/${id}`, updatedMovie) 60 | this.getMovies(); 61 | } 62 | 63 | render() { 64 | 65 | let filteredMovies = this.state.movies.filter( 66 | (movie) => { 67 | return movie.name.toLowerCase().indexOf(this.state.searchQuery.toLowerCase()) !== -1 68 | } 69 | ).sort((a, b) => { 70 | return a.id < b.id ? 1 : a.id > b.id ? -1 : 0; 71 | }); 72 | 73 | return ( 74 | 75 | 76 |
77 | 78 | 79 | 80 | 81 | ( 82 | 83 |
84 |
85 | 86 |
87 |
88 | 89 | 90 | 95 |
96 | )}> 97 | 98 |
99 | 100 | ( 101 | 102 | { 105 | this.addMovie(movie) 106 | history.push("/") 107 | } 108 | } 109 | 110 | /> 111 | 112 | )}> 113 | 114 | 115 | 116 | ( 117 | 118 | { 121 | this.editMovie(id, movie) 122 | } 123 | } 124 | 125 | /> 126 | 127 | )}> 128 | 129 | 130 | 131 |
132 |
133 | 134 |
135 | ) 136 | 137 | } 138 | 139 | 140 | } 141 | 142 | export default App; -------------------------------------------------------------------------------- /src/components/EditMovie.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import axios from 'axios'; 3 | 4 | class EditMovie extends React.Component { 5 | 6 | state = { 7 | name: "", 8 | rating: "", 9 | overview: "", 10 | imageURL: "" 11 | } 12 | 13 | 14 | 15 | async componentDidMount() { 16 | 17 | const id = this.props.match.params.id; 18 | //console.log(id) 19 | 20 | const response = await axios.get(`http://localhost:3002/movies/${id}`); 21 | //console.log(response.data); 22 | 23 | const movie = response.data; 24 | 25 | this.setState({ 26 | name: movie.name, 27 | rating: movie.rating, 28 | overview: movie.overview, 29 | imageURL: movie.imageURL 30 | }) 31 | 32 | } 33 | 34 | onInputChange = (e) => { 35 | // console.log(e.target.name); 36 | // console.log(e.target.value); 37 | 38 | this.setState({ 39 | [e.target.name]: e.target.value 40 | }) 41 | } 42 | 43 | handleFormSubmit = (e) => { 44 | e.preventDefault(); 45 | /* 46 | const name = this.state.name; 47 | const rating = this.state.rating; 48 | const overview = this.state.overview; 49 | const imageURL = this.state.imageURL; */ 50 | 51 | const { name, rating, overview, imageURL } = this.state; 52 | 53 | const id = this.props.match.params.id; 54 | 55 | const updatedMovie = { 56 | name, 57 | rating, 58 | overview, 59 | imageURL 60 | } 61 | 62 | this.props.onEditMovie(id, updatedMovie); 63 | this.props.history.push('/'); 64 | 65 | } 66 | 67 | 68 | render() { 69 | 70 | return ( 71 |
72 |
73 | 74 |
75 |
76 | 77 | 82 |
83 |
84 | 85 | 91 |
92 |
93 |
94 |
95 | 96 | 102 |
103 |
104 |
105 |
106 | 107 | 113 |
114 |
115 | 116 |
117 |
118 | ) 119 | 120 | } 121 | } 122 | 123 | 124 | export default EditMovie; --------------------------------------------------------------------------------