make sure the comment/post being edited is loaded before moving on

This commit is contained in:
Sacha Greif 2013-06-18 10:46:29 +09:00
parent 14421ff6e4
commit ebaf483d46
6 changed files with 27 additions and 14 deletions

View file

@ -1 +1 @@
0.6.0
0.6.4

View file

@ -73,7 +73,7 @@ analyticsInit = function() {
analyticsRequest = function() {
// Google Analytics
if ((googleAnalyticsId = getSetting("googleAnalyticsId"))){
if (googleAnalyticsId = getSetting("googleAnalyticsId") && window._gaq){
window._gaq.push(['_trackPageview', window.location.pathname]);
}

View file

@ -50,7 +50,6 @@
// on post page, we show the comment tree
Session.set('showChildComments',true);
return 'post_page';
};
@ -190,19 +189,27 @@
canEdit: function(page) {
// make findOne() non reactive to avoid re-triggering the router every time the
// current comment or post object changes
// but make sure the comment/post is loaded before moving on
if (page === 'comment_edit') {
var item = Comments.findOne(Session.get('selectedCommentId'), {reactive: false});
if(!Session.get('singleCommentReady'))
return 'loading'
} else {
var item = Posts.findOne(Session.get('selectedPostId'), {reactive: false});
if(!Session.get('singlePostReady'))
return 'loading'
}
var error = canEdit(Meteor.user(), item, true);
if (error === true)
if (error === true){
return page;
}
// a problem.. make sure the item has loaded and we have logged in
if (! item || Meteor.loggingIn())
if (! item || Meteor.loggingIn()){
return 'loading';
}
// otherwise the error tells us what to show.
return error;

View file

@ -2,6 +2,7 @@
Session.set('initialLoad', true);
Session.set('currentDate', new Date());
Session.set('categorySlug', null);
Session.set('singlePostReady', false);
// Settings
Meteor.subscribe('settings', function(){
@ -32,7 +33,9 @@ if(Meteor.userId() != null){
// Single Post
Meteor.autorun(function() {
Meteor.subscribe('singlePost', Session.get('selectedPostId'));
Meteor.subscribe('singlePost', Session.get('selectedPostId'), function(){
Session.set('singlePostReady', true);
});
});
// Digest
@ -80,9 +83,10 @@ pendingPostsHandle = postListSubscription(selectPending, sortPosts('createdAt'),
// Collection depends on selectedPostId and selectedCommentId session variable
Session.set('selectedPostId', null);
Meteor.autosubscribe(function() {
var query = { $or : [ { post : Session.get('selectedPostId') } , { _id : Session.get('selectedCommentId') } ] };
Meteor.subscribe('comments', query, function() {
Session.set('commentReady', true);
Session.set('singleCommentReady', true);
});
});

View file

@ -12,6 +12,8 @@ Template.post_page.helpers({
return canComment(Meteor.user());
},
canView: function(){
console.log('asdas')
console.log(canView(Meteor.user()))
return canView(Meteor.user());
}
});

View file

@ -2,7 +2,7 @@
"meteor": {
"git": "https://github.com/meteor/meteor.git",
"branch": "master",
"commit": "1dfc7171f237a029cca74cbf25024acbf6ed5b75"
"commit": "9bb2b5447e845c4f483df5e9b42a2c1de5ab909b"
},
"dependencies": {
"basePackages": {
@ -33,8 +33,8 @@
},
"paginated-subscription": {
"git": "https://github.com/tmeasday/meteor-paginated-subscription.git",
"tag": "v0.1.1",
"commit": "1ba670364ddac149f404158407b2afc89db42ce5"
"tag": "v0.1.2",
"commit": "35e0c6112df2b4cfeb60b559276a93cac5ee2dd6"
},
"crypto-md5": {
"git": "https://github.com/tmeasday/meteor-crypto-md5.git",