diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-04-28 15:54:41 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-04-28 15:54:41 +0200 |
| commit | aa5638a1c31ce56d59696580f33733dcf0d7764c (patch) | |
| tree | c2d1bd0e480b9bae113ce9af706927c5b7c55952 /client/actions.js | |
| parent | a72ecc91db39ac5a2d60aefc6d767da457500dde (diff) | |
refactor frontend, add threshold slider
Diffstat (limited to 'client/actions.js')
| -rw-r--r-- | client/actions.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/client/actions.js b/client/actions.js new file mode 100644 index 0000000..dfcfa09 --- /dev/null +++ b/client/actions.js @@ -0,0 +1,27 @@ +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 upload = (blob, threshold) => dispatch => { + const params = new FormData() + params.append('q', blob) + params.append('threshold', threshold) + api(dispatch, post, 'similar', '/api/v1/similar', params) +} + +export const submit = (url, threshold) => dispatch => { + const params = new FormData() + params.append('url', url) + params.append('threshold', threshold) + api(dispatch, post, 'similar', '/api/v1/similar', params) +} |
