diff --git a/vnext/src/ui/Post.js b/vnext/src/ui/Post.js
index 3dc23613..dc1c7a9d 100644
--- a/vnext/src/ui/Post.js
+++ b/vnext/src/ui/Post.js
@@ -7,23 +7,25 @@ import qs from 'qs';
import MessageInput from './MessageInput';
-import { post } from '../api';
+import { post, update } from '../api';
-function PostComponent(props) {
+function PostComponent({ location, visitor, history }) {
+ let draftMessage = (location.state || {}).draft || {};
let params = qs.parse(window.location.search.substring(1));
let postMessage = (template) => {
const { attach, body } = template;
- post(body, attach)
+ const postAction = draftMessage.mid ? update(draftMessage.mid, 0, body) : post(body, attach);
+ postAction
.then(response => {
if (response.status === 200) {
const msg = response.data.newMessage;
- this.props.history.push(`/${this.props.visitor.uname}/${msg.mid}`);
+ history.push(`/${visitor.uname}/${msg.mid}`);
}
}).catch(console.log);
};
return (
-
+
*weather It is very cold today!
@@ -33,6 +35,7 @@ function PostComponent(props) {
export default memo(PostComponent);
PostComponent.propTypes = {
+ location: ReactRouterPropTypes.location,
history: ReactRouterPropTypes.history.isRequired,
visitor: UserType
};
diff --git a/vnext/src/ui/Thread.js b/vnext/src/ui/Thread.js
index 30fa0723..6cbb5188 100644
--- a/vnext/src/ui/Thread.js
+++ b/vnext/src/ui/Thread.js
@@ -12,13 +12,13 @@ import Button from './Button';
import { format, embedUrls } from '../utils/embed';
-import { getMessages, comment, markReadTracker, fetchUserUri } from '../api';
+import { getMessages, comment, update, markReadTracker, fetchUserUri, updateAvatar } from '../api';
import './Thread.css';
let isMounted;
-function Comment({ msg, visitor, active, setActive, postComment }) {
+function Comment({ msg, draft, visitor, active, setActive, onStartEditing, postComment }) {
const embedRef = useRef();
const msgRef = useRef();
const [author, setAuthor] = useState(msg.user);
@@ -33,16 +33,16 @@ function Comment({ msg, visitor, active, setActive, postComment }) {
useEffect(() => {
isMounted = true;
if (author.uri) {
- fetchUserUri(author.uri).then(response => {
- if (isMounted) {
- setAuthor(response.data);
- }
- });
+ fetchUserUri(author.uri).then(response => {
+ if (isMounted) {
+ setAuthor(response.data);
+ }
+ });
}
return () => {
- isMounted = false;
+ isMounted = false;
};
-}, [author.uri]);
+ }, [author.uri]);
return (
@@ -59,6 +59,13 @@ function Comment({ msg, visitor, active, setActive, postComment }) {
visitor.uid > 0 ? (
<>
{active === msg.rid || setActive(msg.rid)}>Reply}
+ {
+ visitor.uid == msg.user.uid &&
+ <>
+ ·
+ onStartEditing(msg)}>Edit
+ >
+ }
>
) : (
<>
@@ -77,18 +84,18 @@ function Comment({ msg, visitor, active, setActive, postComment }) {
}
- {
- msg.photo &&
-
- }
+ {
+ msg.photo &&
+
+ }
{
- active === msg.rid && Write a comment...
+ active === msg.rid && Write a comment...
}
@@ -97,9 +104,11 @@ function Comment({ msg, visitor, active, setActive, postComment }) {
Comment.propTypes = {
msg: MessageType.isRequired,
+ draft: PropTypes.string.isRequired,
visitor: UserType.isRequired,
active: PropTypes.number.isRequired,
setActive: PropTypes.func.isRequired,
+ onStartEditing: PropTypes.func.isRequired,
postComment: PropTypes.func.isRequired
};
@@ -108,6 +117,7 @@ export default function Thread(props) {
const [replies, setReplies] = useState([]);
const [loading, setLoading] = useState(false);
const [active, setActive] = useState(0);
+ const [editing, setEditing] = useState({});
useEffect(() => {
setActive(0);
loadReplies();
@@ -157,19 +167,26 @@ export default function Thread(props) {
}, [message]);
let postComment = (template) => {
const { mid, rid, body, attach } = template;
- comment(mid, rid, body, attach).then(res => {
+ let commentAction = editing.rid ? update(mid, editing.rid, body) : comment(mid, rid, body, attach);
+ commentAction.then(res => {
+ setEditing({});
loadReplies();
})
.catch(console.log);
};
+ let startEditing = (reply) => {
+ setActive(reply.replyto);
+ setEditing(reply);
+ };
+
const loaders = Math.min(message.replies || 0, 10);
return (
<>
{
message.mid ? (
- {active === (message.rid || 0) && Write a comment...}
+ {active === (message.rid || 0) && Write a comment...}
) : (
@@ -179,7 +196,7 @@ export default function Thread(props) {
{
!loading ? replies.map((msg) => (
-
+
)) : (
<>
@@ -201,5 +218,5 @@ Thread.propTypes = {
history: ReactRouterPropTypes.history,
match: ReactRouterPropTypes.match,
visitor: UserType.isRequired,
- connection: PropTypes.object.isRequired
+ connection: PropTypes.object.isRequired,
};
diff --git a/vnext/src/ui/__tests__/MessageInput-test.js b/vnext/src/ui/__tests__/MessageInput-test.js
index 7ac69ed0..9603d1fe 100644
--- a/vnext/src/ui/__tests__/MessageInput-test.js
+++ b/vnext/src/ui/__tests__/MessageInput-test.js
@@ -12,31 +12,35 @@ const testMessage = {
to: {}
};
-window.matchMedia = window.matchMedia || function () {
+window.matchMedia = window.matchMedia || function() {
return {
matches: true,
- addListener: function () { },
- removeListener: function () { }
+ addListener: function() { },
+ removeListener: function() { }
};
};
+function createMessageInput(data, onFocus, onSend, draft) {
+ return create(
, {
+ createNodeMock: (element) => {
+ if (element.type === 'textarea') {
+ // mock a focus function
+ return {
+ focus: onFocus,
+ style: {}
+ };
+ }
+ return null;
+ }
+ });
+}
+
it('Gives immediate focus on to textarea on load', () => {
let focused = false;
act(() => {
- create(
{ }} />, {
- createNodeMock: (element) => {
- if (element.type === 'textarea') {
- // mock a focus function
- return {
- focus: () => {
- focused = true;
- },
- style: {}
- };
- }
- return null;
- }
- });
+ createMessageInput(testMessage, () => {
+ focused = true;
+ }, () => { });
});
expect(focused).toEqual(true, 'textarea was not focused');
});
@@ -46,17 +50,7 @@ it('Submits on ctrl-enter', () => {
const onSend = jest.fn();
var messageInput = null;
act(() => {
- messageInput = create(, {
- createNodeMock: (element) => {
- if (element.type === 'textarea') {
- return {
- focus: () => { },
- style: {}
- };
- }
- return null;
- }
- });
+ messageInput = createMessageInput(testMessage, () => {}, onSend);
});
let textarea = messageInput.root.findByType('textarea');
act(() => {
@@ -93,3 +87,12 @@ it('Submits on ctrl-enter', () => {
});
expect(textarea.props.value).toEqual('', 'Value should be cleared after submit');
});
+
+it('Show draft text', () => {
+ var messageInput;
+ act(() => {
+ messageInput = createMessageInput(testMessage, () => {}, () => {}, 'yo');
+ });
+ let textarea = messageInput.root.findByType('textarea');
+ expect(textarea.props.value).toEqual('yo', 'Value should match draft');
+});
--
cgit v1.2.3