Skip to content

Commit

Permalink
improve CommentViewer getHeader() function
Browse files Browse the repository at this point in the history
  • Loading branch information
glenwid committed Apr 26, 2021
1 parent 27c9383 commit 513c177
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/CodeReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const CodeReview: React.FC<CodeReviewProps> = ({
</Pre>
)}
</Highlight>
<div style={{paddingLeft: "0.5em", paddingRight: "0.5em"}}>
<div style={{paddingLeft: "0.5em", paddingRight: "0.5em", paddingTop: "1em"}}>
<CommentViewer comments={getResults()}
result={true}
onReplyCreated={(value) => onCommentCreated(createComment(value, author))}
Expand Down
56 changes: 51 additions & 5 deletions src/components/CommentViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,61 @@ export const CommentViewer: React.FC<CommentViewerProps> = ({comments,
setOldToggleState(toggle)
}, [toggle, oldToggleState, activeKey, toggleCollapse])

const countInfos = () => {
let count = 0;
comments.forEach(element => {
if(element.type === ("mildInfo" || "severeInfo")) {
count++
}
})
return count
}

const countComments = () => {
let count = 0;
comments.forEach(element => {
if(element.type === "comment") {
count++
}
})
return count
}

const getCommentWording = () => {
if(countComments() === 1) {
return " comment"
} else {
return " comments"
}
}

const getInfoWording = () => {
if(countInfos() === 1) {
return " info"
} else {
return " infos"
}
}

const getHeader = () => {
if(result) {
return "Result"
}
const commentNumber = comments.length;
if(commentNumber === 1) {
return commentNumber + " comment";
} else {
return commentNumber + " comments";

if(countComments() > 0) {
if(countInfos() > 0) {
return countComments()
+ getCommentWording()
+ ", "
+ countInfos()
+ getInfoWording()
} else {
return countComments()
+ getCommentWording()
}
}
if(countInfos() > 0) {
return countInfos() + getInfoWording()
}
}

Expand Down

0 comments on commit 513c177

Please sign in to comment.