diff options
| author | Henry Jameson <me@hjkos.com> | 2019-01-25 00:49:37 +0300 |
|---|---|---|
| committer | Henry Jameson <me@hjkos.com> | 2019-01-25 01:08:08 +0300 |
| commit | 9d0d6b86c83a4fad4038077a65149f0f3677fb82 (patch) | |
| tree | 5ce2a6ab76a2096fec7d7608ea51a0238530b0c6 /src/components/conversation/conversation.js | |
| parent | 03ffa7e84e648f1114605c338e6b40c214199e9d (diff) | |
this attempts converting id to number to sort them numerically, since "99" >
"100" while 99 < 100
Diffstat (limited to 'src/components/conversation/conversation.js')
| -rw-r--r-- | src/components/conversation/conversation.js | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/components/conversation/conversation.js b/src/components/conversation/conversation.js index 9bf5e136..07b7c692 100644 --- a/src/components/conversation/conversation.js +++ b/src/components/conversation/conversation.js @@ -1,9 +1,25 @@ import { reduce, filter, sortBy } from 'lodash' import Status from '../status/status.vue' +const sortById = (a, b) => { + const seqA = Number(a.action.id) + const seqB = Number(b.action.id) + const isSeqA = Number.isNaN(seqA) + const isSeqB = Number.isNaN(seqB) + if (isSeqA && isSeqB) { + return seqA > seqB ? -1 : 1 + } else if (isSeqA && !isSeqB) { + return 1 + } else if (!isSeqA && isSeqB) { + return -1 + } else { + return a.action.id > b.action.id ? -1 : 1 + } +} + const sortAndFilterConversation = (conversation) => { conversation = filter(conversation, (status) => status.type !== 'retweet') - return sortBy(conversation, 'id') + return sortBy(conversation, sortById) } const conversation = { |
