Make search page updates more efficient with batch actions
This commit is contained in:
parent
193738083f
commit
8f786baacd
1 changed files with 7 additions and 2 deletions
|
@ -4,6 +4,7 @@ import lighthouse from "lighthouse";
|
||||||
import { doResolveUri } from "actions/content";
|
import { doResolveUri } from "actions/content";
|
||||||
import { doNavigate, doHistoryPush } from "actions/app";
|
import { doNavigate, doHistoryPush } from "actions/app";
|
||||||
import { selectCurrentPage } from "selectors/app";
|
import { selectCurrentPage } from "selectors/app";
|
||||||
|
import batchActions from "util/batchActions";
|
||||||
|
|
||||||
export function doSearch(query) {
|
export function doSearch(query) {
|
||||||
return function(dispatch, getState) {
|
return function(dispatch, getState) {
|
||||||
|
@ -25,22 +26,26 @@ export function doSearch(query) {
|
||||||
dispatch(doNavigate("search", { query: query }));
|
dispatch(doNavigate("search", { query: query }));
|
||||||
} else {
|
} else {
|
||||||
lighthouse.search(query).then(results => {
|
lighthouse.search(query).then(results => {
|
||||||
|
const actions = [];
|
||||||
|
|
||||||
results.forEach(result => {
|
results.forEach(result => {
|
||||||
const uri = lbryuri.build({
|
const uri = lbryuri.build({
|
||||||
channelName: result.channel_name,
|
channelName: result.channel_name,
|
||||||
contentName: result.name,
|
contentName: result.name,
|
||||||
claimId: result.channel_id || result.claim_id,
|
claimId: result.channel_id || result.claim_id,
|
||||||
});
|
});
|
||||||
dispatch(doResolveUri(uri));
|
actions.push(doResolveUri(uri));
|
||||||
});
|
});
|
||||||
|
|
||||||
dispatch({
|
actions.push({
|
||||||
type: types.SEARCH_COMPLETED,
|
type: types.SEARCH_COMPLETED,
|
||||||
data: {
|
data: {
|
||||||
query,
|
query,
|
||||||
results,
|
results,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dispatch(batchActions(...actions));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue