Skip to content

Commit

Permalink
feat(React InstantSearch Hooks): introduce multi-index hits sample (#388
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sarahdayan authored Jun 9, 2022
1 parent 924553b commit d0353fc
Show file tree
Hide file tree
Showing 10 changed files with 9,094 additions and 0 deletions.
23 changes: 23 additions & 0 deletions React InstantSearch Hooks/multi-index-hits/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
21 changes: 21 additions & 0 deletions React InstantSearch Hooks/multi-index-hits/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# multi-index-hits

_This project was generated with [create-instantsearch-app](https://github.com/algolia/create-instantsearch-app) by [Algolia](https://algolia.com)._

## Get started

To run this project locally, install the dependencies and run the local server:

```sh
npm install
npm start
```

Alternatively, you may use [Yarn](https://http://yarnpkg.com/):

```sh
yarn
yarn start
```

Open http://localhost:3000 to see your app.
35 changes: 35 additions & 0 deletions React InstantSearch Hooks/multi-index-hits/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "multi-index-hits",
"version": "0.1.0",
"private": true,
"dependencies": {
"algoliasearch": "^4.13.1",
"instantsearch.css": "^7.4.5",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-instantsearch-hooks-web": "^6.27.0",
"react-scripts": "^5.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions React InstantSearch Hooks/multi-index-hits/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">

<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.png">

<title>multi-index-hits</title>
</head>

<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>

<div id="root"></div>
</body>

</html>
17 changes: 17 additions & 0 deletions React InstantSearch Hooks/multi-index-hits/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.container {
max-width: 1200px;
margin: 0 auto;
padding: 1rem;
}

@media screen and (max-width: 768px) {
.ais-Hits-item {
width: calc(50% - 1rem);
}
}

@media screen and (max-width: 480px) {
.ais-Hits-item {
width: 100%;
}
}
61 changes: 61 additions & 0 deletions React InstantSearch Hooks/multi-index-hits/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import algoliasearch from 'algoliasearch/lite';
import {
Configure,
Highlight,
Hits,
Index,
InstantSearch,
SearchBox,
} from 'react-instantsearch-hooks-web';

import 'instantsearch.css/themes/algolia.css';
import './App.css';

const searchClient = algoliasearch(
'latency',
'6be0576ff61c053d5f9a3225e2a90f76'
);

function App() {
return (
<div className="container">
<InstantSearch indexName="instant_search" searchClient={searchClient}>
<SearchBox />

<Index indexName="instant_search">
<h2>
index: <code>instant_search</code>
</h2>
<Configure hitsPerPage={16} />
<Hits hitComponent={ProductHit} />
</Index>

<Index indexName="instant_search_demo_query_suggestions">
<h2>
index: <code>instant_search_demo_query_suggestions</code>
</h2>
<Configure hitsPerPage={8} />
<Hits hitComponent={QuerySuggestionHit} />
</Index>
</InstantSearch>
</div>
);
}

function ProductHit({ hit }) {
return (
<div>
<Highlight attribute="name" hit={hit} />
</div>
);
}

function QuerySuggestionHit({ hit }) {
return (
<div>
<Highlight attribute="query" hit={hit} />
</div>
);
}

export default App;
10 changes: 10 additions & 0 deletions React InstantSearch Hooks/multi-index-hits/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
body,
h1 {
margin: 0;
padding: 0;
}

body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
}
11 changes: 11 additions & 0 deletions React InstantSearch Hooks/multi-index-hits/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import { createRoot } from 'react-dom/client';

import App from './App';

import './index.css';

const container = document.getElementById('root');
const root = createRoot(container);

root.render(<App />);
Loading

0 comments on commit d0353fc

Please sign in to comment.