fixed categories.js socket callbacks

v1.18.x
Julian Lam 11 years ago
parent 8041bee9fd
commit cbb630fd6b

@ -132,16 +132,16 @@ define(['composer'], function(composer) {
socket.emit('categories.loadMore', { socket.emit('categories.loadMore', {
cid: cid, cid: cid,
after: $('#topics-container').children('.category-item').length after: $('#topics-container').children('.category-item').length
}, function (data) { }, function (err, data) {
if (data.topics.length) { if (!err && data.topics.length) {
Category.onTopicsLoaded(data.topics); Category.onTopicsLoaded(data.topics);
} }
loadingMoreTopics = false; loadingMoreTopics = false;
}); });
} }
function renderRecentReplies(posts) { function renderRecentReplies(err, posts) {
if (!posts || posts.length === 0) { if (err || !posts || posts.length === 0) {
return; return;
} }

@ -102,7 +102,7 @@ define(['composer'], function(composer) {
var loadingEl = document.getElementById('categories-loading'); var loadingEl = document.getElementById('categories-loading');
if (loadingEl) { if (loadingEl) {
socket.emit('categories.get', function(data) { socket.emit('categories.get', function(err, data) {
// Render categories // Render categories
var categoriesFrag = document.createDocumentFragment(), var categoriesFrag = document.createDocumentFragment(),
categoryEl = document.createElement('li'), categoryEl = document.createElement('li'),

@ -3,17 +3,11 @@ var categories = require('../categories'),
SocketCategories = {}; SocketCategories = {};
SocketCategories.getRecentReplies = function(socket, tid, callback) { SocketCategories.getRecentReplies = function(socket, tid, callback) {
categories.getRecentReplies(tid, socket.uid, 4, function(err, replies) { categories.getRecentReplies(tid, socket.uid, 4, callback);
callback(replies);
});
}; };
SocketCategories.get = function(socket, data, callback) { SocketCategories.get = function(socket, data, callback) {
categories.getAllCategories(0, function(err, categories) { categories.getAllCategories(0, callback);
if(callback) {
callback(categories);
}
});
}; };
SocketCategories.loadMore = function(socket, data, callback) { SocketCategories.loadMore = function(socket, data, callback) {
@ -21,7 +15,7 @@ SocketCategories.loadMore = function(socket, data, callback) {
end = start + 9; end = start + 9;
categories.getCategoryTopics(data.cid, start, end, socket.uid, function(topics) { categories.getCategoryTopics(data.cid, start, end, socket.uid, function(topics) {
callback({ callback(null, {
topics: topics topics: topics
}); });
}); });

Loading…
Cancel
Save