-
Notifications
You must be signed in to change notification settings - Fork 0
Review/4 components p1 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4_components_p1
Are you sure you want to change the base?
Changes from all commits
c660fde
552a488
0c8ddac
22f15d9
c10caa5
e431892
c337fcf
6af7bd3
ac2ed92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,44 @@ | ||
| { | ||
| "name": "my-app", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "dependencies": { | ||
| "@testing-library/jest-dom": "^5.16.4", | ||
| "@testing-library/react": "^13.2.0", | ||
| "@testing-library/user-event": "^13.5.0", | ||
| "@types/react": "^18.0.9", | ||
| "@types/react-dom": "^18.0.4", | ||
| "react": "^18.1.0", | ||
| "react-dom": "^18.1.0", | ||
| "react-scripts": "5.0.1", | ||
| "typescript": "^4.6.4", | ||
| "web-vitals": "^2.1.4" | ||
| }, | ||
| "scripts": { | ||
| "start": "react-scripts start", | ||
| "build": "react-scripts build", | ||
| "test": "react-scripts test", | ||
| "eject": "react-scripts eject" | ||
| }, | ||
| "eslintConfig": { | ||
| "extends": [ | ||
| "react-app", | ||
| "react-app/jest" | ||
| ] | ||
| }, | ||
| "browserslist": { | ||
| "production": [ | ||
| ">0.2%", | ||
| "not dead", | ||
| "not op_mini all" | ||
| ], | ||
| "development": [ | ||
| "last 1 chrome version", | ||
| "last 1 firefox version", | ||
| "last 1 safari version" | ||
| ] | ||
| } | ||
| "name": "my-app", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "dependencies": { | ||
| "@testing-library/jest-dom": "^5.16.4", | ||
| "@testing-library/react": "^13.2.0", | ||
| "@testing-library/user-event": "^13.5.0", | ||
| "@types/react": "^18.0.9", | ||
| "@types/react-dom": "^18.0.4", | ||
| "classnames": "^2.3.1", | ||
| "easy-bem": "^1.1.1", | ||
| "react": "^18.1.0", | ||
| "react-dom": "^18.1.0", | ||
| "react-scripts": "5.0.1", | ||
| "sass": "^1.52.1", | ||
| "typescript": "^4.6.4", | ||
| "web-vitals": "^2.1.4" | ||
| }, | ||
| "scripts": { | ||
| "start": "react-scripts start", | ||
| "build": "react-scripts build", | ||
| "test": "react-scripts test", | ||
| "eject": "react-scripts eject" | ||
| }, | ||
| "eslintConfig": { | ||
| "extends": [ | ||
| "react-app", | ||
| "react-app/jest" | ||
| ] | ||
| }, | ||
| "browserslist": { | ||
| "production": [ | ||
| ">0.2%", | ||
| "not dead", | ||
| "not op_mini all" | ||
| ], | ||
| "development": [ | ||
| "last 1 chrome version", | ||
| "last 1 firefox version", | ||
| "last 1 safari version" | ||
| ] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,55 +1,72 @@ | ||
| import { useState } from 'react'; | ||
| import GenresSelector from '../genres-selector-component/genres-selector-component.tsx'; | ||
| import ItemsCount from '../items-count-component/items-count-component.tsx'; | ||
| import MovieItem from '../movie-item-component/movie-item-component.tsx'; | ||
| import Sort from '../sort-component/sort-component.tsx'; | ||
| import { GenresSelector } from '../genres-selector-component/genres-selector-component'; | ||
| import { ItemsCount } from '../items-count-component/items-count-component'; | ||
| import { MovieItem } from '../movie-item-component/movie-item-component'; | ||
| import Sort from '../sort-component/sort-component'; | ||
| import './catalog-component.css'; | ||
|
|
||
| let moviesData = [ | ||
| export interface Movie { | ||
| /** GUID movie identifier */ | ||
| id: string; | ||
| /** Image URL */ | ||
| image: string; | ||
| name: string; | ||
| /** @todo: change type to Date? */ | ||
| year: number; | ||
| genre: string; | ||
| } | ||
|
|
||
| const moviesData: ReadonlyArray<Readonly<Movie>> = [ | ||
| { | ||
| id: 1, | ||
| id: '00000000-0000-0000-0000-000000000001', | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. На сколько я помню, API для этого менторинга имеет ввиду GUID для идентифкатора фильма. Ссылку на API можно найти где-то в pdf с заданием. Там есть Swagger, можно посмотреть чо да как работает |
||
| image: './movie1.png', | ||
| name: 'Pulp Fiction', | ||
| year: 1994, | ||
| genre: 'Criminal', | ||
| }, | ||
| { | ||
| id: 2, | ||
| id: '00000000-0000-0000-0000-000000000002', | ||
| image: './movie2.png', | ||
| name: 'Bohemian Rhaspody', | ||
| year: 2018, | ||
| genre: 'Music & Drama', | ||
| }, | ||
| { | ||
| id: 3, | ||
| id: '00000000-0000-0000-0000-000000000003', | ||
| image: './movie3.png', | ||
| name: 'Kill Bill: Vol. 1', | ||
| year: 2003, | ||
| genre: 'Action', | ||
| }, | ||
| { | ||
| id: 4, | ||
| id: '00000000-0000-0000-0000-000000000004', | ||
| image: './movie4.png', | ||
| name: 'Inception', | ||
| year: 2010, | ||
| genre: 'Action & Thriller', | ||
| }, | ||
| { | ||
| id: 5, | ||
| id: '00000000-0000-0000-0000-000000000005', | ||
| image: './movie5.png', | ||
| name: 'Avengers: War of infinity', | ||
| year: 2018, | ||
| genre: 'Action', | ||
| }, | ||
| { | ||
| id: 6, | ||
| id: '00000000-0000-0000-0000-000000000006', | ||
| image: './movie6.png', | ||
| name: 'Reservoir dogs', | ||
| year: 1991, | ||
| genre: 'Criminal', | ||
| }, | ||
| ]; | ||
|
|
||
| /** | ||
| After typing following code should lead to type errors: | ||
| moviesData[0] = null; | ||
| moviesData[0].genre = null; | ||
| */ | ||
|
|
||
| function Catalog(props) { | ||
| return ( | ||
| <div className="catalog-body"> | ||
|
|
@@ -58,7 +75,7 @@ function Catalog(props) { | |
| <Sort></Sort> | ||
| </div> | ||
| <div className="items-counter"> | ||
| <ItemsCount ItemsCount={moviesData.length}></ItemsCount> | ||
| <ItemsCount itemsCount={moviesData.length}></ItemsCount> | ||
| </div> | ||
| <div className="items-list"> | ||
| {moviesData.map(dataItem => ( | ||
|
|
@@ -75,4 +92,4 @@ function Catalog(props) { | |
| ); | ||
| } | ||
|
|
||
| export default Catalog; | ||
| export { Catalog }; | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| .genres-navigation { | ||
| width: 25%; | ||
|
|
||
| ul { | ||
| display: flex; | ||
| list-style-type: none; | ||
| } | ||
|
|
||
| li { | ||
| flex: auto; | ||
| } | ||
|
|
||
| &__tab:hover { | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| &__tab:visited { | ||
| color: gray; | ||
| } | ||
|
|
||
| &__genre { | ||
| color: white; | ||
|
|
||
| &--active { | ||
| border-bottom: 4px #f65261 solid; | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+1
to
+28
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Чем хорош SASS - например, что можно вкладывать селекторы один в другой, чтобы не утонуть в куче стилей элементов блока. SASS - это пре-процессор сителей, который умеет в переменные, импорты стилей из других модулей со стилями и много чего еще. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,19 @@ | ||
| import { useState } from 'react'; | ||
| import './genres-selector-component.css'; | ||
| import 'bulma/css/bulma.css'; | ||
| import makeBEM from 'easy-bem'; | ||
| //import 'bulma/css/bulma.css'; | ||
|
|
||
| let genresData = [ | ||
| import './genres-selector-component.scss'; | ||
|
|
||
| const bem = makeBEM('genres-navigation'); | ||
|
|
||
| type GenreType = 'ALL' | 'DOCUMENTARY' | 'COMEDY' | 'HORROR' | 'CRIME'; | ||
|
|
||
| interface Genre { | ||
| readonly name: GenreType; | ||
| isActive: boolean; | ||
| } | ||
|
|
||
| let genresData: Array<Genre> = [ | ||
| { name: 'ALL', isActive: true }, | ||
| { name: 'DOCUMENTARY', isActive: false }, | ||
| { name: 'COMEDY', isActive: false }, | ||
|
Comment on lines
+9
to
19
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Опять необязательный вариант типизации структуры для жанра. Такая схема позволит контролировать, что в идентификатор жанра не засунули что-то кроме 'ALL', 'DOCUMENTARY' и проч. |
||
|
|
@@ -12,13 +23,13 @@ let genresData = [ | |
|
|
||
| function GenresSelector() { | ||
| return ( | ||
| <nav className="genres-navigation"> | ||
| <nav className={bem()}> | ||
| <ul> | ||
| {genresData.map(genre => ( | ||
| <li className=".genres-navigation__tab"> | ||
| <li className={bem('tab')}> | ||
| <a | ||
| href="#" | ||
| className={genre.isActive ? 'genres-navigation_active' : ''} | ||
| className={bem('genre', { active: genre.isActive })} | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вот тут пример работы с модификаторами по BEM-методологии |
||
| > | ||
| {genre.name} | ||
| </a> | ||
|
|
@@ -29,4 +40,4 @@ function GenresSelector() { | |
| ); | ||
| } | ||
|
|
||
| export default GenresSelector; | ||
| export { GenresSelector }; | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| .item-counter { | ||
| &__label { | ||
| font-size: 20px; | ||
| } | ||
|
|
||
| &__label_number { | ||
| font-weight: bolder; | ||
| } | ||
| } | ||
|
Comment on lines
+1
to
+9
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Еще пример вложения стилей |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,25 @@ | ||
| import { useState } from 'react'; | ||
| import './item-count-component.css'; | ||
| import React from 'react'; | ||
| import makeBEM from 'easy-bem'; | ||
|
|
||
| function ItemsCount(props) { | ||
| import './item-count-component.scss'; | ||
|
|
||
| const bem = makeBEM('item-counter'); | ||
|
|
||
| interface ItemsCountProps { | ||
| itemsCount?: number; | ||
| } | ||
|
|
||
| const ItemsCount: React.FC<ItemsCountProps> = props => { | ||
| return ( | ||
| <> | ||
| <label className="item-counter-label item-counter-label_number"> | ||
| {props.ItemsCount}{' '} | ||
| </label> | ||
| <label className="item-counter-label">movies found</label> | ||
| </> | ||
| <div className={bem()}> | ||
| <label className={bem('label_number')}>{props.itemsCount} </label> | ||
| <label className={bem('label')}>movies found</label> | ||
| </div> | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| ItemsCount.defaultProps = { | ||
| itemsCount: 0, | ||
| }; | ||
|
Comment on lines
+21
to
+23
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут пример исопльзования значений попросов по-умолчанию |
||
|
|
||
| export default ItemsCount; | ||
| export { ItemsCount }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Таким образом
moviesDataтипизировать в текущих условиях не обязательно, просто хотел похвастаться системой типов в typescript.ReadonlyArrayзапретит менять ссылки в массиве (т.е. присвивать элементу другой объект), аReadonlyзапретит менять поля эленментаMovie