dispatch/client/js/state/channelSearch.js

48 lines
947 B
JavaScript
Raw Normal View History

2019-01-23 06:34:39 +00:00
import createReducer from 'utils/createReducer';
import * as actions from 'state/actions';
const initialState = {
results: [],
2020-05-03 07:05:16 +00:00
end: false,
topCache: {}
2019-01-23 06:34:39 +00:00
};
export default createReducer(initialState, {
2020-05-03 07:05:16 +00:00
[actions.socket.CHANNEL_SEARCH](state, { results, start, server, q }) {
2019-01-23 06:34:39 +00:00
if (results) {
state.end = false;
if (start > 0) {
state.results.push(...results);
} else {
state.results = results;
2020-05-03 07:05:16 +00:00
if (!q) {
state.topCache[server] = results;
}
2019-01-23 06:34:39 +00:00
}
} else {
state.end = true;
}
},
2020-05-03 07:05:16 +00:00
[actions.OPEN_MODAL](state, { name, payload }) {
2019-01-23 06:34:39 +00:00
if (name === 'channel') {
2020-05-03 07:05:16 +00:00
state.results = state.topCache[payload] || [];
state.end = false;
2019-01-23 06:34:39 +00:00
}
}
});
export function searchChannels(server, q, start) {
return {
type: actions.CHANNEL_SEARCH,
server,
q,
socket: {
type: 'channel_search',
data: { server, q, start }
}
};
}