-
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.
[Enhancement #51] Comments are now listed
- Loading branch information
Showing
14 changed files
with
200 additions
and
191 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, {useContext, useState} from "react"; | ||
import {Button, Form} from "react-bootstrap"; | ||
import {ConfigurationContext} from "../../contexts/ConfigurationContext"; | ||
|
||
const CommentForm = (props) => { | ||
const context = useContext(ConfigurationContext); | ||
|
||
const [author, setAuthor] = useState(''); | ||
const [timestamp, setTimestamp] = useState(null); | ||
const [commentValue, setCommentValue] = useState(''); | ||
|
||
const getAuthor = () => { | ||
const users = context.options.users; | ||
const currentUser = context.options.currentUser; | ||
|
||
const currentUserId = users.find(c => c.id === currentUser); | ||
setAuthor(currentUserId.label) | ||
} | ||
|
||
const getTimeStamp = () => { | ||
setTimestamp(Date.now()); | ||
} | ||
|
||
const commentValueChangeHandler = (e) => { | ||
setCommentValue(e.target.value); | ||
getTimeStamp(); | ||
getAuthor(); | ||
} | ||
|
||
const submitHandler = (e) => { | ||
e.preventDefault(); | ||
|
||
const comment = { | ||
author: author, | ||
timestamp: timestamp, | ||
commentValue: commentValue | ||
}; | ||
props.onSaveComment(comment); | ||
console.log(comment) | ||
setCommentValue(''); | ||
} | ||
return ( | ||
<Form onSubmit={submitHandler}> | ||
<Form.Group className="mb-3" controlId="formBasicComment"> | ||
<Form.Label>Comments</Form.Label> | ||
<Form.Control | ||
name="comment" | ||
as="textarea" | ||
placeholder="Write your comments here" | ||
required | ||
value={commentValue} | ||
onChange={commentValueChangeHandler} | ||
/> | ||
</Form.Group> | ||
<Button variant="primary" type="submit"> | ||
Submit | ||
</Button> | ||
</Form> | ||
) | ||
} | ||
|
||
export default CommentForm; |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from "react"; | ||
import CommentView from "./CommentView"; | ||
|
||
const CommentList = (props) => { | ||
return ( | ||
<> | ||
{props.comments.map((comment) => ( | ||
<> | ||
<CommentView | ||
author={comment.author} | ||
timestamp={comment.timestamp} | ||
commentValue={comment.commentValue} | ||
/> | ||
<br/> | ||
</> | ||
))} | ||
</> | ||
) | ||
} | ||
|
||
export default CommentList; |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from "react"; | ||
import TimeAgo from "javascript-time-ago"; | ||
import en from "javascript-time-ago/locale/en"; | ||
|
||
const CommentView = (props) => { | ||
TimeAgo.addDefaultLocale(en); | ||
const time = new TimeAgo('en-US'); | ||
const timeAgo = time.format(props.timestamp) | ||
|
||
return ( | ||
<div className="comment-content"> | ||
<div className="row"> | ||
<span className="col-md-auto comment-author">{props.author}</span> | ||
<span className="text-muted col-sm-auto timestamp">{timeAgo}</span> | ||
</div> | ||
<div className="row"> | ||
<span className="comment-value col">{props.commentValue}</span> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default CommentView; |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react"; | ||
import CommentForm from "./CommentForm"; | ||
|
||
const NewComment = (props) => { | ||
const saveCommentHandler = (enteredComment) => { | ||
const comment = { | ||
...enteredComment, | ||
id: Math.random().toString() | ||
} | ||
props.onAddComment(comment); | ||
} | ||
|
||
return ( | ||
<CommentForm onSaveComment={saveCommentHandler}/> | ||
) | ||
} | ||
|
||
export default NewComment; |
Oops, something went wrong.