summaryrefslogtreecommitdiff
path: root/client/actions.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/actions.js')
-rw-r--r--client/actions.js27
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)
+}