import { get, post } from './util' import * as types from './types' export const api = (dispatch, method, tag, url, params, after) => { dispatch({ type: types.api.loading, tag }) return method(url, params).then(data => { if (after) data = after(data) dispatch({ type: types.api.loaded, tag, data }) return data }).catch(err => { dispatch({ type: types.api.error, tag, err }) }) } export const getInstitutions = () => dispatch => { api(dispatch, get, 'institutions', '/api/institutions', {}) } export const getPapers = () => dispatch => { api(dispatch, get, 'papers', '/api/papers', {}) } export const getPaperInfo = key => dispatch => { api(dispatch, get, 'paperInfo', '/reports/datasets/final/' + key + '.json', {}) api(dispatch, get, 'unknownCitations', '/reports/datasets/unknown/' + key + '.json', {}) } export const getAddress = sha256 => dispatch => { api(dispatch, get, 'address', '/api/address/' + sha256, {}) } export const postAddress = data => dispatch => { api(dispatch, post, 'address', '/api/address/add', data) } export const getVerifications = () => dispatch => ( api(dispatch, get, 'verifications', '/api/verifications', {}) ) export const getVerificationsDataset = dataset => dispatch => ( api(dispatch, get, 'verifications', '/api/verifications/' + dataset, {}) ) export const getVerification = (dataset, sha256) => dispatch => ( api(dispatch, get, 'verify', '/api/verify/' + dataset + '/' + sha256, {}) ) export const postVerification = data => dispatch => ( api(dispatch, post, 'verify', '/api/verify/add', data) ) export const setSortedCitations = sortedCitations => dispatch => dispatch({ type: types.system.set_sorted_citations, sortedCitations })