From c914d94b18164b2c61dafb1db97a1f61cc230df6 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Thu, 21 Nov 2019 12:02:10 +0530 Subject: [PATCH] Format time, fix sort (#230) --- app/controllers/widgets_controller.rb | 2 +- app/javascript/dashboard/components/ChatList.vue | 7 +++---- app/javascript/dashboard/mixins/time.js | 7 +------ 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/app/controllers/widgets_controller.rb b/app/controllers/widgets_controller.rb index 6fac657bb..711a5cca4 100644 --- a/app/controllers/widgets_controller.rb +++ b/app/controllers/widgets_controller.rb @@ -14,7 +14,7 @@ class WidgetsController < ActionController::Base source_id: cookie_params[:source_id] ) - @contact = contact_inbox.contact + @contact = contact_inbox ? contact_inbox.contact : nil end def set_token diff --git a/app/javascript/dashboard/components/ChatList.vue b/app/javascript/dashboard/components/ChatList.vue index a996aae43..f3b357110 100644 --- a/app/javascript/dashboard/components/ChatList.vue +++ b/app/javascript/dashboard/components/ChatList.vue @@ -150,10 +150,9 @@ export default { } else { copyList = this.allChatList.slice(); } - const sorted = copyList.sort((a, b) => - this.wootTime(this.lastMessage(a).created_at).isBefore( - this.wootTime(this.lastMessage(b).created_at) - ) + const sorted = copyList.sort( + (a, b) => + this.lastMessage(b).created_at - this.lastMessage(a).created_at ); return sorted; diff --git a/app/javascript/dashboard/mixins/time.js b/app/javascript/dashboard/mixins/time.js index 6f1f42bdc..1d654a466 100644 --- a/app/javascript/dashboard/mixins/time.js +++ b/app/javascript/dashboard/mixins/time.js @@ -15,12 +15,7 @@ export default { }, dynamicTime(time) { const createdAt = moment(time * 1000); - return createdAt.calendar(null, { - sameDay: 'h:mm A', - lastDay: '[Yesterday]', - lastWeek: 'ddd', - sameElse: 'D MMM', - }); + return createdAt.fromNow(); }, }, };