From 1c83968c9bf90aa15f69d4821f43bbfd3ac790dc Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 1 Aug 2018 13:01:29 -0400 Subject: [PATCH] add api, action and saga for process list --- embark-ui/src/actions/index.js | 30 +++++++++++++++++++++++++++--- embark-ui/src/api/index.js | 11 ++++++++++- embark-ui/src/sagas/index.js | 21 ++++++++++++++++++--- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/embark-ui/src/actions/index.js b/embark-ui/src/actions/index.js index 98d25618..f750ddf1 100644 --- a/embark-ui/src/actions/index.js +++ b/embark-ui/src/actions/index.js @@ -1,22 +1,46 @@ +// Accounts export const FETCH_ACCOUNTS = 'FETCH_ACCOUNTS'; export const RECEIVE_ACCOUNTS = 'RECEIVE_ACCOUNTS'; export const RECEIVE_ACCOUNTS_ERROR = 'RECEIVE_ACCOUNTS_ERROR'; +// Processes +export const FETCH_PROCESSES = 'FETCH_PROCESSES'; +export const RECEIVE_PROCESSES = 'RECEIVE_PROCESSES'; +export const RECEIVE_PROCESSES_ERROR = 'RECEIVE_PROCESSES_ERROR'; export function fetchAccounts() { return { type: FETCH_ACCOUNTS }; -}; +} export function receiveAccounts(accounts) { return { type: RECEIVE_ACCOUNTS, accounts: accounts }; -}; +} export function receiveAccountsError() { return { type: RECEIVE_ACCOUNTS_ERROR }; -}; +} + +export function fetchProcesses() { + return { + type: FETCH_PROCESSES + }; +} + +export function receiveProcesses(processes) { + return { + type: RECEIVE_PROCESSES, + accounts: processes + }; +} + +export function receiveProcessesError() { + return { + type: RECEIVE_PROCESSES_ERROR + }; +} diff --git a/embark-ui/src/api/index.js b/embark-ui/src/api/index.js index 2af45b22..2adc3d1e 100644 --- a/embark-ui/src/api/index.js +++ b/embark-ui/src/api/index.js @@ -2,4 +2,13 @@ import axios from "axios"; export function fetchAccounts() { return axios.get('http://localhost:8000/embark-api/blockchain/accounts'); -}; +} + +export function fetchProcesses() { + console.log('Calling this shit'); + const stuff = axios.get('http://localhost:8000/embark-api/processes'); + stuff.then(result => { + console.log('result', result); + }).catch(console.error); + return stuff; +} diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js index 370cd6fc..49f6c8c6 100644 --- a/embark-ui/src/sagas/index.js +++ b/embark-ui/src/sagas/index.js @@ -1,6 +1,6 @@ -import {all, call, fork, put, takeEvery} from 'redux-saga/effects'; import * as actions from '../actions'; import * as api from '../api'; +import {all, call, fork, put, takeEvery} from 'redux-saga/effects'; export function *fetchAccounts() { try { @@ -15,6 +15,21 @@ export function *watchFetchAccounts() { yield takeEvery(actions.FETCH_ACCOUNTS, fetchAccounts); } -export default function *root() { - yield all([fork(watchFetchAccounts)]); + +export function *fetchProcesses() { + try { + const processes = yield call(api.fetchProcesses); + console.log('Got processes', processes); + yield put(actions.receiveProcesses(processes)); + } catch (e) { + yield put(actions.receiveProcessesError()); + } +} + +export function *watchFetchProcesses() { + yield takeEvery(actions.FETCH_PROCESSES, fetchProcesses); +} + +export default function *root() { + yield all([fork(watchFetchAccounts, watchFetchProcesses())]); }