@@ -26,6 +26,7 @@ import {
2626} from "app/components/chat/MessageEventTimeline" ;
2727import { EventsForTopicResponse } from "trieve-ts-sdk" ;
2828import { format } from "date-fns" ;
29+ import { parseCustomDateString } from "app/utils/formatting" ;
2930
3031export const links : LinksFunction = ( ) => {
3132 return [ { rel : "stylesheet" , href : styles } ] ;
@@ -59,19 +60,8 @@ export default function ChatRoute() {
5960 new Date ( b . created_at ) . getUTCSeconds ( ) -
6061 new Date ( a . created_at ) . getUTCSeconds ( ) ,
6162 ) ;
62- if ( sortedMessages . length > 0 ) {
63- events . push ( {
64- date : new Date ( sortedMessages . at ( 0 ) ! . created_at ) ,
65- type : "New Chat" ,
66- additional : format (
67- new Date ( sortedMessages . at ( 0 ) ! . created_at ) ,
68- "h:m aa, LLL d y" ,
69- ) ,
70- icon : < PlusIcon width = { 20 } fill = "#000" height = { 20 } /> ,
71- } ) ;
72- }
7363
74- messages . forEach ( ( message ) => {
64+ sortedMessages . forEach ( ( message ) => {
7565 if ( message . role === "user" ) {
7666 events . push ( {
7767 date : new Date ( message . created_at ) ,
@@ -86,23 +76,35 @@ export default function ChatRoute() {
8676 if ( event . event_name === "View" ) return ;
8777 if ( event . event_name === "Click" ) {
8878 events . push ( {
89- date : new Date ( event . created_at ) ,
79+ date : new Date ( parseCustomDateString ( event . updated_at , false ) ) ,
9080 type : "Click on Product" ,
9181 icon : < CursorIcon width = { 20 } fill = "#000" height = { 20 } /> ,
9282 } ) ;
9383 }
9484 if ( event . event_name === "site-add_to_cart" ) {
9585 events . push ( {
96- date : new Date ( event . created_at ) ,
86+ date : new Date ( parseCustomDateString ( event . updated_at , false ) ) ,
9787 type : "Add To Cart" ,
9888 icon : < CartIcon width = { 20 } fill = "#000" height = { 20 } /> ,
9989 } ) ;
10090 }
10191 } ) ;
10292
103- const result = events . sort (
104- ( a , b ) => b . date . getUTCSeconds ( ) - a . date . getUTCSeconds ( ) ,
105- ) ;
93+ const result = events . sort ( ( a , b ) => a . date . getTime ( ) - b . date . getTime ( ) ) ;
94+
95+ if ( sortedMessages . length > 0 ) {
96+ result . unshift ( {
97+ date : new Date ( sortedMessages . at ( 0 ) ! . created_at ) ,
98+ type : "New Chat" ,
99+ additional : format (
100+ new Date (
101+ parseCustomDateString ( sortedMessages . at ( 0 ) ! . created_at , true ) ,
102+ ) ,
103+ "h:m aa, LLL d y" ,
104+ ) ,
105+ icon : < PlusIcon width = { 20 } fill = "#000" height = { 20 } /> ,
106+ } ) ;
107+ }
106108 return result ;
107109 } ;
108110
0 commit comments