From c050d39586ec8c4b5cc79cab3e94831d1cd9fbde Mon Sep 17 00:00:00 2001 From: Daniel Cortes Date: Thu, 4 Jun 2020 05:10:24 -0400 Subject: [PATCH] Songs! --- src/components/Search.jsx | 90 ++++++++++++++++++++++++++++++++++++--- src/styles/main.scss | 15 ++++--- src/svg/disc.svg | 5 +-- 3 files changed, 96 insertions(+), 14 deletions(-) diff --git a/src/components/Search.jsx b/src/components/Search.jsx index 00315e0..1931df8 100644 --- a/src/components/Search.jsx +++ b/src/components/Search.jsx @@ -9,12 +9,92 @@ import {Tab, TabList, TabPanel, Tabs} from "react-tabs"; import {ReactComponent as DiscSVG} from "../svg/disc.svg"; -const SearchPlaceholder = () => ( +const SearchPlaceholder = (props) => ( - {[...Array(10)].map((e, i) =>
  • )} + {[...Array(10)].map((e, i) =>
  • )} ) +class SearchSong extends React.Component { + render() { + const song = this.props.song; + return ( +
  • + +
    + {song.title} + {song.artist[0].name} +
    + +
  • + ) + } +} + +class SearchSongs extends React.Component { + constructor(props) { + super(props); + this.state = {songs: null, paginate: null, page: 1} + } + + componentDidMount = _ => this.loadSongs(this.props.query, this.state.page); + + componentDidUpdate = (prevProps, prevState) => { + if (prevProps.query !== this.props.query || prevState.page !== this.state.page) { + this.loadSongs(this.props.query, this.state.page) + + if (prevState.page !== this.state.page) { + this.setState({songs: null}) + } else { + this.setState({songs: null, paginate: null}) + } + } + }; + + makeLink = page => `/search/song?query=${this.state.query}&page=${page}`; + + handlePageChange = page => { + this.setState({songs: null, page: page}) + this.props.onPageChange(page); + } + + loadSongs = (query, page) => { + page = page ? page : 1; + + searchSong(query, page).then((response) => { + this.setState({ + songs: response.recordings, + paginate: response.paginate + }) + }) + }; + + render = () => { + let songs = ; + if (this.state.songs) { + songs = this.state.songs.map((song) => ); + } + + let paginate; + if (this.state.paginate) { + const total = this.state.paginate.total; + const currentPage = this.state.paginate.current_page; + const pageLimit = this.state.paginate.per_page; + + paginate = + } + + return ( + +
      + {songs} +
    + {paginate} +
    + ) + }; +} + class SearchDisc extends React.Component { render() { const disc = this.props.disc; @@ -71,7 +151,7 @@ class SearchDiscs extends React.Component { }; render = () => { - let discs = ; + let discs = ; if (this.state.discs) { discs = this.state.discs.map((disc) => ); } @@ -151,7 +231,7 @@ class SearchArtists extends React.Component { }; render = () => { - let artists = ; + let artists = ; if (this.state.artists) { artists = this.state.artists.map((artist) => ); } @@ -214,7 +294,7 @@ class SearchTabs extends React.Component { -

    Canciones

    + ) } diff --git a/src/styles/main.scss b/src/styles/main.scss index 7d54c15..0402cb5 100644 --- a/src/styles/main.scss +++ b/src/styles/main.scss @@ -127,7 +127,7 @@ ul.entity_list { display: flex; flex-direction: column; - li.artist, li.disc { + li.artist, li.disc, li.song { border: 1px var(--gray-2) solid; &:not(:first-child) { @@ -143,6 +143,7 @@ ul.entity_list { text-decoration: none; color: var(--black); align-items: center; + height: 100%; .description { display: flex; @@ -160,24 +161,26 @@ ul.entity_list { } li.artist { - a { - height: 4rem; - } + height: 4rem; } li.disc { + height: 14rem; a { - height: 14rem; - .coverart { object-fit: cover; width: 200px; height: 200px; margin: 1rem; + border: 1px solid var(--gray-2) } } } + + li.song { + height: 4rem; + } } diff --git a/src/svg/disc.svg b/src/svg/disc.svg index ff04ac2..6be4b79 100644 --- a/src/svg/disc.svg +++ b/src/svg/disc.svg @@ -1,7 +1,6 @@ - - - + +