Skip to content

Commit

Permalink
[Fix #67 / Fix] Fix author label that was not displayed correctly; Fi…
Browse files Browse the repository at this point in the history
…x map key issue
  • Loading branch information
LaChope committed Nov 3, 2021
1 parent 51643e5 commit ec915d4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
22 changes: 11 additions & 11 deletions src/components/comment/CommentList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import Constants from "../../constants/Constants";
const CommentList = (props) => {
const addComments = () => {
return (
props.comment.map((comment) => (
<div key={JSON.stringify(comment[Constants.HAS_TIMESTAMP])}
className="comment-list-items">
<CommentView
commentValue={comment[Constants.HAS_COMMENT_VALUE]}
author={comment[Constants.HAS_AUTHOR] ? comment[Constants.HAS_AUTHOR] : null}
timestamp={comment[Constants.HAS_TIMESTAMP]}
/>
</div>
)));
props.comment.map((comment, index) => (

This comment has been minimized.

Copy link
@blcham

blcham Nov 3, 2021

Collaborator

I don't think "index" is stable thing here ... comments are not orderd within the comment list i guess ... so comment[Constants.HAS_TIMESTAMP] feels to me more correct

<div key={index}
className="comment-list-items">
<CommentView
commentValue={comment[Constants.HAS_COMMENT_VALUE]}
author={comment[Constants.HAS_AUTHOR] ? comment[Constants.HAS_AUTHOR] : null}
timestamp={comment[Constants.HAS_TIMESTAMP]}
/>
</div>
)));
}

const renderSortedComments = () => {
return addComments().sort((a,b) => {
return addComments().sort((a, b) => {
return new Date(a.HAS_TIMESTAMP).getTime()
- new Date(b.HAS_TIMESTAMP).getTime()
}).reverse();
Expand Down
34 changes: 18 additions & 16 deletions src/components/comment/CommentView.jsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
import React, {useState} from "react";
import React, {useContext, useState} from "react";
import TimeAgo from "javascript-time-ago";
import en from "javascript-time-ago/locale/en";
import Constants from "../../constants/Constants";
import {ConfigurationContext} from "../../contexts/ConfigurationContext";

const UNKNOWN_AUTHOR = "Unknown author";

const CommentView = (props) => {
const { options } = useContext(ConfigurationContext);

TimeAgo.addLocale(en);
const time = new TimeAgo('en-US');

const [show, setShow] = useState(false);

const parseJsonComment = (value, constant) => {
const jsonComment = JSON.parse(JSON.stringify(value));
return jsonComment[constant];
}
const getAuthorLabel = () => {
const users = options.users;
const currentUser = options.currentUser;
const currentUserId = users.find(c => c.id === currentUser);

const getAuthor = () => {
if (props.author) {
return parseJsonComment(props.author, [Constants.HAS_AUTHOR]);
} else return UNKNOWN_AUTHOR;
return "... " + currentUserId.label;

This comment has been minimized.

Copy link
@blcham

blcham Nov 3, 2021

Collaborator

badly named variable. Id does not have label. Current user has label.

I guess it should be named opposite way arround:
currentUserId --> currentUser
currentUser --> currentUserId

}
return UNKNOWN_AUTHOR;
}

const getSplitAuthor = () => {
let commentAuthor = {};
const getFullAuthor = () => {
if (props.author) {
commentAuthor = parseJsonComment(props.author, [Constants.HAS_AUTHOR]);
return "..." + commentAuthor.split('/people/').pop();

This comment has been minimized.

Copy link
@blcham

blcham Nov 3, 2021

Collaborator

I do not see how this functionality was replaced to return fragment of URL.

This comment has been minimized.

Copy link
@blcham

blcham Nov 3, 2021

Collaborator
} else return UNKNOWN_AUTHOR;
return props.author[Constants.HAS_AUTHOR];
}
return UNKNOWN_AUTHOR;
}

const getTimeAgo = () => {
return time.format(parseJsonComment(props.timestamp, [Constants.HAS_TIMESTAMP]));
return time.format(props.timestamp[Constants.HAS_TIMESTAMP]);
}

const onMouseEventHandler = () => {
Expand All @@ -42,12 +44,12 @@ const CommentView = (props) => {
<div className="comment-content">
<div className="row">
<span className="col-auto comment-author" onMouseEnter={onMouseEventHandler} onMouseLeave={onMouseEventHandler}>
{show ? getAuthor() : getSplitAuthor()}
{show ? getFullAuthor() : getAuthorLabel()}
</span>
<span className="col-auto text-muted comment-timestamp">{getTimeAgo()}</span>
</div>
<div className="row">
<span className="col comment-value">{parseJsonComment(props.commentValue, [Constants.HAS_COMMENT_VALUE])}</span>
<span className="col comment-value">{props.commentValue[Constants.HAS_COMMENT_VALUE]}</span>
</div>
</div>
);
Expand Down

0 comments on commit ec915d4

Please sign in to comment.