summaryrefslogtreecommitdiff
path: root/client/actions.js
blob: 5f396e24d9c8218ca530a921757cfa882bc45afe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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, error })
  })
}

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 similar = (url, threshold) => dispatch => {
  const params = new FormData()
  params.append('url', url)
  params.append('threshold', threshold)
  api(dispatch, post, 'similar', '/api/v1/similar', params)
}

export const match = (url, threshold) => dispatch => {
  const params = new FormData()
  params.append('url', url)
  params.append('threshold', threshold)
  api(dispatch, post, 'similar', '/api/v1/match', params)
}

export const updateQuery = state => dispatch => {
  dispatch({ type: types.api.updateQuery, state })
}