2018-04-05 19:13:32 +00:00
|
|
|
import createReducer from 'utils/createReducer';
|
2017-05-26 06:20:00 +00:00
|
|
|
import * as actions from './actions';
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
const initialState = {
|
2017-05-26 06:20:00 +00:00
|
|
|
show: false,
|
2018-04-25 03:36:27 +00:00
|
|
|
results: []
|
|
|
|
};
|
2017-05-26 06:20:00 +00:00
|
|
|
|
|
|
|
export const getSearch = state => state.search;
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
export default createReducer(initialState, {
|
|
|
|
[actions.socket.SEARCH](state, { results }) {
|
2018-05-25 21:54:36 +00:00
|
|
|
state.results = results || [];
|
2017-05-26 06:20:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
[actions.TOGGLE_SEARCH](state) {
|
2018-04-25 03:36:27 +00:00
|
|
|
state.show = !state.show;
|
2017-05-26 06:20:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export function searchMessages(server, channel, phrase) {
|
|
|
|
return {
|
|
|
|
type: actions.SEARCH_MESSAGES,
|
|
|
|
server,
|
|
|
|
channel,
|
|
|
|
phrase,
|
|
|
|
socket: {
|
|
|
|
type: 'search',
|
|
|
|
data: { server, channel, phrase }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function toggleSearch() {
|
|
|
|
return {
|
|
|
|
type: actions.TOGGLE_SEARCH
|
|
|
|
};
|
|
|
|
}
|