<commit_before>import { createAction } from 'redux-actions';
import { createThunkAction } from 'utils/redux';
import isEmpty from 'lodash/isEmpty';

export const fetchCountriesDocumentsInit = createAction(
  'fetchCountriesDocumentsInit'
);
export const fetchCountriesDocumentsReady = createAction(
  'fetchCountriesDocumentsReady'
);
export const fetchCountriesDocumentsFail = createAction(
  'fetchCountriesDocumentsFail'
);

export const fetchCountriesDocuments = createThunkAction(
  'fetchCountriesDocuments',
  location => (dispatch, state) => {
    const { countriesDocuments } = state();
    if (
      !countriesDocuments.loading &&
      (isEmpty(countriesDocuments.data) ||
        (!!location && isEmpty(countriesDocuments.data[location])))
    ) {
      const url = `/api/v1/ndcs/countries_documents${
        location ? `?location=${location}` : ''
      }`;
      dispatch(fetchCountriesDocumentsInit());
      fetch(url)
        .then(response => {
          if (response.ok) return response.json();
          throw Error(response.statusText);
        })
        .then(data => {
          dispatch(fetchCountriesDocumentsReady(data.data));
        })
        .catch(error => {
          console.warn(error);
          dispatch(fetchCountriesDocumentsFail());
        });
    }<commit_msg>FIx Document provider not refetching<commit_after>import { createAction } from 'redux-actions';
import { createThunkAction } from 'utils/redux';
import isEmpty from 'lodash/isEmpty';

export const fetchCountriesDocumentsInit = createAction(
  'fetchCountriesDocumentsInit'
);
export const fetchCountriesDocumentsReady = createAction(
  'fetchCountriesDocumentsReady'
);
export const fetchCountriesDocumentsFail = createAction(
  'fetchCountriesDocumentsFail'
);

export const fetchCountriesDocuments = createThunkAction(
  'fetchCountriesDocuments',
  location => (dispatch, state) => {
    const { countriesDocuments } = state();
    if (
      !countriesDocuments.loading &&
      (!location ||
        !countriesDocuments.data || isEmpty(countriesDocuments.data[location]))
    ) {
      const url = `/api/v1/ndcs/countries_documents${
        location ? `?location=${location}` : ''
      }`;
      dispatch(fetchCountriesDocumentsInit());
      fetch(url)
        .then(response => {
          if (response.ok) return response.json();
          throw Error(response.statusText);
        })
        .then(data => {
          dispatch(fetchCountriesDocumentsReady(data.data));
        })
        .catch(error => {
          console.warn(error);
          dispatch(fetchCountriesDocumentsFail());
        });
    }
{'fraction_non_alphanumeric': 0.11984732824427481, 'fraction_numerical': 0.0007633587786259542, 'mean_word_length': 3.4050420168067226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '264698', 'n_tokens_mistral': 737, 'n_tokens_neox': 703, 'n_words': 128}