import React from 'react'import * as ReactDOM from 'react-dom'import { formatDate } from 'front/date'import { IssueIcon, EditArticleIcon, NewArticleIcon, SeeIcon, SignupOrLogin, TimeIcon, TopicIcon } from 'front'import Comment from 'front/Comment'import CommentInput from 'front/CommentInput'import LikeArticleButton from 'front/LikeArticleButton'import { CommentType } from 'front/types/CommentType'import ArticleList from 'front/ArticleList'import routes from 'front/routes'import { cant } from 'front/cant'import CustomLink from 'front/CustomLink'// This also worked. But using the packaged one reduces the need to replicate// or factor out the webpack setup of the ourbigbook package.//import { ourbigbook_runtime } from 'ourbigbook/ourbigbook_runtime.js';import { ourbigbook_runtime } from 'ourbigbook/dist/ourbigbook_runtime.js'const Article = ({ article, articlesInSamePage, comments, commentsCount=0, commentCountByLoggedInUser=undefined, isIssue=false, issueArticle=undefined, issuesCount, latestIssues, loggedInUser, topIssues,}) => { const [curComments, setComments] = React.useState(comments) let seeAllCreateNew if (!isIssue) { seeAllCreateNew = <> {latestIssues.length > 0 && <> See all ({ issuesCount }){' '} } {loggedInUser ? New discussion : } } const articlesInSamePageMap = {} if (!isIssue) { for (const article of articlesInSamePage) { articlesInSamePageMap[article.topicId] = article } } const canEdit = isIssue ? !cant.editIssue(loggedInUser, article) : !cant.editArticle(loggedInUser, article) const renderRefCallback = React.useCallback( (elem) => { if (elem) { for (const h of elem.querySelectorAll('.h')) { const id = h.id const web = h.querySelector('.web') const toplevel = web.classList.contains('top') // TODO rename to article later on. let curArticle, isIndex if (isIssue) { if (!toplevel) { continue } curArticle = article } else if ( // Happens on user index page. id === '' ) { curArticle = article isIndex = true } else { curArticle = articlesInSamePageMap[id] if (!curArticle) { // Possible for Include headers. Maybe one day we will cover them. continue } } let mySlug if (loggedInUser) { mySlug = `${loggedInUser.username}/${curArticle.topicId}` } ReactDOM.render( <> {!isIssue && <> {' '} {!isIndex && {curArticle.topicCount}{toplevel ? <> By Others On Same Topic : ''} } {' '} {isIndex ? issuesCount : curArticle.issueCount}{toplevel ? ' Discussions' : ''} } {toplevel && <> {' '} {' '} {formatDate(article.updatedAt)} } {false && article.createdAt !== article.updatedAt && <> {' Updated: '} {formatDate(article.updatedAt)} } {canEdit ? <> {' '} {false && <>TODO: convert this a and all other injected links to Link. https://github.com/cirosantilli/ourbigbook/issues/274 } {toplevel && <> Edit} : <> {!isIssue && <> {curArticle.hasSameTopic ? <> {article.slug !== mySlug && <> {' '} {' '}{toplevel ? ' See My Version' : ''}{' '} } : <> {' '} {' '}{toplevel ? ' Create my own version' : ''}{' '} } } } , web ); } ourbigbook_runtime(elem); } }, [] ); return <>
{isIssue ? <>

Comments ({ commentsCount })

{curComments?.map((comment: CommentType) => )} : <>

Discussion ({ issuesCount })

{ seeAllCreateNew } { latestIssues.length > 0 ? <>

Latest threads

Top threads

{ seeAllCreateNew } :

There are no discussions about this article yet.

} }
}export default Article