Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const emptyEngagements = {
  2.   total_reactions: 0,
  3.   reactions: {
  4.     likes: 0,
  5.   },
  6.   comments: 0,
  7.   reshares: 0,
  8. };
  9.  
  10. export const getSortedSamples = (samples = { web= [] , twitter= [] }: any) => {
  11.   const decoreateSample = source => sample => ({
  12.     ...sample,
  13.     sourceForDisplay: source,
  14.     engagements: sample.engagements || { ...emptyEngagements },
  15.   })
  16.   const sortByPostedTime = (sampleA, sampleB) =>  dayjs(sampleA.posted_time).isBefore(sampleB.posted_time) ? -1 : 1
  17.  
  18.   return [
  19.     ...samples.twitter.map(decoreateSample(SOURCES_FOR_DISPLAY.TWITTER)),
  20.     ...samples.web.map(decoreateSample(SOURCES_FOR_DISPLAY.WEB)),
  21.   ].sort(sortByPostedTime)
  22. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement