Skip to content

Commit

Permalink
[Enhancement #51] Comments are now listed
Browse files Browse the repository at this point in the history
  • Loading branch information
LaChope authored and blcham committed Sep 30, 2021
1 parent 2defb67 commit cbfa66e
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 191 deletions.
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"html-webpack-plugin": "^4.3.0",
"javascript-time-ago": "^2.3.8",
"jest": "^26.0.1",
"prettier": "^2.0.5",
"query-string": "^6.13.5",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Answer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { FormGenContext } from '../contexts/FormGenContext';
import { ConfigurationContext } from '../contexts/ConfigurationContext';
import HelpIcon from './HelpIcon';
import JsonLdUtils from 'jsonld-utils';
import QuestionCommentIcon from "./QuestionCommentIcon";
import QuestionCommentIcon from "./comment/QuestionCommentIcon";

const Answer = (props) => {
const formGenContext = React.useContext(FormGenContext);
Expand Down
32 changes: 0 additions & 32 deletions src/components/CommentForm.jsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/Question.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import MediaContent from './MediaContent';
import { CaretSquareUp, CaretSquareDown, InfoCircle } from '../styles/icons';
import { ConfigurationContext } from '../contexts/ConfigurationContext';
import classNames from 'classnames';
import QuestionCommentIcon from "./QuestionCommentIcon";
import QuestionCommentIcon from "./comment/QuestionCommentIcon";

// TODO Remove once the pretty layout is tested
const PRETTY_ANSWERABLE_LAYOUT = true;
Expand Down
112 changes: 0 additions & 112 deletions src/components/QuestionCommentIcon.jsx

This file was deleted.

44 changes: 0 additions & 44 deletions src/components/SubmittedComment.jsx

This file was deleted.

62 changes: 62 additions & 0 deletions src/components/comment/CommentForm.jsx
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;
21 changes: 21 additions & 0 deletions src/components/comment/CommentList.jsx
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;
23 changes: 23 additions & 0 deletions src/components/comment/CommentView.jsx
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;
18 changes: 18 additions & 0 deletions src/components/comment/NewComment.jsx
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;

0 comments on commit cbfa66e

Please sign in to comment.