diff --git a/front/src/actions/message.js b/front/src/actions/message.js index c0cf1ef7e8..bb56e4feaa 100644 --- a/front/src/actions/message.js +++ b/front/src/actions/message.js @@ -5,16 +5,7 @@ import uuid from 'uuid'; const TYPING_MIN_TIME = 400; const TYPING_MAX_TIME = 600; -const sortMessages = messages => - messages.sort((a, b) => { - if (a.created_at < b.created_at) { - return -1; - } - if (a.created_at > b.created_at) { - return 1; - } - return 0; - }); +const sortMessages = messages => messages.sort((a, b) => a.created_at - b.created_at); function createActions(store) { const actions = { @@ -32,6 +23,8 @@ function createActions(store) { }); try { let messages = await state.httpClient.get('/api/v1/message'); + // Force date usage + messages.forEach(message => (message.created_at = new Date(message.created_at))); messages = sortMessages(messages); store.setState({ messages, diff --git a/front/src/config/demo.json b/front/src/config/demo.json index 0d069928dd..d0f401667d 100644 --- a/front/src/config/demo.json +++ b/front/src/config/demo.json @@ -465,7 +465,7 @@ "receiver_id": "0cd30aef-9c4e-4a23-88e3-3547971296e5", "text": "It's a clear day today. Temperature outside is 26°C.", "is_read": true, - "created_at": "2019-02-12T07:49:07.556Z" + "created_at": "2019-02-12T07:45:07.556Z" }, { "id": "247b1dd0-6fab-47a8-a9c8-1405deae0ae8", @@ -473,7 +473,7 @@ "receiver_id": null, "text": "What's the weather like?", "is_read": true, - "created_at": "2019-02-12T07:49:07.556Z" + "created_at": "2019-02-12T07:44:07.556Z" }, { "id": "247b1dd0-6fab-47a8-a9c8-1405deae0ae8", @@ -481,7 +481,7 @@ "receiver_id": "0cd30aef-9c4e-4a23-88e3-3547971296e5", "text": "It's 24°C in the kitchen.", "is_read": true, - "created_at": "2019-02-12T07:49:07.556Z" + "created_at": "2019-02-12T07:49:07.557Z" }, { "id": "247b1dd0-6fab-47a8-a9c8-1405deae0ae8",