diff --git a/webclient/src/utils.js b/webclient/src/utils.js index 6a05471..311ce6e 100644 --- a/webclient/src/utils.js +++ b/webclient/src/utils.js @@ -13,16 +13,46 @@ export const sourceLink = (story) => { ); }; +export const storyScore = story => { + if (!story.score) { + return null; + } + return (<>{story.score} points); +}; +export const storyAuthor = story => { + if (!story.author) { + return null; + } + if (story.author_link) { + return (<>by {story.author}); + } + return <>by {story.author}; +}; + +export const storyCommentsLink = story => { + if (!story.num_comments) { + return null; + } + return ( 99 ? "hot" : ""} + to={"/" + story.id + "/c"}> + {story.num_comments} comment{story.num_comments !== 1 && "s"} + ); +}; + export const infoLine = (story) => (
- {story.score} points by {story.author_link ? {story.author} : story.author} - ​ {moment.unix(story.date).fromNow()} - ​ on {story.source} | ​ - 99 ? "hot" : ""} - to={"/" + story.id + "/c"}> - {story.num_comments} comment{story.num_comments !== 1 && "s"} - + {[ + <>{moment.unix(story.date).fromNow()} {storyAuthor(story)}, + <>{story.source}, + storyScore(story),/*​*/ + storyCommentsLink(story) + ].filter(e => e).map((e, i) => ( + <> + {i !== 0 ? <> • : <>} + {e} + + ))}
);