File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { BrowserRouter as Router , Routes , Route } from "react-router-dom" ;
2+ import React from 'react' ;
13import './App.css' ;
24import Home from "./screens/Home/Home" ;
35import Podcast from "./screens/Podcast/Podcast" ;
46import Episode from "./screens/Episode/Episode" ;
5- import { BrowserRouter as Router , Routes , Route } from "react-router-dom" ;
67
78const App = ( ) => {
89 return (
Original file line number Diff line number Diff line change 11import "./Home.css"
2- import React from 'react' ;
3- import { useSelector } from 'react-redux' ;
2+ import React , { useEffect } from 'react' ;
3+ import { useSelector , useDispatch } from 'react-redux' ;
4+ import moment from "moment/moment" ;
5+ import { requestPodcastList } from "../../services/data" ;
6+ import { updatePodcaster } from "../../redux/podcasterSlice" ;
47
58const Home = ( ) => {
6- const podcaster = useSelector ( state => state . podcaster ) ;
9+ const dispatch = useDispatch ( ) ,
10+ podcaster = useSelector ( state => state . podcaster ) ;
11+
12+ useEffect ( ( ) => {
13+ async function fetchData ( ) {
14+ const podcastList = await requestPodcastList ( ) ;
15+ podcastList && dispatch ( updatePodcaster ( {
16+ podcastList,
17+ lastUpdate : moment ( ) . valueOf ( )
18+ } ) ) ;
19+ }
20+
21+ if ( podcaster . status === "ZERO" ) {
22+ fetchData ( ) ;
23+ }
24+ } , [ podcaster . status ] ) ;
25+
726
827 return ( < >
928 < p className = "home-title" > Home:</ p >
1029 < p > Estado de la store: { podcaster . status } </ p >
30+ < p > Numero de podcasts: { podcaster . podcastList . length } </ p >
1131 </ > ) ;
1232}
1333
Original file line number Diff line number Diff line change 1+ async function requestPodcastList ( ) {
2+ return fetch ( "https://itunes.apple.com/us/rss/toppodcasts/limit=100/genre=1310/json" )
3+ . then ( ( res ) => res . json ( ) )
4+ . then ( ( data ) => {
5+ return data . feed . entry . map ( ( item ) => {
6+ return {
7+ id : item . id . attributes [ 'im:id' ] ,
8+ title : item ?. title . label ,
9+ author : item [ 'im:artist' ] . label ,
10+ image : item [ 'im:image' ] [ 0 ] . label
11+ }
12+ } ) ;
13+ } ) . catch ( ( err ) => console . log ( err ) ) ;
14+ }
15+
16+ export {
17+ requestPodcastList ,
18+ }
You can’t perform that action at this time.
0 commit comments