Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55,220 changes: 27,634 additions & 27,586 deletions package-lock.json

Large diffs are not rendered by default.

81 changes: 42 additions & 39 deletions package.json
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"
]
}
}
43 changes: 30 additions & 13 deletions src/components/catalog-component/catalog-component.tsx
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>> = [
Copy link
Collaborator Author

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

{
id: 1,
id: '00000000-0000-0000-0000-000000000001',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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">
Expand All @@ -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 => (
Expand All @@ -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
Copy link
Collaborator Author

@AlexandrBeznosov AlexandrBeznosov May 30, 2022

Choose a reason for hiding this comment

The 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
Copy link
Collaborator Author

@AlexandrBeznosov AlexandrBeznosov May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Опять необязательный вариант типизации структуры для жанра. Такая схема позволит контролировать, что в идентификатор жанра не засунули что-то кроме 'ALL', 'DOCUMENTARY' и проч.
А вот это readonly name: GenreType; позволит задвать жанр только при инициализации экземпляра, мутировать после уже нельзя

Expand All @@ -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 })}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот тут пример работы с модификаторами по BEM-методологии

>
{genre.name}
</a>
Expand All @@ -29,4 +40,4 @@ function GenresSelector() {
);
}

export default GenresSelector;
export { GenresSelector };
8 changes: 4 additions & 4 deletions src/components/header-component/header-component.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';
import AddMovieButton from '../add-movie-component/add-movie-component.tsx';
import SearchButton from '../search-button-component/search-button-component.tsx';
import Search from '../search-component/search-component.tsx';
import AddMovieButton from '../add-movie-component/add-movie-component';
import SearchButton from '../search-button-component/search-button-component';
import { Search } from '../search-component/search-component';
import './header-component.css';

function Header() {
Expand All @@ -13,7 +13,7 @@ function Header() {
</div>
<div className="search-block">
<h1 className="search-block__tagline">FIND YOUR MOVIE</h1>
<div className='search-line'>
<div className="search-line">
<Search className="search-block__input" />
<SearchButton />
</div>
Expand Down
7 changes: 0 additions & 7 deletions src/components/items-count-component/item-count-component.css

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Еще пример вложения стилей

32 changes: 21 additions & 11 deletions src/components/items-count-component/items-count-component.tsx
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут пример исопльзования значений попросов по-умолчанию


export default ItemsCount;
export { ItemsCount };
Loading