Skip to content

Commit 4e36cc7

Browse files
authored
Merge pull request #21 from OrcaPracticas/add/routers
➕ADD: Integracion del router
2 parents c9ad228 + 9ed2640 commit 4e36cc7

6 files changed

Lines changed: 49 additions & 34 deletions

File tree

Tools/Tools.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ class Tools {
33
const DATA = data.map((item) => {
44
const { id, title, urls = {} } = item;
55
const { logo_image: { original = "" } } = urls;
6+
67
return {
78
id,
89
logo: original,
910
title,
10-
uri: `${link}?id=${id}`,
11+
uri: {
12+
slug: title.toLocaleLowerCase().replace(/\s/g, "-"),
13+
id,
14+
},
1115
};
1216
});
1317
return DATA;
@@ -17,13 +21,18 @@ class Tools {
1721
const DATA = data.map((item) => {
1822
const {
1923
id, duration,
20-
title,
24+
channel, title,
2125
} = item;
2226
return {
2327
id,
2428
duration,
2529
title,
26-
uri: `${link}?id=${id}`,
30+
uri: {
31+
slugChannel: channel.title.toLocaleLowerCase().replace(/\s/g, "-"),
32+
idChannel: channel.id,
33+
slug: title.toLocaleLowerCase().replace(/\s/g, "-"),
34+
id,
35+
},
2736
};
2837
});
2938
return DATA;

components/Cards.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Dependencias
2-
import Link from "next/link";
32
import PropTypes from "prop-types";
43
import React from "react";
54

5+
import { Link } from "../router";
6+
67
/**
78
* Información por cada canal habilitado.
89
*
@@ -17,8 +18,8 @@ const Card = ({ channels }) => (
1718
logo = "/default-podcast.png", uri,
1819
} = channel;
1920
return (
20-
<Link href={uri} key={`Card-${id}`}>
21-
<a className="channel" href={uri}>
21+
<Link route="channel" params={uri} key={`Card-${id}`}>
22+
<a className="channel" >
2223
<img src={logo} alt={title} />
2324
<h3>{title}</h3>
2425
</a>

components/Header.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Dependencias
22
import Head from "next/head";
3-
import Link from "next/link";
43
import PropTypes from "prop-types";
54
import React from "react";
65

6+
import { Link } from "../router";
7+
78
/**
89
* Header general correspondientes a las paginas del sitio.
910
*
@@ -26,8 +27,8 @@ const Header = (props) => {
2627
<header>
2728
{
2829
(back) ? (
29-
<Link href={back}>
30-
<a className="back" href={back}>&lt; Regresar </a>
30+
<Link route="channel" params={back}>
31+
<a className="back" > &lt; Regresar </a>
3132
</Link>
3233
) : "PodCast"
3334
}

components/PodCastList.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Dependencias
2-
import Link from "next/link";
32
import PropTypes from "prop-types";
43
import React from "react";
54

5+
import { Link } from "../router";
6+
67
/**
78
* Listdado de los ultimos podcast.
89
*
@@ -16,8 +17,8 @@ const PodCastList = ({ podcasts }) => (
1617
duration, id, title, uri,
1718
} = podcast;
1819
return (
19-
<Link href={uri} key={`List-${id}`}>
20-
<a className="podcast" href={uri}>
20+
<Link route="podcast" params={uri} key={`List-${id}`}>
21+
<a className="podcast">
2122
<h3>{ title }</h3>
2223
<div className="meta">
2324
{`${Math.ceil(duration / 60)} minutes`}

pages/channel.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,36 @@ const Channel = ({
2929
(statusCode !== 200)
3030
? <Error statusCode={statusCode} />
3131
: (
32-
<>
33-
{
34-
(channels.length > 0) && (
35-
<>
36-
<h2>Series</h2>
37-
<Cards channels={channels} />
38-
</>
39-
)
40-
}
32+
<>
33+
{
34+
(channels.length > 0) && (
35+
<>
36+
<h2>Series</h2>
37+
<Cards channels={channels} />
38+
</>
39+
)
40+
}
4141

42-
{
43-
(list.length > 0) && (
44-
<>
45-
<h2>Ultimos Podcasts</h2>
46-
<PodCastList podcasts={list} />
47-
</>
48-
)
49-
}
42+
{
43+
(list.length > 0) && (
44+
<>
45+
<h2>Ultimos Podcasts</h2>
46+
<PodCastList podcasts={list} />
47+
</>
48+
)
49+
}
5050

51-
<style jsx>
52-
{`
51+
<style jsx>
52+
{`
5353
h2 {
5454
padding: 15px;
5555
font-size: 2em;
5656
font-weight: 600;
5757
margin: 0;
5858
}
5959
`}
60-
</style>
61-
</>
60+
</style>
61+
</>
6262
)
6363
}
6464
</Layout>

pages/podcast.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ PodCast.getInitialProps = async ({ query, res }) => {
6262
RESPOSE.player.channel = channel.title;
6363
RESPOSE.player.poster = urls.image;
6464
RESPOSE.player.title = title;
65-
RESPOSE.header.back = `/channel?id=${channel.id}`;
65+
RESPOSE.header.back = {
66+
slug: channel.title.toLocaleLowerCase().replace(/\s/g, "-"),
67+
id: channel.id,
68+
};
6669
}
6770
} catch (error) {
6871
res.statusCode = 503;

0 commit comments

Comments
 (0)