|
|
@@ -1,57 +1,24 @@
|
|
|
import './AlbumList.css';
|
|
|
import InfiniteScroll from 'react-infinite-scroller';
|
|
|
import {useEffect} from 'react';
|
|
|
-import {formatDuration} from './utils';
|
|
|
-import logo from './logo.svg';
|
|
|
-import {getAlbums, getTracks, request} from './Api';
|
|
|
+import {getAlbums, request} from './Api';
|
|
|
+import Album from './Album';
|
|
|
|
|
|
-function _albumProps(albums, index) {
|
|
|
+function _albumProps(albums, index, props) {
|
|
|
if (index === 0) {
|
|
|
- return {showArtist: true, showType: true}
|
|
|
+ return {showArtist: !props.noArtist, showType: true}
|
|
|
}
|
|
|
|
|
|
if (albums[index-1].artist !== albums[index].artist) {
|
|
|
- return {showArtist: true, showType: true}
|
|
|
+ return {showArtist: !props.noArtist, showType: true}
|
|
|
}
|
|
|
|
|
|
let showType = (albums[index-1].type !== albums[index].type);
|
|
|
return {showType};
|
|
|
}
|
|
|
|
|
|
-function fetchTracks(album_id, type, dispatch) {
|
|
|
- const {url, options} = getTracks(album_id);
|
|
|
- request(url, options)
|
|
|
- .then(payload => dispatch({type, payload}))
|
|
|
- .catch(e => console.log(e))
|
|
|
-}
|
|
|
-
|
|
|
-function Album({album, showArtist, showType, dispatch}) {
|
|
|
- return (
|
|
|
- <div>
|
|
|
- {showArtist && (<h3>{album.artist}</h3>)}
|
|
|
- {showType && (<h4>{album.type}</h4>)}
|
|
|
- <div className="Album">
|
|
|
- <img src={album.cover || logo} alt={album.album} />
|
|
|
- <span className="Album-year">{album.year}</span>
|
|
|
- <span className="Album-country">{album.country}</span>
|
|
|
- <span className="Album-tracks">{album.track_count} @ {formatDuration(album.total_duration)}</span>
|
|
|
- <span className="Album-title">{album.album}</span>
|
|
|
- <span className="Album-publisher">{album.publisher}</span>
|
|
|
- <span className="Album-genre">{album.genre}</span>
|
|
|
- <div className="Album-actions">
|
|
|
- <button onClick={(e)=>fetchTracks(album.id, 'ALBUM_PLAY', dispatch)}>
|
|
|
- <svg viewBox="0 0 24 24"><g><path d="M8 5v14l11-7z"/></g></svg>
|
|
|
- </button>
|
|
|
- <button onClick={(e)=>fetchTracks(album.id, 'ALBUM_ENQUEUE', dispatch)}>
|
|
|
- <svg viewBox="0 0 24 24"><g><path d="M10 6h4v4h4v4h-4v4h-4v-4h-4v-4h4z"/></g></svg>
|
|
|
- </button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- )
|
|
|
-}
|
|
|
|
|
|
-function fetchAlbums(filters, page, dispatch) {
|
|
|
+export function fetchAlbums(filters, page, dispatch) {
|
|
|
const {filter, categories, latest} = filters;
|
|
|
const limit = 15;
|
|
|
const offset = page * limit;
|
|
|
@@ -74,7 +41,7 @@ function fetchAlbums(filters, page, dispatch) {
|
|
|
|
|
|
export default function AlbumList(props) {
|
|
|
const {albums, error, filters, dispatch, playerDispatch, scrollRef} = props;
|
|
|
- const title = filters.latest ? 'Latest' : 'Alphabetical';
|
|
|
+ const title = (!props.noTitle && (filters.latest ? 'Latest' : 'Alphabetical'));
|
|
|
|
|
|
useEffect(()=>{
|
|
|
fetchAlbums(filters, albums.page, dispatch);
|
|
|
@@ -82,7 +49,7 @@ export default function AlbumList(props) {
|
|
|
|
|
|
return (
|
|
|
<div className="AlbumList">
|
|
|
- <h2>{title}</h2>
|
|
|
+ {title && <h2>{title}</h2>}
|
|
|
{ error ? (
|
|
|
<div className="error">{error}></div>
|
|
|
) : (
|
|
|
@@ -95,7 +62,7 @@ export default function AlbumList(props) {
|
|
|
useWindow={false}
|
|
|
>
|
|
|
{albums.items.map((album, idx) => (
|
|
|
- <Album key={idx} album={album} dispatch={playerDispatch} {..._albumProps(albums.items, idx)} />
|
|
|
+ <Album key={idx} album={album} dispatch={playerDispatch} {..._albumProps(albums.items, idx, props)}/>
|
|
|
))}
|
|
|
</InfiniteScroll>
|
|
|
)
|