DefinitelyTyped/types/react-instantsearch-native/react-instantsearch-native-tests.tsx
tkow 5d2b848c4a [react-instantsearch-native:hotfix] avoid to set type conflicted prop (#38125)
* [hotfix] avoid to set type conflicted prop

* lint

* add semi colon

* [chore] some remove a nit, and add same type migration to react-instantsearch-dom

* [chore] remove algoliaClient

* [chore] re-add algoliaClient
2019-09-09 11:34:11 -07:00

104 lines
2.6 KiB
TypeScript

import * as React from "react";
import { SearchBox, Hits, Highlight, Menu } from "react-instantsearch-dom";
import { InstantSearch, Index, connectStateResults } from 'react-instantsearch-native';
import { values } from 'lodash';
// https://community.algolia.com/react-instantsearch/guide/Conditional_display.html
const App1 = () => (
<InstantSearch appId="" apiKey="" indexName="first">
<SearchBox />
<AllResults>
<div>
<Index indexName="first">
<IndexResults>
<div>
<div>first: </div>
<Hits />
</div>
</IndexResults>
</Index>
<Index indexName="second">
<IndexResults>
<div>
<div>second: </div>
<Hits />
</div>
</IndexResults>
</Index>
<Index indexName="third">
<IndexResults>
<div>
<div>third: </div>
<Hits />
</div>
</IndexResults>
</Index>
</div>
</AllResults>
</InstantSearch>
);
const App2 = () => (
<InstantSearch searchClient={{}} indexName="first">
<SearchBox />
<AllResults>
<div>
<Index indexName="first">
<IndexResults>
<div>
<div>first: </div>
<Hits />
</div>
</IndexResults>
</Index>
<Index indexName="second">
<IndexResults>
<div>
<div>second: </div>
<Hits />
</div>
</IndexResults>
</Index>
<Index indexName="third">
<IndexResults>
<div>
<div>third: </div>
<Hits />
</div>
</IndexResults>
</Index>
</div>
</AllResults>
</InstantSearch>
);
const IndexResults = connectStateResults(
({ searchState, searchResults, children }) =>
searchResults && searchResults.nbHits !== 0 ? (
children as React.ReactElement
) : (
<div>
No results has been found for {searchState.query} and index{' '}
{searchResults ? searchResults.index : ''}
</div>
)
);
const AllResults = connectStateResults(({ allSearchResults, children }) => {
const hasResults =
allSearchResults &&
values(allSearchResults).some(results => results.nbHits > 0);
return !hasResults ? (
<div>
<div>No results in category, products or brand</div>
<Index indexName="first" />
<Index indexName="second" />
<Index indexName="third" />
</div>
) : (
children as React.ReactElement
);
});