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 | |
| parent | bb7efd0af0db8183b5b3f96ac0de1bfd9cd249ae (diff) | |
face info page
Diffstat (limited to 'client')
| -rw-r--r-- | client/faceAnalysis/faceAnalysis.actions.js | 20 | ||||
| -rw-r--r-- | client/faceAnalysis/faceAnalysis.query.js | 4 | ||||
| -rw-r--r-- | client/faceAnalysis/faceAnalysis.reducer.js | 7 | ||||
| -rw-r--r-- | client/index.js | 2 | ||||
| -rw-r--r-- | client/types.js | 2 |
5 files changed, 24 insertions, 11 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))) } diff --git a/client/faceAnalysis/faceAnalysis.query.js b/client/faceAnalysis/faceAnalysis.query.js index 86dbe1ae..6b92b70d 100644 --- a/client/faceAnalysis/faceAnalysis.query.js +++ b/client/faceAnalysis/faceAnalysis.query.js @@ -57,8 +57,8 @@ class FaceAnalysisQuery extends Component { {'Put yourself under the microscope of various facial recognition algorithms. See what can be determined from a photo.'} </p> <ol> - <li>Upload a photo of yourself</li> - <li>{'Your search data is never stored and immediately cleared '} + <li>Upload a photo of yourself and be judged by the algorithm</li> + <li>{'Your search data is only stored for the duration of this analysis and is immediately cleared '} {'once you leave this page.'}</li> </ol> <p> diff --git a/client/faceAnalysis/faceAnalysis.reducer.js b/client/faceAnalysis/faceAnalysis.reducer.js index d8e914ab..54a6d5eb 100644 --- a/client/faceAnalysis/faceAnalysis.reducer.js +++ b/client/faceAnalysis/faceAnalysis.reducer.js @@ -2,6 +2,7 @@ import * as types from '../types' const initialState = () => ({ query: {}, + task: {}, result: {}, loading: false, }) @@ -20,6 +21,12 @@ export default function faceAnalysisReducer(state = initialState(), action) { [action.tag]: action.data, } + case types.faceAnalysis.poll: + return { + ...state, + result: action.data, + } + case types.faceAnalysis.error: return { ...state, diff --git a/client/index.js b/client/index.js index 40be2841..96f2c8c8 100644 --- a/client/index.js +++ b/client/index.js @@ -20,6 +20,8 @@ function appendReactApplet(el, payload) { } function fetchDataset(payload) { + if (payload.command === 'face_analysis') return new Promise(resolve => resolve()) + if (payload.dataset === 'info') return new Promise(resolve => resolve()) const url = "https://megapixels.nyc3.digitaloceanspaces.com/v1/citations/" + payload.dataset + ".json" return fetch(url, { mode: 'cors' }).then(r => r.json()) } diff --git a/client/types.js b/client/types.js index 2d35ec36..fd9aa3e0 100644 --- a/client/types.js +++ b/client/types.js @@ -7,7 +7,7 @@ export const tagAsType = (type, names) => ( ) export const faceAnalysis = tagAsType('faceAnalysis', [ - 'loading', 'loaded', 'error', 'update_options', + 'loading', 'loaded', 'poll', 'error', 'update_options', ]) export const faceSearch = tagAsType('faceSearch', [ |
