diff options
| author | adamhrv <adam@ahprojects.com> | 2018-12-17 01:39:39 +0100 |
|---|---|---|
| committer | adamhrv <adam@ahprojects.com> | 2018-12-17 01:39:39 +0100 |
| commit | c7e73f613fc5189c0adeda9fd693cb6aca3d4247 (patch) | |
| tree | f4ee5eb0fd84d84780b2d31d48c5ab666ab63236 /client/faceSearch/faceSearch.actions.js | |
| parent | 88ec48e1c4d93ba9cd3aa186c068ef2aa4c27c56 (diff) | |
| parent | 6a6af799c528e7d2c865db75757e90cd921f85ae (diff) | |
Merge branch 'master' of github.com:adamhrv/megapixels_dev
Diffstat (limited to 'client/faceSearch/faceSearch.actions.js')
| -rw-r--r-- | client/faceSearch/faceSearch.actions.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/client/faceSearch/faceSearch.actions.js b/client/faceSearch/faceSearch.actions.js new file mode 100644 index 00000000..224977b5 --- /dev/null +++ b/client/faceSearch/faceSearch.actions.js @@ -0,0 +1,57 @@ +// import fetchJsonp from 'fetch-jsonp' +import * as types from '../types' +// import { hashPath } from '../util' +import { store } from '../store' +import { post, preloadImage } from '../util' +// import querystring from 'query-string' + +// urls + +const url = { + upload: (dataset) => process.env.API_HOST + '/api/dataset/' + dataset + '/face/', +} +export const publicUrl = { +} + +// standard loading events + +const loading = (tag, offset) => ({ + type: types.faceSearch.loading, + tag, + offset +}) +const loaded = (tag, data, offset = 0) => ({ + type: types.faceSearch.loaded, + tag, + data, + offset +}) +const error = (tag, err) => ({ + type: types.faceSearch.error, + tag, + err +}) + +// search UI functions + +export const updateOptions = opt => dispatch => { + dispatch({ type: types.faceSearch.update_options, opt }) +} + +// API functions + +export const upload = (payload, file) => dispatch => { + // const { options } = store.getState().faceSearch + const tag = 'result' + const fd = new FormData() + fd.append('query_img', file) + // fd.append('limit', options.perPage) + // if (!query) { + dispatch(loading(tag)) + // } + post(url.upload(payload.dataset), fd) + .then(data => { + dispatch(loaded(tag, data)) + }) + .catch(err => dispatch(error(tag, err))) +} |
