<commit_before>import { get, post, del } from '../utils/api'; //eslint-disable-line
//requestLocalStorageData() from local storage
//requestAPIData() from api
//requestImportData() from auth page


export function requestAPIData() {
  return async ( dispatch, getState ) => {
    dispatch({
      type: 'obtain_data_api'
    });
    // if ( getState().configvars.invengine_id &&
    //      getState().configvars.token ) {
    let id = getState().configvars.invengine_id
    let token = getState().configvars.token
    try {
      // const result = await get('https://api.myjson.com/bins/2bwgk');
      const result = await get(`https://localhost:5000/api/contacts/${id}/${token}`);
      // const result = await get(`/api/contacts/${id}`); //uncomment this later
      dispatch({
        type: 'obtain_data_api_success',
        data: result.data
      });
      // dispatch(mergeData(result));
    } catch(e) {
      // console.log('okay error happened here:: ', e);
      dispatch({
        type: 'obtain_data_api_failure',
        e
      });
    }
    // } else{

    // };
  }
}

export function saveContactsToServer () {
  return async (dispatch, getState) => {
    // const { data , configvars } = getState();
    const configvars = getState().configvars;
    const d = getState().data
    let data = { contacts: d, token: configvars.token, id: configvars.invengine_id }
    if (data.id&&data.token) {
      dispatch(dispatchSendContacts(data))
    } else {
      dispatch({
        type:'obtaining_id&token_from_server' });
      try {
        const result = await get(`http://localhost:5000/api/users`);
        // const result = await get(`/api/users/${data.id}`);//uncomment this for local web
        data = { ...data, id: result.invengine_id, token: result.token };
        dispatch({
          type:'obtaining_id&token_from_server_success',
          id: result.invengine_id, token: result.token
        });
        dispatch(dispatchSendContacts(data));
      }
      catch(e) {
        dispatch({
          type:'obtaining_id&token_from_server_failure',<commit_msg>confirmed api/contacts/ GET endpoint work<commit_after>import { get, post, del } from '../utils/api'; //eslint-disable-line
//requestLocalStorageData() from local storage
//requestAPIData() from api
//requestImportData() from auth page


export function requestAPIData() {
  return async ( dispatch, getState ) => {
    dispatch({
      type: 'obtain_data_api'
    });
    let id = getState().configvars.invengine_id
    let token = getState().configvars.token
    try {
      // const result = await get('https://api.myjson.com/bins/2bwgk');
      const result = await get(`http://localhost:5000/api/contacts/${id}/${token}`);
      // const result = await get(`/api/contacts/${id}`); //uncomment this later
      dispatch({
        type: 'obtain_data_api_success',
        data: result.data
      });
    } catch(e) {
      dispatch({
        type: 'obtain_data_api_failure',
        e
      });
    }
  }
}

export function saveContactsToServer () {
  return async (dispatch, getState) => {
    // const { data , configvars } = getState();
    const configvars = getState().configvars;
    const d = getState().data
    let data = { contacts: d, token: configvars.token, id: configvars.invengine_id }
    if (data.id&&data.token) {
      dispatch(dispatchSendContacts(data))
    } else {
      dispatch({
        type:'obtaining_id&token_from_server' });
      try {
        const result = await get(`http://localhost:5000/api/users`);
        // const result = await get(`/api/users/${data.id}`);//uncomment this for local web
        data = { ...data, id: result.invengine_id, token: result.token };
        dispatch({
          type:'obtaining_id&token_from_server_success',
          id: result.invengine_id, token: result.token
        });
        dispatch(dispatchSendContacts(data));
      }
      catch(e) {
        dispatch({
          type:'obtaining_id&token_from_server_failure',
{'fraction_non_alphanumeric': 0.14666666666666667, 'fraction_numerical': 0.004528301886792453, 'mean_word_length': 2.664516129032258, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 3, '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': '4868437', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1201, 'n_words': 253}