From 32f7b50bb5c62d27def3f2e6d2839511c0b8f9a9 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Thu, 23 Jul 2015 09:39:29 -0400 Subject: adds predictive posting on the client --- web/react/components/create_post.jsx | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'web/react/components/create_post.jsx') diff --git a/web/react/components/create_post.jsx b/web/react/components/create_post.jsx index 377e7bd34..76f2bf262 100644 --- a/web/react/components/create_post.jsx +++ b/web/react/components/create_post.jsx @@ -65,10 +65,17 @@ module.exports = React.createClass({ post.channel_id = this.state.channelId; post.filenames = this.state.previews; - client.createPost(post, ChannelStore.getCurrent(), + var time = utils.getTimestamp(); + post.pending_post_id = user_id + ":"+ time; + post.user_id = user_id; + post.create_at = time; + post.root_id = this.state.rootId; + post.parent_id = this.state.parentId; + + var channel = ChannelStore.getCurrent(); + + client.createPost(post, channel, function(data) { - PostStore.storeDraft(data.channel_id, null); - this.setState({messageText: '', submitting: false, postError: null, previews: [], serverError: null}); this.resizePostHolder(); AsyncClient.getPosts(true); @@ -79,13 +86,25 @@ module.exports = React.createClass({ ChannelStore.setChannelMember(member); }.bind(this), function(err) { - var state = {}; - state.serverError = err.message; + var state = {} + + if (err.message === "Invalid RootId parameter") { + if ($('#post_deleted').length > 0) $('#post_deleted').modal('show'); + PostStore.removePendingPost(post.pending_post_id); + } else { + post.did_fail = true; + PostStore.updatePendingPost(post); + } state.submitting = false; this.setState(state); }.bind(this) ); + + post.is_loading = true; + PostStore.storePendingPost(post); + PostStore.storeDraft(channel.id, user_id, null); + this.setState({messageText: '', submitting: false, postError: null, previews: [], serverError: null}); } $('.post-list-holder-by-time').perfectScrollbar('update'); -- cgit v1.2.3-1-g7c22 From 5596a6b37c440522176fdc05217161d7de7e169c Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Thu, 23 Jul 2015 12:45:08 -0400 Subject: added client predictive commenting --- web/react/components/create_post.jsx | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'web/react/components/create_post.jsx') diff --git a/web/react/components/create_post.jsx b/web/react/components/create_post.jsx index 76f2bf262..8110f5886 100644 --- a/web/react/components/create_post.jsx +++ b/web/react/components/create_post.jsx @@ -214,20 +214,34 @@ module.exports = React.createClass({ var channelId = ChannelStore.getCurrentId(); if (this.state.channelId !== channelId) { var draft = PostStore.getCurrentDraft(); - this.setState({ - channelId: channelId, messageText: draft['message'], initialText: draft['message'], submitting: false, - serverError: null, postError: null, previews: draft['previews'], uploadsInProgress: draft['uploadsInProgress'] - }); + + var previews = []; + var messageText = ''; + var uploadsInProgress = 0; + if (draft && draft['previews'] && draft['message']) { + previews = draft['previews']; + messageText = draft['message']; + uploadsInProgress = draft['uploadsInProgress']; + } + + this.setState({channelId: channelId, messageText: messageText, initialText: messageText, submitting: false, serverError: null, postError: null, previews: previews, uploadsInProgress: uploadsInProgress}); } }, getInitialState: function() { PostStore.clearDraftUploads(); + PostStore.clearPendingPosts(ChannelStore.getCurrentId()); var draft = PostStore.getCurrentDraft(); - return { - channelId: ChannelStore.getCurrentId(), messageText: draft['message'], uploadsInProgress: draft['uploadsInProgress'], - previews: draft['previews'], submitting: false, initialText: draft['message'] - }; + var previews = []; + var messageText = ''; + var uploadsInProgress = 0; + if (draft && draft["previews"] && draft["message"]) { + previews = draft['previews']; + messageText = draft['message']; + uploadsInProgress = draft['uploadsInProgress']; + } + + return { channelId: ChannelStore.getCurrentId(), messageText: messageText, uploadsInProgress: uploadsInProgress, previews: previews, submitting: false, initialText: messageText}; }, getFileCount: function(channelId) { if (channelId === this.state.channelId) { -- cgit v1.2.3-1-g7c22 From fa1491bbfbb1261757943759edf44883d31e5477 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Wed, 12 Aug 2015 12:45:15 -0400 Subject: finalize implenetation of predictive client posts so that users get immediate feedback after posting --- web/react/components/create_post.jsx | 53 ++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'web/react/components/create_post.jsx') diff --git a/web/react/components/create_post.jsx b/web/react/components/create_post.jsx index 8110f5886..8e9e95751 100644 --- a/web/react/components/create_post.jsx +++ b/web/react/components/create_post.jsx @@ -66,33 +66,44 @@ module.exports = React.createClass({ post.filenames = this.state.previews; var time = utils.getTimestamp(); - post.pending_post_id = user_id + ":"+ time; - post.user_id = user_id; + var userId = UserStore.getCurrentId(); + post.pending_post_id = userId + ':' + time; + post.user_id = userId; post.create_at = time; post.root_id = this.state.rootId; post.parent_id = this.state.parentId; - var channel = ChannelStore.getCurrent(); + var channel = ChannelStore.get(this.state.channelId); + + PostStore.storePendingPost(post); + PostStore.storeDraft(channel.id, userId, null); + this.setState({messageText: '', submitting: false, postError: null, previews: [], serverError: null}); client.createPost(post, channel, function(data) { this.resizePostHolder(); AsyncClient.getPosts(true); - var channel = ChannelStore.get(this.state.channelId); - var member = ChannelStore.getMember(this.state.channelId); + var member = ChannelStore.getMember(channel.id); member.msg_count = channel.total_msg_count; member.last_viewed_at = Date.now(); ChannelStore.setChannelMember(member); + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECIEVED_POST, + post: data + }); }.bind(this), function(err) { - var state = {} + var state = {}; - if (err.message === "Invalid RootId parameter") { - if ($('#post_deleted').length > 0) $('#post_deleted').modal('show'); + if (err.message === 'Invalid RootId parameter') { + if ($('#post_deleted').length > 0) { + $('#post_deleted').modal('show'); + } PostStore.removePendingPost(post.pending_post_id); } else { - post.did_fail = true; + post.state = Constants.POST_FAILED; PostStore.updatePendingPost(post); } @@ -100,11 +111,6 @@ module.exports = React.createClass({ this.setState(state); }.bind(this) ); - - post.is_loading = true; - PostStore.storePendingPost(post); - PostStore.storeDraft(channel.id, user_id, null); - this.setState({messageText: '', submitting: false, postError: null, previews: [], serverError: null}); } $('.post-list-holder-by-time').perfectScrollbar('update'); @@ -218,10 +224,10 @@ module.exports = React.createClass({ var previews = []; var messageText = ''; var uploadsInProgress = 0; - if (draft && draft['previews'] && draft['message']) { - previews = draft['previews']; - messageText = draft['message']; - uploadsInProgress = draft['uploadsInProgress']; + if (draft && draft.previews && draft.message) { + previews = draft.previews; + messageText = draft.message; + uploadsInProgress = draft.uploadsInProgress; } this.setState({channelId: channelId, messageText: messageText, initialText: messageText, submitting: false, serverError: null, postError: null, previews: previews, uploadsInProgress: uploadsInProgress}); @@ -229,19 +235,18 @@ module.exports = React.createClass({ }, getInitialState: function() { PostStore.clearDraftUploads(); - PostStore.clearPendingPosts(ChannelStore.getCurrentId()); var draft = PostStore.getCurrentDraft(); var previews = []; var messageText = ''; var uploadsInProgress = 0; - if (draft && draft["previews"] && draft["message"]) { - previews = draft['previews']; - messageText = draft['message']; - uploadsInProgress = draft['uploadsInProgress']; + if (draft && draft.previews && draft.message) { + previews = draft.previews; + messageText = draft.message; + uploadsInProgress = draft.uploadsInProgress; } - return { channelId: ChannelStore.getCurrentId(), messageText: messageText, uploadsInProgress: uploadsInProgress, previews: previews, submitting: false, initialText: messageText}; + return {channelId: ChannelStore.getCurrentId(), messageText: messageText, uploadsInProgress: uploadsInProgress, previews: previews, submitting: false, initialText: messageText}; }, getFileCount: function(channelId) { if (channelId === this.state.channelId) { -- cgit v1.2.3-1-g7c22 From 4866606eb708bbc82804e4910f14025c53f67c10 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Wed, 12 Aug 2015 14:52:43 -0400 Subject: minor bug fixes to pending posts --- web/react/components/create_post.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/react/components/create_post.jsx') diff --git a/web/react/components/create_post.jsx b/web/react/components/create_post.jsx index 8e9e95751..3714560ea 100644 --- a/web/react/components/create_post.jsx +++ b/web/react/components/create_post.jsx @@ -76,7 +76,7 @@ module.exports = React.createClass({ var channel = ChannelStore.get(this.state.channelId); PostStore.storePendingPost(post); - PostStore.storeDraft(channel.id, userId, null); + PostStore.storeDraft(channel.id, null); this.setState({messageText: '', submitting: false, postError: null, previews: [], serverError: null}); client.createPost(post, channel, -- cgit v1.2.3-1-g7c22