From 62389209ae7e727267e011fb2d44bdddc20af4eb Mon Sep 17 00:00:00 2001 From: Jacob Lurye Date: Wed, 6 Dec 2017 16:58:23 -0500 Subject: [PATCH 1/3] Sort history by recency. --- views/profile.handlebars | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/views/profile.handlebars b/views/profile.handlebars index 8e2b57d..4f05ffe 100644 --- a/views/profile.handlebars +++ b/views/profile.handlebars @@ -226,6 +226,14 @@ $("#convo-count").text(res.length); } + // Sort the results by recency + res.sort((a, b) => { + a_info = extraInfoFromChat(a); + b_info = extraInfoFromChat(b); + + return a_info.connectedDate - b_info.connectedDate; + }).reverse() + // Populate history form res.forEach(row => { From 1ebda7465e03acb425edd3afa3185535fe4f230a Mon Sep 17 00:00:00 2001 From: Jacob Lurye Date: Wed, 6 Dec 2017 17:03:23 -0500 Subject: [PATCH 2/3] Add error-checking. --- views/profile.handlebars | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/views/profile.handlebars b/views/profile.handlebars index 4f05ffe..bd8b377 100644 --- a/views/profile.handlebars +++ b/views/profile.handlebars @@ -231,6 +231,10 @@ a_info = extraInfoFromChat(a); b_info = extraInfoFromChat(b); + if (a_info === undefined || b_info === undefined) { + return 0 + } + return a_info.connectedDate - b_info.connectedDate; }).reverse() From 38b0f7af196d641aa9584ac68c5dd0eeb8ed9734 Mon Sep 17 00:00:00 2001 From: Nicholas Boucher Date: Wed, 6 Dec 2017 17:08:37 -0500 Subject: [PATCH 3/3] Added `null` checking --- views/profile.handlebars | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/views/profile.handlebars b/views/profile.handlebars index bd8b377..1445712 100644 --- a/views/profile.handlebars +++ b/views/profile.handlebars @@ -146,21 +146,21 @@ function buildLeaderboard(leaders) { var start = '
' - var tHead = '
' + - '
Friend
' + - '
Empathetic
' + - '
Polite
' + - '
Knowledgeable
' + - '
Creative
' + + var tHead = '
' + + '
Friend
' + + '
Empathetic
' + + '
Polite
' + + '
Knowledgeable
' + + '
Creative
' + '
'; var cols = ''; leaders.forEach(friend => { var friendStats = ('
' + - '
' + friend.name + '
' + - '
' + countBadges('empathetic' , friend) + '
' + + '
' + friend.name + '
' + + '
' + countBadges('empathetic' , friend) + '
' + '
' + countBadges('polite' , friend) + '
' + - '
' + countBadges('knowledgeable', friend) + '
' + - '
' + countBadges('creative' , friend) + '
' + + '
' + countBadges('knowledgeable', friend) + '
' + + '
' + countBadges('creative' , friend) + '
' + '
'); cols += friendStats; }); @@ -231,7 +231,8 @@ a_info = extraInfoFromChat(a); b_info = extraInfoFromChat(b); - if (a_info === undefined || b_info === undefined) { + if (a_info === undefined || b_info === undefined + || a_info === null || b_info === null) { return 0 } @@ -347,7 +348,7 @@ $("#convo-button").on("click", (e) => { // This is a hack, see questions code for this onclick function. // Needed to do this so we could use function internal to questions.handlebars' script. - $('#call')[0].onclick(); + $('#call')[0].onclick(); }); getHistory();