import React from 'react';
import 'whatwg-fetch';
import {addBuildSummary} from './Actions.es6'

const receiveBuildSummaries = (dispatch) => {
  const endpoint = "ws://localhost:4444/api/summaries";

  let dummy = [
     { buildId: 1, buildNumber: 1, state: "success", startTime: "2016-08-29T14:54Z", duration: 360},
     { buildId: 2, buildNumber: 2, state: "failed",  startTime: "2016-08-29T13:54Z", duration: 120},
     { buildId: 4, buildNumber: 4, state: "running", startTime: "2016-08-31T12:54Z", duration: 5466}
  ]

  fetch(endpoint).then(response => response.json()).then(body=>dispatch(addBuildSummary(body.summaries)));



}

export { receiveBuildSummaries };

@@ -160,10 +160,12 @@
  = %22
-ws
+http
 ://l
@@ -513,16 +513,116 @@
 n: 5466%7D
+,%0A     %7B buildId: 5, buildNumber: 4, state: %22running%22, startTime: %222016-08-31T12:54Z%22, duration: -2%7D
 %0A  %5D%0A%0A  
@@ -724,16 +724,120 @@
 aries)))
+%0A  .catch(()=%3E%7B%0A    console.log(%22fallback to dummy data%22);%0A    dispatch(addBuildSummary(dummy));%0A  %7D)%0A  
 ;%0A%0A%0A%0A%7D%0A%0A

add dummy fallback for development