@@ -3,6 +3,7 @@ import moment from "moment";
33import { useSelector } from "utils/react-redux-hooks" ;
44
55import StoryTopic from "components/story-topic/StoryTopic" ;
6+ import placeholder from "assets/newsPlaceholder.png" ;
67
78import { Date } from "components/story-topic-headers/StoryTopicHeaders.styles" ;
89import { SeeAll } from "components/most-popular/MostPopular.styles" ;
@@ -16,38 +17,41 @@ import {
1617} from "./TopStories.styles" ;
1718
1819const 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 ) ;
0 commit comments