Permalink
Browse files

#32 I made some modular shit

  • Loading branch information...
1 parent bdfe518 commit f3730d8d15853d9225f218082970b086cf633580 @Mtroyanovsky1 committed Feb 17, 2017
Showing with 24 additions and 4 deletions.
  1. +20 −3 public/scripts/script.js
  2. +4 −1 routes/chats.js
@@ -4,11 +4,14 @@
Handling clicking on a question in question-list
*/
-var currentChatId;
+var currentChat;
var currentQuestioner;
var allQuestions;
+var questionChats;
+var answerChats; // /api/chats?kindofchat=answers
+
//***********
//sockets stuff
@@ -34,6 +37,8 @@ $.ajax({
}
});
+
+
$('.question_submit').on('click', function(event) {
$.ajax({
url: '/api/questions/new',
@@ -53,6 +58,18 @@ $('.question_submit').on('click', function(event) {
})
});
+//function to replace the view html
+
+
+var messageToDiv = function(message) {
+ return '<div class="from-me">' + ${message.content} + '</div>';
+};
+
+var messageFromDiv = function(message) {
+ return '<div class="to-me">' + ${message.content} + '</div>';
+};
+
+
$('.questions-list').on('click', '.question', function(event){
event.preventDefault();
@@ -66,9 +83,9 @@ $('.questions-list').on('click', '.question', function(event){
url: '/api/chats/new',
success: function(result){
- currentChatId = result._id;
+ currentChat = result;
currentQuestioner = result.questioner;
- // the first message Id of the chat is in results.messge[0]
+ // the first message Id of the chat is in results.message[0]
console.log(result);
}
});
View
@@ -60,6 +60,7 @@ router.post('/api/chats/new', function(req, res) {
if(err) {
res.status(400).json(err);
} else {
+ newChat.messages = [newMessage];
res.json(newChat);
}
});
@@ -88,7 +89,9 @@ router.get('/api/chats', function(req, res){
return res.status(400).json({message: 'Invalid query'});
}
- Chat.find({_id: {$in: chatType}}, function(err, chats){
+ Chat.find({_id: {$in: chatType}})
+ .populate('messages')
+ .exec(function(err, chats){
if(err){
res.status(400).json(err);
}else{

0 comments on commit f3730d8

Please sign in to comment.