Creadno lista pero con problemas en paginate
This commit is contained in:
@@ -19,7 +19,7 @@ const range = (from, to, step = 1) => {
|
|||||||
return range;
|
return range;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Paginate extends Component {
|
export default class Paginate extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
const {totalRecords = 0, pageLimit = 30, pageNeighbours = 0, currentPage = 1} = props;
|
const {totalRecords = 0, pageLimit = 30, pageNeighbours = 0, currentPage = 1} = props;
|
||||||
@@ -135,24 +135,21 @@ export class Paginate extends Component {
|
|||||||
const blocks = pages.map((page, index) => {
|
const blocks = pages.map((page, index) => {
|
||||||
if (page === LEFT_PAGE) return (
|
if (page === LEFT_PAGE) return (
|
||||||
<li key={page} className="page-item">
|
<li key={page} className="page-item">
|
||||||
<a className="page-link" href={this.makePageLink(this.state.currentPage - 1)}
|
<a className="page-link" href={this.makePageLink(this.state.currentPage - 1)} onClick={this.handleMoveLeft}>
|
||||||
onClick={this.handleMoveLeft}>
|
|
||||||
<span>« Anterior</span>
|
<span>« Anterior</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
if (page === RIGHT_PAGE) return (
|
if (page === RIGHT_PAGE) return (
|
||||||
<li key={page} className="page-item">
|
<li key={page} className="page-item">
|
||||||
<a className="page-link" href={this.makePageLink(this.state.currentPage + 1)}
|
<a className="page-link" href={this.makePageLink(this.state.currentPage + 1)} onClick={this.handleMoveRight}>
|
||||||
onClick={this.handleMoveRight}>
|
|
||||||
<span>Siguiente »</span>
|
<span>Siguiente »</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<li key={page} className={`page-item ${currentPage === page ? 'active' : ''}`}>
|
<li key={page} className={`page-item ${currentPage === page ? 'active' : ''}`}>
|
||||||
<a className="page-link" href={this.makePageLink(index)}
|
<a className="page-link" href={this.makePageLink(page)} onClick={this.handleClick(page)}>{page}</a>
|
||||||
onClick={this.handleClick(page)}>{page}</a>
|
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,15 +1,34 @@
|
|||||||
import React, {Fragment} from "react";
|
import React, {Fragment} from "react";
|
||||||
import queryString from "query-string";
|
import queryString from "query-string";
|
||||||
import ReactJson from "react-json-view";
|
import ReactJson from "react-json-view";
|
||||||
|
|
||||||
import {searchArtist} from "../services/search_service";
|
import {searchArtist} from "../services/search_service";
|
||||||
import SearchBar from "./SearchBar";
|
import SearchBar from "./SearchBar";
|
||||||
import {Paginate} from "./Paginate";
|
import Paginate from "./Paginate";
|
||||||
|
import {Link, navigate} from "@reach/router";
|
||||||
|
|
||||||
|
class SearchArtist extends React.Component {
|
||||||
|
render() {
|
||||||
|
const artist = this.props.artist;
|
||||||
|
return (
|
||||||
|
<li className='entity'>
|
||||||
|
<Link to={`/artist/${artist.id}`}>
|
||||||
|
<span>{artist.name}</span>
|
||||||
|
<span className='small'>{[artist.type, artist.country].filter(Boolean).join(' - ')}</span>
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const SearchList = () => (
|
class SearchList extends React.Component {
|
||||||
<div>
|
render() {
|
||||||
</div>
|
const artists = this.props.artists;
|
||||||
);
|
return <ul className='entity_list'>
|
||||||
|
{artists.map((artist) => <SearchArtist key={artist.id} artist={artist}/>)}
|
||||||
|
</ul>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class Search extends React.Component {
|
export class Search extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -31,23 +50,15 @@ export class Search extends React.Component {
|
|||||||
this.loadArtists(this.state.params.query, this.state.params.page);
|
this.loadArtists(this.state.params.query, this.state.params.page);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps, prevState, snapshot) {
|
|
||||||
if (prevState.params !== this.state.params) {
|
|
||||||
this.loadArtists(this.state.params.query, this.state.params.page);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
makeLink(page) {
|
makeLink(page) {
|
||||||
return `/search?query=${this.state.params.query}&page=${page}`
|
return `/search?query=${this.state.params.query}&page=${page}`
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePageChange(page) {
|
async handlePageChange(page) {
|
||||||
this.props.navigate(page).then(() => {
|
await navigate(page)
|
||||||
this.setState({
|
this.setState({params: this.loadParams()}, () => {
|
||||||
artists: null,
|
this.loadArtists(this.state.params.query, this.state.params.page);
|
||||||
params: this.loadParams()
|
});
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleQueryChange(query) {
|
handleQueryChange(query) {
|
||||||
@@ -88,7 +99,11 @@ export class Search extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadParams() {
|
loadParams() {
|
||||||
return queryString.parse(this.props.location.search);
|
const parsed = queryString.parse(this.props.location.search);
|
||||||
|
return {
|
||||||
|
query: parsed.query,
|
||||||
|
page: parsed.page
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadArtists(query, page) {
|
loadArtists(query, page) {
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
:root {
|
:root {
|
||||||
--gray: hsl(0, 0%, 85%);
|
--gray: hsl(0, 0%, 85%);
|
||||||
|
--dark-gray: hsl(0, 0%, 30%);
|
||||||
|
--black: hsl(0, 0%, 20%);
|
||||||
|
--emerald: hsl(138, 70%, 50%);
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@@ -7,6 +10,7 @@ body {
|
|||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 0 1em;
|
padding: 0 1em;
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
|
color: var(--black);
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
@@ -18,6 +22,11 @@ button {
|
|||||||
border: 1px var(--gray) solid;
|
border: 1px var(--gray) solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: var(--emerald);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
.nav {
|
.nav {
|
||||||
display: flex;
|
display: flex;
|
||||||
min-height: 3.25em;
|
min-height: 3.25em;
|
||||||
@@ -45,13 +54,13 @@ ul.pagination {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.page-link {
|
.page-link {
|
||||||
color: black;
|
color: var(--black);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
padding: 0 1em;
|
padding: 0 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-item.active a{
|
.page-item.active a {
|
||||||
color: blue;
|
color: var(--emerald);
|
||||||
}
|
}
|
||||||
|
|
||||||
.full-width {
|
.full-width {
|
||||||
@@ -72,4 +81,35 @@ ul.pagination {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ul.entity_list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.entity {
|
||||||
|
height: 4em;
|
||||||
|
border: 1px var(--gray) solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.entity:not(:first-child) {
|
||||||
|
border-top: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.entity a {
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
height: 100%;
|
||||||
|
padding-left: 1em;
|
||||||
|
text-decoration: none;
|
||||||
|
color: var(--black);
|
||||||
|
|
||||||
|
justify-content: center;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.entity a .small {
|
||||||
|
font-size: .8em;
|
||||||
|
color: var(--dark-gray);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user