Skip to content

Commit

Permalink
refactor(Webpage): function for getting the author/s string.
Browse files Browse the repository at this point in the history
  • Loading branch information
YishaiGlasner committed Mar 16, 2023
1 parent 9141c72 commit 6c1b247
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions static/js/WebPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import Sefaria from "./sefaria/sefaria";
import React from "react";

const WebPage = ({authors, isHebrew, favicon, url, domain, title, description, articleSource, anchorRef}) => {
const authorsNum = authors?.length;
const author = authorsNum > 1 ? 'Authors' : 'Author';
function getAuthorsString(lang, authors) {
function getAuthorsAsString(lang, authors) {
const finalJoiner = (lang === 'he') ? ' ו' : ' and ';
function arrangeAuthorName(authorName) {
return authorName.split(', ').reverse().join(' ');
Expand All @@ -17,16 +15,23 @@ const WebPage = ({authors, isHebrew, favicon, url, domain, title, description, a
}
return authors?.reduce((accumulator, author, i) => addAuthorToString(accumulator, author, i), '');
}
const authorsNames = getAuthorsString(isHebrew ? 'he' : 'en', authors);
function getAuthorString(authors) {
const authorsNum = authors?.length;
const author = authorsNum > 1 ? 'Authors' : 'Author';
const authorsNames = getAuthorsAsString(isHebrew ? 'he' : 'en', authors);
return (
authorsNames ? <div className="authors">
<InterfaceText>{author}</InterfaceText>: {authorsNames}
</div> : null
);
}
return (<div className={"webpage" + (isHebrew ? " hebrew" : "")} key={url}>
<img className="icon" src={favicon} />
<a className="title" href={url} target="_blank">{title}</a>
<div className="domain">{domain}</div>
{description ? <div className="description">{description}</div> : null}
<div className="webpageMetadata">
{authorsNames ? <div className="authors">
<InterfaceText>{author}</InterfaceText>: {authorsNames}
</div> : null}
{getAuthorString(authors)}
{articleSource ? <div className="articleSource">
<InterfaceText>Source</InterfaceText>: {articleSource.title}{articleSource.related_parts ? ` ${articleSource.related_parts}`: ''}
</div> : null}
Expand Down

0 comments on commit 6c1b247

Please sign in to comment.