File size: 913 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import { createSearchResults } from './createSearchResults';
import type { IndexWidget } from 'instantsearch.js/es/widgets/index/index';
export function getIndexSearchResults(indexWidget: IndexWidget) {
const helper = indexWidget.getHelper()!;
const results =
// On SSR, we get the results injected on the Index.
indexWidget.getResults() ||
// On the browser, we create fallback results based on the helper state.
createSearchResults(helper.state);
const scopedResults = indexWidget.getScopedResults().map((scopedResult) => {
const fallbackResults =
scopedResult.indexId === indexWidget.getIndexId()
? results
: createSearchResults(scopedResult.helper.state);
return {
...scopedResult,
// We keep `results` from being `null`.
results: scopedResult.results || fallbackResults,
};
});
return {
results,
scopedResults,
};
}
|