├── src ├── variables.scss ├── components │ ├── app-filter │ │ ├── app-filter.css │ │ └── app-filter.js │ ├── app-info │ │ ├── app-info.scss │ │ └── app-info.js │ ├── search-panel │ │ ├── search-panel.css │ │ └── search-panel.js │ ├── movie-list │ │ ├── movie-list.css │ │ └── movie-list.js │ ├── movies-add-form │ │ ├── movies-add-form.css │ │ └── movies-add-form.js │ ├── app │ │ ├── app.css │ │ └── app.js │ └── movie-list-item │ │ ├── movie-list-item.js │ │ └── movie-list-item.css ├── index.scss └── index.js ├── public └── index.html ├── package.json └── README.md /src/variables.scss: -------------------------------------------------------------------------------- 1 | $my-color: #fff; 2 | -------------------------------------------------------------------------------- /src/components/app-filter/app-filter.css: -------------------------------------------------------------------------------- 1 | .btn-group { 2 | margin-top: 1rem; 3 | } 4 | -------------------------------------------------------------------------------- /src/components/app-info/app-info.scss: -------------------------------------------------------------------------------- 1 | .app-info { 2 | padding: 1.5rem; 3 | border-radius: 4px; 4 | background-color: #fcfaf5; 5 | box-shadow: 15px 15px 30px rgba(0, 0, 0, 0.15); 6 | } 7 | -------------------------------------------------------------------------------- /src/index.scss: -------------------------------------------------------------------------------- 1 | @import './variables.scss'; 2 | 3 | * { 4 | margin: 0; 5 | padding: 0; 6 | box-sizing: border-box; 7 | } 8 | 9 | body { 10 | background-color: $my-color; 11 | } 12 | -------------------------------------------------------------------------------- /src/components/search-panel/search-panel.css: -------------------------------------------------------------------------------- 1 | .search-input { 2 | padding: 1.5rem; 3 | border-radius: 4px; 4 | background-color: #fcfaf5; 5 | box-shadow: 15px 15px 30px rgba(0, 0, 0, 0.15); 6 | } 7 | -------------------------------------------------------------------------------- /src/components/movie-list/movie-list.css: -------------------------------------------------------------------------------- 1 | .movie-list { 2 | margin-top: 1.5rem; 3 | padding: 1.5rem; 4 | border-radius: 4px; 5 | background-color: #fcfaf5; 6 | box-shadow: 15px 15px 30px rgba(0, 0, 0, 0.15); 7 | } 8 | -------------------------------------------------------------------------------- /src/components/movies-add-form/movies-add-form.css: -------------------------------------------------------------------------------- 1 | .movies-add-form { 2 | margin-top: 1.5rem; 3 | padding: 1.5rem; 4 | border-radius: 4px; 5 | background-color: #fcfaf5; 6 | box-shadow: 15px 15px 30px rgba(0, 0, 0, 0.15); 7 | } 8 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import App from './components/app/app' 4 | import './index.scss' 5 | 6 | const root = ReactDOM.createRoot(document.getElementById('root')) 7 | root.render( 8 | 9 | 10 | 11 | ) 12 | -------------------------------------------------------------------------------- /src/components/app/app.css: -------------------------------------------------------------------------------- 1 | .app { 2 | height: 100vh; 3 | color: #000; 4 | } 5 | 6 | .content { 7 | max-width: 1000px; 8 | background-color: #fff; 9 | margin: 0 auto; 10 | padding: 5rem 0; 11 | } 12 | .search-panel { 13 | margin-top: 1.5rem; 14 | padding: 1.5rem; 15 | border-radius: 4px; 16 | background-color: #fcfaf5; 17 | box-shadow: 15px 15px 30px rgba(0, 0, 0, 0.15); 18 | } 19 | -------------------------------------------------------------------------------- /src/components/app-info/app-info.js: -------------------------------------------------------------------------------- 1 | import './app-info.scss' 2 | 3 | const AppInfo = ({ allMoviesCount, favouriteMovieCount }) => { 4 | return ( 5 |
6 |

Barcha kinolar soni: {allMoviesCount}

7 |

Sevimli film: {favouriteMovieCount}

8 |
9 | ) 10 | } 11 | 12 | export default AppInfo 13 | -------------------------------------------------------------------------------- /src/components/search-panel/search-panel.js: -------------------------------------------------------------------------------- 1 | import { useState } from 'react' 2 | import './search-panel.css' 3 | 4 | const SearchPanel = props => { 5 | const [term, setTerm] = useState('') 6 | 7 | const updateTermHandler = e => { 8 | const term = e.target.value.toLowerCase() 9 | setTerm(term) 10 | props.updateTermHandler(term) 11 | } 12 | 13 | return ( 14 | 21 | ) 22 | } 23 | 24 | export default SearchPanel 25 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Sammi | Movies 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /src/components/movie-list/movie-list.js: -------------------------------------------------------------------------------- 1 | import './movie-list.css' 2 | 3 | import MovieListItem from '../movie-list-item/movie-list-item' 4 | 5 | const MovieList = ({ data, onDelete, onToggleProp }) => { 6 | return ( 7 | 20 | ) 21 | } 22 | 23 | export default MovieList 24 | -------------------------------------------------------------------------------- /src/components/app-filter/app-filter.js: -------------------------------------------------------------------------------- 1 | import './app-filter.css' 2 | 3 | const AppFilter = ({ updateFilterHandler, filter }) => { 4 | return ( 5 |
6 | {btnsArr.map(btn => ( 7 | 15 | ))} 16 |
17 | ) 18 | } 19 | 20 | const btnsArr = [ 21 | { name: 'all', label: 'Barcha kinolar' }, 22 | { name: 'popular', label: 'Mashhur kinolar' }, 23 | { name: 'mostViewers', label: "Eng ko'p ko'rilgan kinolar" }, 24 | ] 25 | 26 | export default AppFilter 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "movie", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "react": "^18.2.0", 10 | "react-dom": "^18.2.0", 11 | "react-scripts": "5.0.1", 12 | "sass": "^1.55.0", 13 | "uuid": "^9.0.0", 14 | "web-vitals": "^2.1.4" 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build", 19 | "test": "react-scripts test", 20 | "eject": "react-scripts eject" 21 | }, 22 | "eslintConfig": { 23 | "extends": [ 24 | "react-app", 25 | "react-app/jest" 26 | ] 27 | }, 28 | "browserslist": { 29 | "production": [ 30 | ">0.2%", 31 | "not dead", 32 | "not op_mini all" 33 | ], 34 | "development": [ 35 | "last 1 chrome version", 36 | "last 1 firefox version", 37 | "last 1 safari version" 38 | ] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/components/movie-list-item/movie-list-item.js: -------------------------------------------------------------------------------- 1 | import './movie-list-item.css' 2 | 3 | const MovieListItem = props => { 4 | const { name, viewers, onDelete, onToggleProp, favourite, like } = props 5 | 6 | return ( 7 |
  • 8 | 9 | {name} 10 | 11 | 12 |
    13 | 16 | 19 | 20 |
    21 |
  • 22 | ) 23 | } 24 | 25 | export default MovieListItem 26 | -------------------------------------------------------------------------------- /src/components/movie-list-item/movie-list-item.css: -------------------------------------------------------------------------------- 1 | .list-group-item { 2 | padding: 15px 20px; 3 | border-bottom: 1px solid #3d5a80; 4 | } 5 | 6 | .list-group-item:last-child { 7 | border-bottom: none; 8 | } 9 | 10 | .list-group-item span { 11 | line-height: 35px; 12 | font-size: 20px; 13 | cursor: pointer; 14 | width: 550px; 15 | } 16 | 17 | .list-group-item input { 18 | line-height: 35px; 19 | font-size: 20px; 20 | text-align: center; 21 | border: 0; 22 | } 23 | 24 | .list-group-item button { 25 | width: 35px; 26 | height: 35px; 27 | margin: 3px; 28 | font-size: 17px; 29 | border: none; 30 | cursor: pointer; 31 | } 32 | 33 | .list-group-item .btn-cookie { 34 | color: #e09f3e; 35 | } 36 | 37 | .list-group-item .btn-trash { 38 | color: #e5383b; 39 | } 40 | 41 | .list-group-item .fa-star { 42 | width: 35px; 43 | height: 35px; 44 | text-align: center; 45 | line-height: 35px; 46 | font-size: 16px; 47 | color: #ffd700; 48 | transition: 0.3s all; 49 | transform: translateX(30px); 50 | opacity: 0; 51 | } 52 | 53 | .list-group-item.like .fa-star { 54 | opacity: 1; 55 | transform: translateX(0px); 56 | } 57 | 58 | .list-group-item.favourite .list-group-item-label, 59 | .list-group-item.favourite .list-group-item-input { 60 | color: #e09f3e; 61 | } 62 | 63 | .list-group-item.favourite .btn-star { 64 | color: #aeaeae; 65 | } 66 | -------------------------------------------------------------------------------- /src/components/movies-add-form/movies-add-form.js: -------------------------------------------------------------------------------- 1 | import { useState } from 'react' 2 | import './movies-add-form.css' 3 | 4 | const MoviesAddForm = ({ addForm }) => { 5 | const [state, setState] = useState({ name: '', views: '' }) 6 | 7 | const changeHandlerInput = e => setState({ ...state, [e.target.name]: e.target.value }) 8 | 9 | const addFormHandler = e => { 10 | e.preventDefault() 11 | if (state.name === '' || state.views === '') return 12 | const data = { name: state.name, viewers: state.views } 13 | addForm(data) 14 | setState({ name: '', views: '' }) 15 | } 16 | 17 | return ( 18 |
    19 |

    Yangi kino qo'shish

    20 |
    21 | 29 | 37 | 40 |
    41 |
    42 | ) 43 | } 44 | 45 | export default MoviesAddForm 46 | -------------------------------------------------------------------------------- /src/components/app/app.js: -------------------------------------------------------------------------------- 1 | import { useState, useEffect } from 'react' 2 | import AppInfo from '../app-info/app-info' 3 | import SearchPanel from '../search-panel/search-panel' 4 | import AppFilter from '../app-filter/app-filter' 5 | import MovieList from '../movie-list/movie-list' 6 | import MoviesAddForm from '../movies-add-form/movies-add-form' 7 | import { v4 as uuidv4 } from 'uuid' 8 | 9 | import './app.css' 10 | 11 | const App = () => { 12 | const [data, setData] = useState([]) 13 | const [term, setTerm] = useState('') 14 | const [filter, setFilter] = useState('all') 15 | const [isLoading, setIsLoading] = useState(false) 16 | 17 | const onDelete = id => { 18 | const newArr = data.filter(c => c.id !== id) 19 | setData(newArr) 20 | } 21 | 22 | const addForm = item => { 23 | const newItem = { 24 | name: item.name, 25 | viewers: item.viewers, 26 | id: uuidv4(), 27 | favourite: false, 28 | like: false, 29 | } 30 | const newArr = [...data, newItem] 31 | setData(newArr) 32 | } 33 | 34 | const onToggleProp = (id, prop) => { 35 | const newArr = data.map(item => { 36 | if (item.id === id) { 37 | return { ...item, [prop]: !item[prop] } 38 | } 39 | return item 40 | }) 41 | setData(newArr) 42 | } 43 | 44 | const searchHandler = (arr, term) => { 45 | if (term === 0) { 46 | return arr 47 | } 48 | 49 | return arr.filter(item => item.name.toLowerCase().indexOf(term) > -1) 50 | } 51 | 52 | const filterHandler = (arr, filter) => { 53 | switch (filter) { 54 | case 'popular': 55 | return arr.filter(c => c.like) 56 | case 'mostViewers': 57 | return arr.filter(c => c.viewers > 800) 58 | default: 59 | return arr 60 | } 61 | } 62 | 63 | const updateTermHandler = term => setTerm(term) 64 | 65 | const updateFilterHandler = filter => setFilter(filter) 66 | 67 | useEffect(() => { 68 | setIsLoading(true) 69 | fetch('https://jsonplaceholder.typicode.com/todos?_start=0&_limit=5') 70 | .then(response => response.json()) 71 | .then(json => { 72 | const newArr = json.map(item => ({ 73 | name: item.title, 74 | id: item.id, 75 | viewers: item.id * 10, 76 | favourite: false, 77 | like: false, 78 | })) 79 | setData(newArr) 80 | }) 81 | .catch(err => console.log(err)) 82 | .finally(() => setIsLoading(false)) 83 | }, []) 84 | 85 | return ( 86 |
    87 |
    88 | c.favourite).length} 91 | /> 92 |
    93 | 94 | 95 |
    96 | {isLoading && 'Loading..'} 97 | 102 | 103 |
    104 |
    105 | ) 106 | } 107 | 108 | export default App 109 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | 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. 37 | 38 | 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. 39 | 40 | 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. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | --------------------------------------------------------------------------------