Skip to content

Commit 9fec7ee

Browse files
committed
feat: fetch youtube videos dynamically, move menu icons into one story
1 parent bf52f71 commit 9fec7ee

11 files changed

+76
-165
lines changed

src/dashboard/learn/Learn.tsx

Lines changed: 55 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,17 @@
11
import { makeStyles } from "@material-ui/core";
2-
import React from "react";
2+
import React, { useEffect, useState } from "react";
33
import Grid from "@material-ui/core/Grid";
44
import LearnItem from "./LearnItem";
55

6-
const videos = [
7-
{
8-
videoId: "EGmR676jMt8",
9-
title: "Community Call #19 (2021-03-24)",
10-
},
11-
{
12-
videoId: "oB3BeDNtN7g",
13-
title: "Community Call #18 (2021-03-17)",
14-
},
15-
{
16-
videoId: "zpwiZlbRRbs",
17-
title: "Community Call #16 (2021-02-24)",
18-
},
19-
{
20-
videoId: "A9bQPYvWb1o",
21-
title: "Community Call #14 (2021-02-10)",
22-
},
23-
{
24-
videoId: "Xha5l6t19Nk",
25-
title: "Community Call #13 (2021-02-03)",
26-
},
27-
{
28-
videoId: "tL5FRf-QvH8",
29-
title: "Community Call #12 (2021-01-27)",
30-
},
31-
{
32-
videoId: "CpeFQqFKksg",
33-
title: "Community Call #11 (2021-01-13)",
34-
},
35-
{
36-
videoId: "CFwnbgoMMBM",
37-
title: "Community Call #10 (2020-12-23)",
38-
},
39-
{
40-
videoId: "QTx7U6fPe_k",
41-
title: "Community Call #9 (2020-12-16)",
42-
},
43-
{
44-
videoId: "oBoDNGI8f3w",
45-
title: "Community Call #8 (2020-12-09)",
46-
},
47-
{
48-
videoId: "_KbbTmMA8WM",
49-
title: "Community Call #7 (2020-12-02)",
50-
},
51-
{
52-
videoId: "xi0sXZgG9NE",
53-
title: "Community Call #6 (2020-11-25)",
54-
},
55-
{
56-
videoId: "tt_TYVft4dQ",
57-
title: "Community Call #5 (2020-11-18)",
58-
},
59-
{
60-
videoId: "iNw5d1rZUqY",
61-
title: "Community Call #4 (2020-11-11)",
62-
},
63-
{
64-
videoId: "IBrVkzyCwb4",
65-
title: "Community Call #3 (2020-11-04)",
66-
},
67-
{
68-
videoId: "rC7zlCSuVEc",
69-
title: "Community Call #2 (2020-10-28)",
70-
},
71-
{
72-
videoId: "mGumdYAjDkY",
73-
title: "Community Call #1 (2020-10-21)",
74-
},
75-
];
6+
const fetchVideos = async () => {
7+
const response = await fetch(
8+
"https://youtube.googleapis.com/youtube/v3/search?channelId=UCemVkpcBJvbzciHp_5Ly4dw&key=AIzaSyAitbrvF7nJkOlarAMAcco7zwgN-msm0Nc&part=snippet,id&order=date&maxResults=6"
9+
);
10+
if (response.status === 200) {
11+
const responseJSON = await response.json();
12+
return responseJSON;
13+
}
14+
};
7615

7716
const useStyles = makeStyles(() => ({
7817
heading: {
@@ -81,17 +20,57 @@ const useStyles = makeStyles(() => ({
8120
},
8221
}));
8322

23+
interface Video {
24+
id: {
25+
videoId: string;
26+
};
27+
snippet: {
28+
title: string;
29+
};
30+
}
31+
32+
interface Videos {
33+
videoId: string;
34+
title: string;
35+
}
36+
8437
const Learn: React.FunctionComponent = () => {
8538
const classes = useStyles();
39+
const [videos, setVideos] = useState<Videos[]>([]);
40+
const [error, setError] = useState("");
41+
42+
const handleFetchVideos = async () => {
43+
try {
44+
const response = await fetchVideos();
45+
response.items.forEach((video: Video) => {
46+
setVideos((prevState) => {
47+
return [
48+
...prevState,
49+
{ videoId: video.id.videoId, title: video.snippet.title },
50+
];
51+
});
52+
});
53+
} catch (e) {
54+
setError("Unable to fetch videos.");
55+
}
56+
};
57+
58+
useEffect(() => {
59+
handleFetchVideos();
60+
}, []);
8661

8762
return (
8863
<div>
8964
<h1 className={classes.heading}>Learn</h1>
90-
<Grid container spacing={2}>
91-
{videos.map((video) => {
92-
return <LearnItem {...video} key={video.videoId} />;
93-
})}
94-
</Grid>
65+
{error ? (
66+
<p>{error}</p>
67+
) : (
68+
<Grid container spacing={2}>
69+
{videos.map((video) => {
70+
return <LearnItem {...video} key={video.videoId} />;
71+
})}
72+
</Grid>
73+
)}
9574
</div>
9675
);
9776
};

src/stories/ConsoleIcon.stories.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/stories/LearnIcon.stories.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/stories/MMBotIcon.stories.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/stories/MenuIcons.stories.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import { storiesOf } from "@storybook/react";
3+
import { ConsoleIcon } from "../common/components/icons/ConsoleIcon";
4+
import { LearnIcon } from "../common/components/icons/LearnIcon";
5+
import { MMBotIcon } from "../common/components/icons/MMBotIcon";
6+
import { OverviewIcon } from "../common/components/icons/OverviewIcon";
7+
import { SettingsIcon } from "../common/components/icons/SettingsIcon";
8+
import { TradeHistoryIcon } from "../common/components/icons/TradeHistoryIcon";
9+
import { TradeIcon } from "../common/components/icons/TradeIcon";
10+
import { WalletIcon } from "../common/components/icons/WalletIcon";
11+
12+
storiesOf("Menu Icons", module)
13+
.add("Overview Icon", () => <OverviewIcon />)
14+
.add("MMBot Icon", () => <MMBotIcon />)
15+
.add("Trade Icon", () => <TradeIcon />)
16+
.add("Trade History Icon", () => <TradeHistoryIcon />)
17+
.add("Wallet Icon", () => <WalletIcon />)
18+
.add("Console Icon", () => <ConsoleIcon />)
19+
.add("Learn Icon", () => <LearnIcon />)
20+
.add("Settings Icon", () => <SettingsIcon />);

src/stories/OverviewIcon.stories.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/stories/SettingsIcon.stories.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/stories/TradeHistoryIcon.stories.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/stories/TradeIcon.stories.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/stories/WalletIcon.stories.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)