aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/components/Thread.js
diff options
context:
space:
mode:
Diffstat (limited to 'vnext/src/components/Thread.js')
-rw-r--r--vnext/src/components/Thread.js25
1 files changed, 16 insertions, 9 deletions
diff --git a/vnext/src/components/Thread.js b/vnext/src/components/Thread.js
index 90a7be90..22972752 100644
--- a/vnext/src/components/Thread.js
+++ b/vnext/src/components/Thread.js
@@ -1,10 +1,8 @@
import React, { useEffect, useState, useRef } from 'react';
+import PropTypes from 'prop-types';
import ReactRouterPropTypes from 'react-router-prop-types';
-import { UserType } from './Types';
-
-import { Link } from 'react-router-dom';
-import moment from 'moment';
+import { UserType, MessageType } from './Types';
import Message from './Message';
import MessageInput from './MessageInput';
@@ -73,6 +71,14 @@ function Comment({ msg, visitor, active, setActive, postComment }) {
);
}
+Comment.propTypes = {
+ msg: MessageType.isRequired,
+ visitor: UserType.isRequired,
+ active: PropTypes.bool.isRequired,
+ setActive: PropTypes.func.isRequired,
+ postComment: PropTypes.func.isRequired
+};
+
export default function Thread(props) {
const [message, setMessage] = useState(props.location.state || {});
const [replies, setReplies] = useState([]);
@@ -88,7 +94,7 @@ export default function Thread(props) {
if (props.connection) {
props.connection.removeEventListener('msg', onReply);
}
- }
+ };
}, [props.connection]);
let loadReplies = () => {
document.body.scrollTop = 0;
@@ -113,20 +119,20 @@ export default function Thread(props) {
).catch(ex => {
console.log(ex);
});
- }
+ };
let onReply = (json) => {
const msg = JSON.parse(json.data);
if (msg.mid == message.mid) {
setReplies([...this.state.replies, msg]);
}
- }
+ };
let postComment = (template) => {
const { mid, rid, body, attach } = template;
comment(mid, rid, body, attach).then(res => {
loadReplies();
})
.catch(console.log);
- }
+ };
const loaders = Math.min(message.replies || 0, 10);
return (
@@ -165,5 +171,6 @@ Thread.propTypes = {
location: ReactRouterPropTypes.location,
history: ReactRouterPropTypes.history,
match: ReactRouterPropTypes.match,
- visitor: UserType.isRequired
+ visitor: UserType.isRequired,
+ connection: PropTypes.shape.isRequired
};