2017-05-26 06:20:00 +00:00
|
|
|
import { List, Record } from 'immutable';
|
2017-06-21 06:40:28 +00:00
|
|
|
import createReducer from 'util/createReducer';
|
2017-05-26 06:20:00 +00:00
|
|
|
import * as actions from './actions';
|
|
|
|
|
|
|
|
const State = Record({
|
|
|
|
show: false,
|
|
|
|
results: List()
|
|
|
|
});
|
|
|
|
|
|
|
|
export const getSearch = state => state.search;
|
|
|
|
|
|
|
|
export default createReducer(new State(), {
|
|
|
|
[actions.socket.SEARCH](state, action) {
|
|
|
|
return state.set('results', List(action.results));
|
|
|
|
},
|
|
|
|
|
|
|
|
[actions.TOGGLE_SEARCH](state) {
|
|
|
|
return state.set('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
|
|
|
|
};
|
|
|
|
}
|