|
| 1 | +// Dependencias |
| 2 | +import PropTypes from "prop-types"; |
| 3 | +import React from "react"; |
| 4 | +import "isomorphic-fetch"; |
| 5 | + |
| 6 | +// Componentes |
| 7 | +import { PlayerAudio, Layout } from "../components"; |
| 8 | +import { api, audio } from "./config.json"; |
| 9 | + |
| 10 | +/** |
| 11 | + * Player que permite esuchar el audio. |
| 12 | + * |
| 13 | + * @param {Object} Header Configuraciones para el header. |
| 14 | + * @param {Object} player Configuracion correspondiente el reproductor. |
| 15 | + */ |
| 16 | +const PodCast = ({ header, player }) => ( |
| 17 | + <Layout header={header}> |
| 18 | + <PlayerAudio {...player} /> |
| 19 | + </Layout> |
| 20 | +); |
| 21 | + |
| 22 | +/** |
| 23 | + * Metodo encargado de realizar la peticion al Api. |
| 24 | + * |
| 25 | + * @param {String} query Id correspondiente al consulta. |
| 26 | + * @return {Promise} |
| 27 | + */ |
| 28 | +PodCast.getInitialProps = async ({ query }) => { |
| 29 | + const REQUEST = await fetch(`${api}${audio}/${query.id}.mp3`); |
| 30 | + const { body: { audio_clip: mp3 = { } } } = await REQUEST.json(); |
| 31 | + const { channel = {}, title = "", urls = {} } = mp3; |
| 32 | + const PROPS = { |
| 33 | + audioMp3: urls.high_mp3, |
| 34 | + channel: channel.title, |
| 35 | + poster: urls.image, |
| 36 | + title, |
| 37 | + }; |
| 38 | + return { header: { back: `/channel?id=${channel.id}` }, player: PROPS }; |
| 39 | +}; |
| 40 | + |
| 41 | +PodCast.prototype = { |
| 42 | + header: PropTypes.shape(PropTypes.object), |
| 43 | + player: PropTypes.shape(PropTypes.object), |
| 44 | +}; |
| 45 | + |
| 46 | +PodCast.defaultProps = { |
| 47 | + header: {}, |
| 48 | + player: {}, |
| 49 | +}; |
| 50 | + |
| 51 | +export default PodCast; |
0 commit comments