diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-01-13 00:54:13 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-01-13 00:54:13 +0100 |
| commit | 47b6ae0f8ad2f49692222bb0c800e7ba1eb4b94b (patch) | |
| tree | 0206451c15aec72128003d0e953a55b40b81b9a8 /client/faceAnalysis/faceAnalysis.actions.js | |
| parent | bb7efd0af0db8183b5b3f96ac0de1bfd9cd249ae (diff) | |
face info page
Diffstat (limited to 'client/faceAnalysis/faceAnalysis.actions.js')
| -rw-r--r-- | client/faceAnalysis/faceAnalysis.actions.js | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/client/faceAnalysis/faceAnalysis.actions.js b/client/faceAnalysis/faceAnalysis.actions.js index 90d7156f..6a318b5d 100644 --- a/client/faceAnalysis/faceAnalysis.actions.js +++ b/client/faceAnalysis/faceAnalysis.actions.js @@ -8,7 +8,7 @@ import { get, post } from '../util' // urls const url = { - upload: (dataset) => process.env.API_HOST + '/api/dataset/' + dataset + '/face', + upload: () => process.env.API_HOST + '/task/upload/sleep', } export const publicUrl = { } @@ -26,6 +26,11 @@ const loaded = (tag, data, offset = 0) => ({ data, offset }) +const polled = (data, offset = 0) => ({ + type: types.faceAnalysis.poll, + data, + offset +}) const error = (tag, err) => ({ type: types.faceAnalysis.error, tag, @@ -42,7 +47,7 @@ export const updateOptions = opt => dispatch => { export const upload = (payload, file) => dispatch => { // const { options } = store.getState().faceAnalysis - const tag = 'result' + const tag = 'task' const fd = new FormData() fd.append('query_img', file) // fd.append('limit', options.perPage) @@ -62,14 +67,13 @@ const POLL_DELAY = 500 let pollTimeout = null export const poll = (payload, taskURL) => dispatch => { - const tag = 'poll' clearTimeout(pollTimeout) - dispatch(loading(tag)) get(taskURL) .then(data => { - dispatch(loaded(tag, data)) - // check if complete - pollTimeout = setTimeout(() => poll(payload, taskURL), POLL_DELAY) + dispatch(polled(data)) + if (!data.complete) { + pollTimeout = setTimeout(() => poll(payload, taskURL), POLL_DELAY) + } }) - .catch(err => dispatch(error(tag, err))) + .catch(err => dispatch(error('result', err))) } |
