add api, action and saga for process list

This commit is contained in:
Jonathan Rainville 2018-08-01 13:01:29 -04:00 committed by Pascal Precht
parent ebf18f47a8
commit 63bc9a909c
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
3 changed files with 55 additions and 7 deletions

View File

@ -1,22 +1,46 @@
// Accounts
export const FETCH_ACCOUNTS = 'FETCH_ACCOUNTS'; export const FETCH_ACCOUNTS = 'FETCH_ACCOUNTS';
export const RECEIVE_ACCOUNTS = 'RECEIVE_ACCOUNTS'; export const RECEIVE_ACCOUNTS = 'RECEIVE_ACCOUNTS';
export const RECEIVE_ACCOUNTS_ERROR = 'RECEIVE_ACCOUNTS_ERROR'; 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() { export function fetchAccounts() {
return { return {
type: FETCH_ACCOUNTS type: FETCH_ACCOUNTS
}; };
}; }
export function receiveAccounts(accounts) { export function receiveAccounts(accounts) {
return { return {
type: RECEIVE_ACCOUNTS, type: RECEIVE_ACCOUNTS,
accounts: accounts accounts: accounts
}; };
}; }
export function receiveAccountsError() { export function receiveAccountsError() {
return { return {
type: RECEIVE_ACCOUNTS_ERROR 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
};
}

View File

@ -2,4 +2,13 @@ import axios from "axios";
export function fetchAccounts() { export function fetchAccounts() {
return axios.get('http://localhost:8000/embark-api/blockchain/accounts'); 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;
}

View File

@ -1,6 +1,6 @@
import {all, call, fork, put, takeEvery} from 'redux-saga/effects';
import * as actions from '../actions'; import * as actions from '../actions';
import * as api from '../api'; import * as api from '../api';
import {all, call, fork, put, takeEvery} from 'redux-saga/effects';
export function *fetchAccounts() { export function *fetchAccounts() {
try { try {
@ -15,6 +15,21 @@ export function *watchFetchAccounts() {
yield takeEvery(actions.FETCH_ACCOUNTS, fetchAccounts); 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())]);
} }