dispatch/client/js/state/search.js

39 lines
715 B
JavaScript
Raw Normal View History

import createReducer from 'utils/createReducer';
import * as actions from './actions';
2018-04-25 03:36:27 +00:00
const initialState = {
show: false,
2018-04-25 03:36:27 +00:00
results: []
};
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 || [];
},
[actions.TOGGLE_SEARCH](state) {
2018-04-25 03:36:27 +00:00
state.show = !state.show;
}
});
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
};
}