working on comment form latency compensation

This commit is contained in:
Sacha Greif 2014-12-28 11:45:35 +09:00
parent e91d60ecc9
commit 7d7a3939fc
3 changed files with 19 additions and 20 deletions

View file

@ -17,7 +17,11 @@ Template[getTemplate('comment_form')].events({
var $submitButton = instance.$('.btn-submit');
var body = $commentForm.val();
$submitButton.addClass('loading');
// now that the form is latency compensated, we don't actually need to show this
// $commentForm.prop('disabled', true);
// $submitButton.addClass('loading');
$commentForm.val('');
if(getCurrentTemplate() == 'comment_reply'){
@ -33,22 +37,14 @@ Template[getTemplate('comment_form')].events({
Meteor.call('submitComment', comment, function(error, newComment){
$commentForm.prop('disabled', false);
$submitButton.removeClass('loading');
if (error) {
console.log(error);
flashMessage(error.reason, "error");
} else {
trackEvent("newComment", newComment);
Router.go('post_page_comment', {
_id: parentComment.postId,
commentId: newComment._id
});
}
});
@ -65,20 +61,14 @@ Template[getTemplate('comment_form')].events({
Meteor.call('submitComment', comment, function(error, newComment){
$commentForm.val('');
$commentForm.prop('disabled', false);
$submitButton.removeClass('loading');
if(error){
console.log(error);
flashMessage(error.reason, "error");
}else{
trackEvent("newComment", newComment);
Session.set('scrollToCommentId', newComment._id);
}
});

View file

@ -92,8 +92,8 @@ Comments.allow({
// ------------------------------------------------------------------------------------------- //
Comments.before.insert(function (userId, doc) {
if(Meteor.isServer)
doc.htmlBody = sanitize(marked(doc.body));
// note: only actually sanitizes on the server
doc.htmlBody = sanitize(marked(doc.body));
});
Comments.before.update(function (userId, doc, fieldNames, modifier, options) {
@ -131,6 +131,10 @@ commentAfterSubmitMethodCallbacks.push(function (comment) {
// ------------------------------------------------------------------------------------------- //
submitComment = function (comment) {
console.log(comment)
if (Meteor.isServer) {
Meteor._sleepForMs(4000)
}
var userId = comment.userId; // at this stage, a userId is expected

View file

@ -88,6 +88,10 @@ form, .accounts-dialog{
&[type="number"]{
width: 30%;
}
&:disabled{
background: #eee;
color: $light-text;
}
}
input[type="text"], input[type="password"], input[type="number"], .login-form input{
height:30px;
@ -120,19 +124,20 @@ input[type="submit"], button, .button, .btn{
font-size:15px;
cursor:pointer;
margin:0;
color: white;
// line-height:26px;
// height:26px;
font-weight:normal;
&.disabled, &.loading{
background:$lighter-grey !important;
pointer-events:none;
color: $medium-text;
}
&.inline{
display: inline-block;
}
&.btn-primary{
background:$red;
color:white;
&:link, &:hover, &:active, &:visited{
color:white;
}