import { routeActions } from 'react-router-redux';
import fetch from 'isomorphic-fetch';

//
//  actions types
//

export const REQUEST_BUS_STOPS_AROUND_ME = 'REQUEST_BUS_STOPS_AROUND_ME'

//
//  actions helpers
//

function requestBusStopsAroundMe( coors, meters ) {
  fetch( 'secret-depths-4660.herokuapp/paradas?lt=' + coors.latitude + '&ln=' + coors.longitude + '&r=' + meters )
    .then( function(){
      dispatch( routeActions.push( '/loading' ) );
    })
    .then( function( response ) {
      if ( response.status >= 400 ) {
        dispatch( routeActions.push( '/errors' ) );
        return {
          meters: meters,
          coors: coors,
          busStops: {},
          error: {
            type: response.status,
            message: response.message
          }
        }
      }
      dispatch( routeActions.push( '/results' ) );
      return {
        meters: meters,
        coors: coors,
        busStops: response.json(),
        error: {}
      }
    })
}

//
//  actions creators
//

export function getBusStopsAroundMe( coors, meters ) {
  var busStopsApiResponse = requestBusStopsAroundMe( coors, meters );
  return {
    type: REQUEST_BUS_STOPS_AROUND_ME,
    busStopsAroundMe: busStopsApiResponse
  };
}

@@ -1,94 +1,4 @@
-import %7B routeActions %7D from 'react-router-redux';%0Aimport fetch from 'isomorphic-fetch';%0A%0A
 //%0A/
@@ -31,22 +31,18 @@
 t const 
-REQUES
+GE
 T_BUS_ST
@@ -59,17 +59,14 @@
 _ME 
+ 
 = '
-REQUES
+GE
 T_BU
@@ -88,414 +88,208 @@
 ME'%0A
-%0A//%0A//  actions helpers%0A//%0A%0Afunction requestBusStopsAroundMe( coors, meters ) %7B%0A  fetch( 'secret-depths-4660.herokuapp/paradas?lt=' + coors.latitude + '&ln=' + coors.longitude + '&r=' + meters )%0A    .then( function()%7B%0A      dispatch( routeActions.push( '/loading' ) );%0A    %7D)%0A    .then( function( response ) %7B%0A      if ( response.status %3E= 400 ) %7B%0A        dispatch( routeActions.push( '/errors' ) );%0A      
+export const SET_METERS_AROUND_ME     = 'SET_METERS_AROUND_ME'%0Aexport const SET_COORS_AROUND_ME      = 'SET_COORS_AROUND_ME'%0A%0A//%0A//  actions creators%0A//%0A%0Aexport function setMetersAroundMe( meters ) %7B%0A
   re
@@ -295,26 +295,52 @@
 eturn %7B%0A    
-  
+type: SET_METERS_AROUND_ME,%0A
     meters: 
@@ -349,235 +349,61 @@
 ters
-,
 %0A  
-        coors: coors,%0A          busStops: %7B%7D,%0A          error: %7B%0A            type: response.status,%0A            message: response.message%0A          %7D%0A        %7D%0A      %7D%0A      dispatch( routeActions.push( '/results' ) );%0A    
+%7D;%0A%7D%0A%0Aexport function setCoorsAroundMe( coors ) %7B%0A
   re
@@ -417,32 +417,35 @@
     
-    meters: meters,%0A    
+type: SET_COORS_AROUND_ME,%0A
     
@@ -460,233 +460,71 @@
 oors
-,
 %0A  
-      busStops: response.json(),%0A        error: %7B%7D%0A      %7D%0A    %7D)%0A%7D%0A%0A//%0A//  actions creators%0A//%0A%0Aexport function getBusStopsAroundMe( coors, meters ) %7B%0A  var busStopsApiResponse = requestBusStopsAroundMe( coors, meters );
+%7D;%0A%7D%0A%0Aexport function getBusStopsAroundMe( coors, meters ) %7B
 %0A  r
@@ -545,14 +545,10 @@
 pe: 
-REQUES
+GE
 T_BU
@@ -574,49 +574,44 @@
     
-busStopsAroundMe: busStopsApiResponse
+meters: meters,%0A    coors: coors
 %0A  %7D;%0A%7D%0A
@@ -590,28 +590,29 @@
 rs,%0A    coors: coors%0A  %7D;%0A%7D%0A
+%0A

add new actions