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-06-15 08:58:51 +00:00
|
|
|
[actions.socket.CHANNEL_SEARCH](state, { results, start, network, 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) {
|
2020-06-15 08:58:51 +00:00
|
|
|
state.topCache[network] = results;
|
2020-05-03 07:05:16 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-15 08:58:51 +00:00
|
|
|
export function searchChannels(network, q, start) {
|
2019-01-23 06:34:39 +00:00
|
|
|
return {
|
|
|
|
type: actions.CHANNEL_SEARCH,
|
2020-06-15 08:58:51 +00:00
|
|
|
network,
|
2019-01-23 06:34:39 +00:00
|
|
|
q,
|
|
|
|
socket: {
|
|
|
|
type: 'channel_search',
|
2020-06-15 08:58:51 +00:00
|
|
|
data: { network, q, start }
|
2019-01-23 06:34:39 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|