-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix #67 / Fix] Fix author label that was not displayed correctly; Fi…
…x map key issue
- Loading branch information
Showing
2 changed files
with
29 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong.
blcham
Collaborator
|
||
} | ||
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.
Sorry, something went wrong.
blcham
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 = () => { | ||
|
@@ -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> | ||
); | ||
|
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