use of the podcast api and saving in the store · ifmcode/podcaster@b0f8ce1 · GitHub
Skip to content

Commit b0f8ce1

Browse files
committed
use of the podcast api and saving in the store
1 parent 4d3c550 commit b0f8ce1

3 files changed

Lines changed: 43 additions & 4 deletions

File tree

‎src/App.js‎

Lines changed: 2 additions & 1 deletion

‎src/screens/Home/Home.js‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
import "./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

58
const 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

‎src/services/data.js‎

Lines changed: 18 additions & 0 deletions

0 commit comments

Comments
 (0)