2020-07-27 22:04:12 +02:00
|
|
|
// @flow
|
|
|
|
import * as ACTIONS from 'constants/action_types';
|
|
|
|
import { handleActions } from 'util/redux-utils';
|
|
|
|
import { SEARCH_OPTIONS } from 'constants/search';
|
|
|
|
|
2020-12-03 18:29:47 +01:00
|
|
|
const defaultState: SearchState = {
|
|
|
|
// $FlowFixMe
|
2020-07-27 22:04:12 +02:00
|
|
|
options: {
|
2021-03-03 20:23:42 +01:00
|
|
|
[SEARCH_OPTIONS.RESULT_COUNT]: 50,
|
|
|
|
[SEARCH_OPTIONS.CLAIM_TYPE]: 'file,channel',
|
|
|
|
[SEARCH_OPTIONS.MEDIA_AUDIO]: false,
|
2020-07-27 22:04:12 +02:00
|
|
|
[SEARCH_OPTIONS.MEDIA_VIDEO]: true,
|
2021-03-03 20:23:42 +01:00
|
|
|
[SEARCH_OPTIONS.MEDIA_TEXT]: false,
|
|
|
|
[SEARCH_OPTIONS.MEDIA_IMAGE]: false,
|
|
|
|
[SEARCH_OPTIONS.MEDIA_APPLICATION]: false,
|
2020-07-27 22:04:12 +02:00
|
|
|
},
|
|
|
|
urisByQuery: {},
|
2020-12-03 18:29:47 +01:00
|
|
|
searching: false,
|
2020-07-27 22:04:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default handleActions(
|
|
|
|
{
|
|
|
|
[ACTIONS.SEARCH_START]: (state: SearchState): SearchState => ({
|
|
|
|
...state,
|
|
|
|
searching: true,
|
|
|
|
}),
|
|
|
|
[ACTIONS.SEARCH_SUCCESS]: (state: SearchState, action: SearchSuccess): SearchState => {
|
|
|
|
const { query, uris } = action.data;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
searching: false,
|
|
|
|
urisByQuery: Object.assign({}, state.urisByQuery, { [query]: uris }),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
[ACTIONS.SEARCH_FAIL]: (state: SearchState): SearchState => ({
|
|
|
|
...state,
|
|
|
|
searching: false,
|
|
|
|
}),
|
|
|
|
|
|
|
|
[ACTIONS.UPDATE_SEARCH_OPTIONS]: (state: SearchState, action: UpdateSearchOptions): SearchState => {
|
|
|
|
const { options: oldOptions } = state;
|
|
|
|
const newOptions = action.data;
|
|
|
|
const options = { ...oldOptions, ...newOptions };
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
options,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
defaultState
|
|
|
|
);
|