<commit_before>import isEmpty from 'lodash/isEmpty';
import { normalize } from 'normalizr';
import { createReducer } from 'store';
import contentful from 'contentful-client';
import { stories as storiesSchema } from 'schemas';
import { buildFilters } from 'utils/stories';

const GET_STORIES = 'stories/GET_STORIES';
const GET_FILTERED_STORIES = 'stories/GET_FILTERED_STORIES';
const SET_FITERS_ACTIVE = 'stories/SET_FITERS_ACTIVE';

const initialState = {
  all: {
    entities: {},
    result: []
  },
  filtered: {
    entities: {},
    result: []
  },
  filtersActive: false
};

const storiesReducer = {
  [GET_STORIES](state, action) {
    return { ...state, all: action.payload };
  },
  [GET_FILTERED_STORIES](state, action) {
    return { ...state, filtered: action.payload };
  },
  [SET_FITERS_ACTIVE](state, action) {
    return { ...state, filtersActive: action.payload };
  }
};


// Navigation pre-fetching thunks
export async function getStoriesThunk(dispatch, getState) {
  const { all } = getState().stories;
  if (all.result.length === 0) {
    const { items } = await contentful.getEntries({
      content_type: 'story',
      order: 'fields.story_date'
    });

    dispatch({
      type: GET_STORIES,
      payload: normalize(items, storiesSchema)
    });
  }
}

export async function getFilteredStoriesThunk(dispatch, getState) {
  const { query = {} } = getState().location;
  let filtersActive = false;

  if (!isEmpty(query)) {
    filtersActive = true;
    const filters = buildFilters(query);
    const { items } = await contentful.getEntries({
      ...filters,
      content_type: 'story',
      order: 'fields.story_date'
    });

    dispatch({
      type: GET_FILTERED_STORIES,
      payload: normalize(items, storiesSchema)
    });
  }

  dispatch({
    type: SET_FITERS_ACTIVE,
    payload: filtersActive
  });
}

export default createReducer(initialState, storiesReducer);<commit_msg>Fix stories order<commit_after>import isEmpty from 'lodash/isEmpty';
import { normalize } from 'normalizr';
import { createReducer } from 'store';
import contentful from 'contentful-client';
import { stories as storiesSchema } from 'schemas';
import { buildFilters } from 'utils/stories';

const GET_STORIES = 'stories/GET_STORIES';
const GET_FILTERED_STORIES = 'stories/GET_FILTERED_STORIES';
const SET_FITERS_ACTIVE = 'stories/SET_FITERS_ACTIVE';

const initialState = {
  all: {
    entities: {},
    result: []
  },
  filtered: {
    entities: {},
    result: []
  },
  filtersActive: false
};

const storiesReducer = {
  [GET_STORIES](state, action) {
    return { ...state, all: action.payload };
  },
  [GET_FILTERED_STORIES](state, action) {
    return { ...state, filtered: action.payload };
  },
  [SET_FITERS_ACTIVE](state, action) {
    return { ...state, filtersActive: action.payload };
  }
};


// Navigation pre-fetching thunks
export async function getStoriesThunk(dispatch, getState) {
  const { all } = getState().stories;
  if (all.result.length === 0) {
    const { items } = await contentful.getEntries({
      content_type: 'story',
      order: '-fields.story_date'
    });

    dispatch({
      type: GET_STORIES,
      payload: normalize(items, storiesSchema)
    });
  }
}

export async function getFilteredStoriesThunk(dispatch, getState) {
  const { query = {} } = getState().location;
  let filtersActive = false;

  if (!isEmpty(query)) {
    filtersActive = true;
    const filters = buildFilters(query);
    const { items } = await contentful.getEntries({
      ...filters,
      content_type: 'story',
      order: 'fields.story_date'
    });

    dispatch({
      type: GET_FILTERED_STORIES,
      payload: normalize(items, storiesSchema)
    });
  }

  dispatch({
    type: SET_FITERS_ACTIVE,
    payload: filtersActive
  });
}

export default createReducer(initialState, storiesReducer);

{'fraction_non_alphanumeric': 0.13241415192507805, 'fraction_numerical': 0.0005202913631633715, 'mean_word_length': 3.5937873357228196, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2127719', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1229, 'n_words': 271}