Issue #2 Pagina de canciones

This commit is contained in:
Daniel Cortes
2020-06-17 20:47:58 -04:00
parent e0c0be7ef8
commit 2b4826e50b
3 changed files with 61 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
import React from "react";
export const Comments = (props) => {
return (
<div>
<h3>Comentarios</h3>
<p>No aun :3</p>
</div>
)
}

View File

@@ -15,6 +15,7 @@ import {ArtistView} from "./views/Artist";
import {DiscView} from "./views/Disc"; import {DiscView} from "./views/Disc";
import {ReleaseView} from "./views/Release"; import {ReleaseView} from "./views/Release";
import {Recomended} from "./views/Recomended"; import {Recomended} from "./views/Recomended";
import {SongView} from "./views/Song";
const Main = (props) => { const Main = (props) => {
const navigate = (query) => props.history.push(`/search?query=${query}`); const navigate = (query) => props.history.push(`/search?query=${query}`);
@@ -46,6 +47,7 @@ const App = () => (
<Route path='/artist/:mbid?' component={ArtistView}/> <Route path='/artist/:mbid?' component={ArtistView}/>
<Route path='/disc/:mbid?' component={DiscView}/> <Route path='/disc/:mbid?' component={DiscView}/>
<Route path='/release/:mbid?' component={ReleaseView}/> <Route path='/release/:mbid?' component={ReleaseView}/>
<Route path='/song/:mbid?' component={SongView}/>
<Route exact path='/' component={Main}/> <Route exact path='/' component={Main}/>
<Route path='*' component={NoRoute}/> <Route path='*' component={NoRoute}/>
</Switch> </Switch>

49
src/views/Song.jsx Normal file
View File

@@ -0,0 +1,49 @@
import React, {Fragment, useEffect, useState} from 'react';
import {capitalize, toDuration} from "../services/utils";
import {getSong} from "../services/entity_service";
import {Entity} from "../components/Entity";
import {Comments} from "../components/Comments";
const Song = (props) => {
const song = props.song;
if(!song) {
return <Fragment/>
}
let subtitle = ''
if(song.disambiguation && song.length) {
subtitle = <span>{capitalize(song.disambiguation)} - [{toDuration(song.length)}]</span>
}else if (song.disambiguation) {
subtitle = <span>{capitalize(song.disambiguation)}</span>
}else if (song.length) {
subtitle = <span>[{toDuration(song.length)}]</span>
}
return <Entity title={song.title} subtitle={subtitle} buttonText='Agregar a mi lista'/>
}
export const SongView = (props) => {
const mbid = props.match.params.mbid;
const [song, setSong] = useState(null);
useEffect(() => {
if (mbid) {
getSong(mbid).then((result) => setSong(result));
}
}, [mbid]);
return (
<div>
<Song song={song}/>
{song &&
<Comments/>
}
</div>
)
}