From aa5638a1c31ce56d59696580f33733dcf0d7764c Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sun, 28 Apr 2019 15:54:41 +0200 Subject: refactor frontend, add threshold slider --- client/actions.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 client/actions.js (limited to 'client/actions.js') 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) +} -- cgit v1.2.3-70-g09d2