-
Notifications
You must be signed in to change notification settings - Fork 0
Added some changes #9
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: master
Are you sure you want to change the base?
Changes from all commits
e641478
a4b6359
258673c
0070e1b
870acaa
5b352f1
3bf4ba5
4c2a7bd
1063316
c67773a
30b3cc2
a6cf178
78ff687
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
| /coverage | ||
|
|
||
| # production | ||
| /build | ||
| # /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
|
|
||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| const BASE_URL = | ||
| "https://mate-academy.github.io/phone-catalogue-static/api/phones"; | ||
| //https://mate-academy.github.io/phone-catalogue-static/api/phones/motorola-xoom-with-wi-fi.json | ||
| export const getAll = async () => { | ||
| const response = await fetch(`${BASE_URL}.json`); | ||
| const phones = await response.json(); | ||
|
|
||
| return phones; | ||
| }; | ||
|
|
||
| export const getCurrentPhone = async phone => { | ||
| const response = await fetch(`${BASE_URL}/${phone}.json`); | ||
| const data = await response.json(); | ||
|
|
||
| return data; | ||
| }; |
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import React from "react"; | ||
| import { NavLink } from "react-router-dom"; | ||
|
|
||
| import Select from "./components/Select"; | ||
| import config from "../config"; | ||
|
|
||
| const DataTable = ({ | ||
| visibleItems, | ||
| onHeaderClick, | ||
| onHandleCheck, | ||
| checkedItems, | ||
| onMainCheck, | ||
| filteredItems, | ||
| showChecked, | ||
| onShowAllChecked, | ||
| perPage, | ||
| onPerPageChange | ||
| }) => { | ||
| return ( | ||
| <div className="Table-wrapper"> | ||
| <table className="table"> | ||
| <thead> | ||
| <tr className="thead-dark Table__headers"> | ||
| <th> | ||
| <input | ||
| type="checkbox" | ||
| checked={checkedItems.length === filteredItems.length} | ||
| onChange={onMainCheck.bind(this)} | ||
| name="main" | ||
| value="main" | ||
| /> | ||
| </th> | ||
| {Object.keys(config).map(key => ( | ||
| <th | ||
| key={key} | ||
| className={config[key].isSortable && "Table__sorting"} | ||
| onClick={ | ||
| config[key].isSortable ? () => onHeaderClick(key) : null | ||
| } | ||
| > | ||
| {key} | ||
| </th> | ||
| ))} | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {visibleItems.map(item => { | ||
| return ( | ||
| <tr key={item.id}> | ||
| <td> | ||
| <input | ||
| type="checkbox" | ||
| checked={checkedItems.includes(item.id)} | ||
|
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. тут можно в |
||
| onChange={onHandleCheck.bind(this)} | ||
|
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. здесь тоже не понятно, что за |
||
| name={item.id} | ||
| value={item.id} | ||
| /> | ||
| </td> | ||
| {Object.keys(config).map(key => { | ||
| if (key === "name") { | ||
| return ( | ||
| <td key={key}> | ||
| <NavLink to={`/${item.id}`}>{item[key]}</NavLink> | ||
| </td> | ||
| ); | ||
| } | ||
|
|
||
| return <td key={key}>{item[key]}</td>; | ||
| })} | ||
| </tr> | ||
| ); | ||
| })} | ||
| </tbody> | ||
| </table> | ||
| <button className="CheckAll__btn" onClick={onShowAllChecked.bind(this)}> | ||
| {showChecked ? "Show all" : "Show checked"} | ||
| </button> | ||
| <Select perPage={perPage} onPerPageChange={onPerPageChange.bind(this)} /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default DataTable; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import React from "react"; | ||
|
|
||
| const Pagination = ({ | ||
| isTop, | ||
| page = 1, | ||
| count = 20, | ||
| perPage = 3, | ||
| onPageChange | ||
| }) => { | ||
| const pagesCount = Math.ceil(count / perPage) + 1; | ||
|
|
||
| const pages = []; | ||
|
|
||
| for (let i = 1; i < pagesCount; i++) { | ||
| pages.push(i); | ||
| } | ||
| if (!isTop) { | ||
| return ( | ||
| <div className="Pagination"> | ||
| {pages.map(item => ( | ||
| <button | ||
| key={item} | ||
| className={ | ||
| item === page | ||
| ? "Pagination__active Pagination__btn" | ||
| : "Pagination__btn" | ||
| } | ||
| onClick={() => onPageChange(item)} | ||
| > | ||
| {item} | ||
| </button> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } else { | ||
| return ( | ||
| <div className="Pagination"> | ||
| {page !== 1 && ( | ||
| <button | ||
| className="Pagination__back" | ||
| onClick={() => onPageChange(page - 1)} | ||
| > | ||
| ← | ||
| </button> | ||
| )} | ||
| {pages.map(item => { | ||
|
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. Не совсем оптимальное решение через |
||
| if (item === page || item === page + 1 || item === page - 1) { | ||
| return ( | ||
| <button | ||
| key={item} | ||
| className={ | ||
| item === page | ||
| ? "Pagination__active Pagination__btn" | ||
| : "Pagination__btn" | ||
| } | ||
| onClick={() => onPageChange(item)} | ||
| > | ||
| {item} | ||
| </button> | ||
| ); | ||
| } | ||
| })} | ||
| {page !== pages.length && ( | ||
| <button | ||
| className="Pagination__next" | ||
| onClick={() => onPageChange(page + 1)} | ||
| > | ||
| → | ||
| </button> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| export default Pagination; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import React from "react"; | ||
|
|
||
| const Search = ({ onChangeQuery, visibleQuery }) => { | ||
| return ( | ||
| <div className="md-form active-purple active-purple-2 mb-3"> | ||
| <input | ||
| className="Search" | ||
| type="text" | ||
| placeholder="Search" | ||
| aria-label="Search" | ||
| onChange={onChangeQuery} | ||
| value={visibleQuery} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default Search; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import React from "react"; | ||
|
|
||
| const Select = ({ perPage = 3, onPerPageChange }) => { | ||
| return ( | ||
| <select | ||
| className="Select browser-default custom-select" | ||
| onChange={onPerPageChange} | ||
| value={perPage} | ||
| > | ||
| <option value="3">3</option> | ||
| <option value="5">5</option> | ||
| <option value="10">10</option> | ||
| <option value="20">20</option> | ||
| </select> | ||
| ); | ||
| }; | ||
|
|
||
| export default Select; |
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.
какой-то здесь странный
bind. Оно без него не работает?