Skip to content

Commit 761af78

Browse files
committed
2 parents d6647fc + af30347 commit 761af78

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

src/components/top-stories/TopStories.jsx

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import moment from "moment";
33
import { useSelector } from "utils/react-redux-hooks";
44

55
import StoryTopic from "components/story-topic/StoryTopic";
6+
import placeholder from "assets/newsPlaceholder.png";
67

78
import { Date } from "components/story-topic-headers/StoryTopicHeaders.styles";
89
import { SeeAll } from "components/most-popular/MostPopular.styles";
@@ -16,38 +17,41 @@ import {
1617
} from "./TopStories.styles";
1718

1819
const TopStories = () => {
19-
const { story, width } = useSelector((state) => state.news);
20+
const { story } = useSelector((state) => state.news);
2021

2122
return (
2223
<div>
2324
<StoryTopic />
2425
<TopStoriesContainer>
25-
{story.slice(0, 3).map((data) => (
26-
<StoryContainer key={data.title}>
27-
<img
28-
src={
29-
width < 1200 ? data.multimedia[0].url : data.multimedia[3].url
30-
}
31-
alt="story"
32-
/>
33-
<TagContainer>
34-
<h1>
35-
<Tag>{data.section}</Tag>
36-
</h1>
37-
<Date margin="10px" width="30%">
38-
{moment(data.created_date).format("MMM DD, YYYY")}
39-
</Date>
40-
</TagContainer>
26+
{story.slice(0, 3).map((data) => {
27+
const url = data?.multimedia?.[0]?.url;
4128

42-
<Title header={data.title.split(" ")}>{data.title}</Title>
43-
<SubTitle>
44-
{data.abstract.split(" ").slice(0, 20).join(" ")}...
45-
</SubTitle>
46-
<SeeAll href={data.url} target="_blank" rel="noopener">
47-
Continue Reading
48-
</SeeAll>
49-
</StoryContainer>
50-
))}
29+
return (
30+
<StoryContainer key={data.title}>
31+
<img
32+
src={url ?? placeholder}
33+
alt="story"
34+
style={{ width: !url ? "400px" : "100%" }}
35+
/>
36+
<TagContainer>
37+
<h1>
38+
<Tag>{data.section}</Tag>
39+
</h1>
40+
<Date margin="10px" width="30%">
41+
{moment(data.created_date).format("MMM DD, YYYY")}
42+
</Date>
43+
</TagContainer>
44+
45+
<Title header={data.title.split(" ")}>{data.title}</Title>
46+
<SubTitle>
47+
{data.abstract.split(" ").slice(0, 20).join(" ")}...
48+
</SubTitle>
49+
<SeeAll href={data.url} target="_blank" rel="noopener">
50+
Continue Reading
51+
</SeeAll>
52+
</StoryContainer>
53+
);
54+
})}
5155
</TopStoriesContainer>
5256
</div>
5357
);

src/tests/components/__snapshots__/TopStories.test.js.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ exports[`Testing TopStories component Should match snapshot 1`] = `
264264
<img
265265
alt="story"
266266
src="https://static01.nyt.com/images/2020/12/19/us/covid-thanksgiving-effect-promo-1608423451574/covid-thanksgiving-effect-promo-1608423451574-thumbLarge.jpg"
267+
style={
268+
Object {
269+
"width": "100%",
270+
}
271+
}
267272
/>
268273
<styled.div>
269274
<div

0 commit comments

Comments
 (0)