From 8bb2d174bfea464b0ccc418307bac7195b462f2c Mon Sep 17 00:00:00 2001 From: Jason Schwarzenberger Date: Thu, 26 Nov 2020 12:11:45 +1300 Subject: [PATCH] info line adjustments. --- webclient/src/utils.js | 46 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) 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} + + ))}
);