11import React from "react" ;
22
33const getOriginFromUrl = ( str ) => {
4- if ( ! str ) {
4+ if ( ! str ) {
55 return null ;
66 }
7- try {
7+ try {
88 const url = new window . URL ( str ) ;
9- return url . origin ;
10- } catch ( err ) {
9+ return url . origin ;
10+ } catch ( err ) {
1111 // console.log(err);
1212 return str ;
1313 }
14- }
14+ } ;
1515
16- export default ( props ) => {
16+ const getClassForPoints = ( points = 0 ) => {
17+ if ( points >= 50 && points < 100 ) {
18+ return "text-brown" ;
19+ } if ( points >= 100 ) {
20+ return "text-orange" ;
21+ }
22+ return null ;
23+ } ;
24+
25+ const ListItem = ( props ) => {
1726 const {
18- num_comments, // Number of comments
27+ num_comments : numComments , // Number of comments
1928 points, // Vote Count
2029 title,
2130 url,
22- author,
23- created_at
31+ author
2432 } = props . data ;
25- if ( ! title ) {
33+ if ( ! title ) {
2634 return null ;
2735 }
28-
29- const getClassForPoints = ( points = 0 ) => {
30- if ( points >= 50 && points < 100 ) {
31- return "text-brown"
32- } else if ( points >= 100 ) {
33- return "text-orange" ;
34- } else {
35- return null ;
36- }
37- }
3836 const className = getClassForPoints ( points ) ;
3937 return (
4038 < tr className = "row-item" >
41- < td className = "row-item__td" > { num_comments || "-" } </ td >
39+ < td className = "row-item__td" > { numComments || "-" } </ td >
4240 < td className = { `row-item__td ${ className } ` } > { points || "-" } </ td >
4341 < td className = "row-item__td" >
4442 < span className = "caret-upvote" > </ span >
4543 </ td >
4644 < td className = "row-item__td" >
4745 < div className = "row-item__info clearfix" >
4846 < div className = "row-item__info--title" >
49- < a href = { url } target = "__blank" suppressHydrationWarning = { true } >
47+ < a href = { url } target = "__blank" >
5048 { title }
5149 </ a >
52- < small > { getOriginFromUrl ( url ) } </ small >
50+ < small suppressHydrationWarning = { true } > { getOriginFromUrl ( url ) } </ small >
5351 </ div >
5452 < div className = "row-item__info--meta" >
5553 < div className = "row-item__info--meta-block" >
5654 < small > by < strong > { author } </ strong > </ small >
5755 </ div >
5856 < div className = "row-item__info--meta-block" >
5957 < small >
60- < a href = "#" > hide</ a >
58+ < a href = "#" > hide</ a >
6159 </ small >
6260 </ div >
6361 </ div >
6462 </ div >
6563 </ td >
6664 </ tr >
67- )
68- }
65+ ) ;
66+ } ;
67+
68+ export default ListItem ;
0 commit comments