import { createSelector } from 'reselect';
import { selectArticles } from './articles';
import { selectEvents } from './events';

export const selectFrontpage = createSelector(
  selectArticles,
  selectEvents,
  (articles, events) => {
    return articles.concat(events);
  }
);

import moment from 'moment';
import { sortBy } from 'lodash';
import { createSelector } from 'reselect';
import { selectArticles } from './articles';
import { selectEvents } from './events';

export const selectFrontpage = createSelector(
  selectArticles,
  selectEvents,
  (articles, events) =>
    sortBy(articles.concat(events), item => {
      const timeField = item.eventType ? item.startTime : item.createdAt;
      return Math.abs(moment() - moment(timeField));
    })
);

Sort events and articles by dates from now
Sort events and articles by dates from now
