Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/65 #66

Merged
merged 1 commit into from
May 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions src/components/_App_CommentSection/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useRef } from 'react'
import { BrowserRouter as Router, Switch, Route, Link, Redirect } from 'react-router-dom'
import './style.scss'
import { Feed, Icon, Header, Loader, Button, Comment, Form } from 'semantic-ui-react'
import PropTypes from 'prop-types'
Expand Down Expand Up @@ -47,7 +48,7 @@ class CommentSection extends React.Component {
that.setState({ comments: result })
})
.catch((error) => {
console.error(error)
location.href = '/'
})
}

Expand Down Expand Up @@ -144,27 +145,31 @@ class CommentSection extends React.Component {
Comments
</Header>

{this.state.comments.length == 0 ? (
<span className="empty-comments">Sorry. We could not find any comments.</span>
{this.state.comments ? (
this.state.comments.length == 0 ? (
<span className="empty-comments">Sorry. We could not find any comments.</span>
) : (
this.state.comments.map((comment) => {
return (
<Comment key={comment.id}>
{comment.avatar == '' ? (
<Comment.Avatar href={'/app/user/' + comment.email} src={unknownAvatar} />
) : (
<Comment.Avatar href={'/app/user/' + comment.email} src={process.env.REACT_APP_API_URL + '/' + comment.avatar.replace('./', '')} />
)}
<Comment.Content>
<Comment.Author href={'/app/user/' + comment.email}>{comment.name}</Comment.Author>
<Comment.Metadata>
<span>{this.getDate(comment.created_at)}</span>
</Comment.Metadata>
<Comment.Text dangerouslySetInnerHTML={{ __html: this.decodeHTMLEntities(comment.comment_content) }}></Comment.Text>
</Comment.Content>
</Comment>
)
})
)
) : (
this.state.comments.map((comment) => {
return (
<Comment key={comment.id}>
{comment.avatar == '' ? (
<Comment.Avatar href={'/app/user/' + comment.email} src={unknownAvatar} />
) : (
<Comment.Avatar href={'/app/user/' + comment.email} src={process.env.REACT_APP_API_URL + '/' + comment.avatar.replace('./', '')} />
)}
<Comment.Content>
<Comment.Author href={'/app/user/' + comment.email}>{comment.name}</Comment.Author>
<Comment.Metadata>
<span>{this.getDate(comment.created_at)}</span>
</Comment.Metadata>
<Comment.Text dangerouslySetInnerHTML={{ __html: this.decodeHTMLEntities(comment.comment_content) }}></Comment.Text>
</Comment.Content>
</Comment>
)
})
<Redirect to="/" />
)}

<Form onSubmit={this.handleSubmit} reply>
Expand Down