<commit_before>import { gotError } from 'lib/actions/general';
import * as api from 'lib/api/locations';
import { reorderModels } from 'lib/helpers';
import { searchAutocompleteFor } from 'lib/google';
import { Promise } from 'es6-promise';
import debugFactory from 'debug';

const debug = debugFactory( 'voyageur:library-actions' );

export function importLocations( data ) {
  return function( dispatch, getState ) {
    const locations = JSON.parse( data );
    if ( ! locations.map ) return dispatch( gotError( 'Only an array of Location objects can be submitted' ) );
    Promise.all( locations.map( params => api.createNewLocation( getState().auth.token, params ) ) )
    .then( () => dispatch( fetchLibrary() ) )
    .then( () => gotError( 'Import complete!' ) )
    .catch( err => dispatch( gotError( err ) ) );
  };
}

export function addLocation( params ) {
  return function( dispatch, getState ) {
    if ( ! params.name || ! params.address ) return dispatch( gotError( 'Locations must have a name and an address' ) );
    api.createNewLocation( getState().auth.token, params )
    .then( () => dispatch( fetchLibrary() ) )
    .catch( ( err ) => dispatch( gotError( err ) ) );
    const location = Object.assign( { _id: 'new-location_' + Date.now(), isLoading: true }, params );
    dispatch( gotNewLocation( location ) );
  };
}<commit_msg>Replace Date.now in addLocation action<commit_after>import { gotError } from 'lib/actions/general';
import * as api from 'lib/api/locations';
import { reorderModels, getHashFor } from 'lib/helpers';
import { searchAutocompleteFor } from 'lib/google';
import { Promise } from 'es6-promise';
import debugFactory from 'debug';

const debug = debugFactory( 'voyageur:library-actions' );

export function importLocations( data ) {
  return function( dispatch, getState ) {
    const locations = JSON.parse( data );
    if ( ! locations.map ) return dispatch( gotError( 'Only an array of Location objects can be submitted' ) );
    Promise.all( locations.map( params => api.createNewLocation( getState().auth.token, params ) ) )
    .then( () => dispatch( fetchLibrary() ) )
    .then( () => gotError( 'Import complete!' ) )
    .catch( err => dispatch( gotError( err ) ) );
  };
}

export function addLocation( params ) {
  return function( dispatch, getState ) {
    if ( ! params.name || ! params.address ) return dispatch( gotError( 'Locations must have a name and an address' ) );
    api.createNewLocation( getState().auth.token, params )
    .then( () => dispatch( fetchLibrary() ) )
    .catch( ( err ) => dispatch( gotError( err ) ) );
    const location = Object.assign( { _id: 'new-location_' + getHashFor( params.name + params.address ), isLoading: true }, params );
    dispatch( gotNewLocation( location ) );
  };
}
{'fraction_non_alphanumeric': 0.14476053294922578, 'fraction_numerical': 0.0007202016564638099, 'mean_word_length': 3.9430604982206408, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '7217442', 'n_tokens_mistral': 808, 'n_tokens_neox': 804, 'n_words': 243}