Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
/dist
/.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: 'algolia',
};
22 changes: 22 additions & 0 deletions InstantSearch.js/infinitehits-async-transformitems/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/dist
/.cache

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

npm-debug.log*
yarn-debug.log*
yarn-error.log*
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"proseWrap": "never",
"trailingComma": "es5"
}
49 changes: 49 additions & 0 deletions InstantSearch.js/infinitehits-async-transformitems/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Instantsearch InfiniteHits async transfomItems


---

This sample illustrate how to asynchronoulsy load data into a hit template using [transformItems](https://www.algolia.com/doc/api-reference/widgets/hits/js/#widget-param-transformitems) in a infiniteHits page.

<p align="center"><img src="capture.png?raw=true" alt="A capture of the Algolia InfiniteHits async transfomItems" /></p>

## Features

This sample showcase the following features:

- 🗺️ InstantSearch [hits widget transformItems method](https://www.algolia.com/doc/api-reference/widgets/hits/js/#widget-param-transformitems).
- 🗺️ InstantSearch [infiniteHits widget](https://www.algolia.com/doc/api-reference/widgets/infinite-hits/js/).

## Demo

[Access the demo](https://codesandbox.io/s/github/algolia/doc-code-samples/tree/master/InstantSearch.js/infinitehits-async-transformitems)

## How to run this sample locally

### 1. Clone this repository

```
git clone git@github.com:algolia/doc-code-samples.git
```

### 2. Navigate to this sample folder

```
cd InstantSearch.js/infinitehits-async-transformitems
```

### 3. Install the dependencies and run the server

```
npm install
npm start
```

Alternatively, you may use Yarn:

```
yarn
yarn start
```

Open <http://localhost:3000> to see your app.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions InstantSearch.js/infinitehits-async-transformitems/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!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="manifest" href="./manifest.webmanifest" />
<link rel="shortcut icon" href="./favicon.png" />

<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/instantsearch.css@7/themes/algolia-min.css"
/>
<link rel="stylesheet" href="./src/index.css" />
<link rel="stylesheet" href="./src/app.css" />

<title>ais-ecommerce-demo-app</title>
</head>

<body>
<div class="ais-InstantSearch">
<h1>InstantSearch.js e-commerce demo</h1>

<div class="left-panel">
<div id="clear-refinements"></div>

<h2>Brands</h2>
<div id="brand-list"></div>
</div>

<div class="right-panel">
<div id="searchbox" class="ais-SearchBox"></div>
<div id="hits"></div>
<div id="pagination"></div>
</div>
</div>

<script src="https://cdn.jsdelivr.net/npm/algoliasearch@4/dist/algoliasearch-lite.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4"></script>
<script src="./src/app.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "is-ecommerce-demo-app",
"name": "is-ecommerce-demo-app Sample",
"icons": [
{
"src": "favicon.png",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
23 changes: 23 additions & 0 deletions InstantSearch.js/infinitehits-async-transformitems/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "demo-infinitehits-transformitems",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "parcel index.html --port 3000",
"build": "parcel build index.html",
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix"
},
"devDependencies": {
"babel-eslint": "10.0.1",
"eslint": "4.19.1",
"eslint-config-algolia": "13.3.0",
"eslint-config-prettier": "4.1.0",
"eslint-plugin-import": "2.17.3",
"eslint-plugin-prettier": "3.1.0",
"parcel-bundler": "1.12.3",
"prettier": "1.17.1"
},
"keywords": [],
"description": ""
}
50 changes: 50 additions & 0 deletions InstantSearch.js/infinitehits-async-transformitems/src/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
body {
font-family: sans-serif;
padding: 1em;
}

.ais-ClearRefinements {
margin: 1em 0;
}

.ais-SearchBox {
margin: 1em 0;
}

.ais-Pagination {
margin-top: 1em;
}

.left-panel {
float: left;
width: 250px;
}

.right-panel {
margin-left: 260px;
}

.ais-InstantSearch {
max-width: 960px;
overflow: hidden;
margin: 0 auto;
}

.ais-Hits-item {
margin-bottom: 1em;
width: calc(50% - 1rem);
}

.ais-Hits-item img {
margin-right: 1em;
}

.hit-name {
margin-bottom: 0.5em;
}

.hit-description {
color: #888;
font-size: 14px;
margin-bottom: 0.5em;
}
47 changes: 47 additions & 0 deletions InstantSearch.js/infinitehits-async-transformitems/src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* global instantsearch algoliasearch */

const search = instantsearch({
indexName: 'demo_ecommerce',
searchClient: algoliasearch('B1G2GM9NG0', 'aadef574be1f9252bb48d4ea09b5cfe5'),
});

search.addWidgets([
instantsearch.widgets.searchBox({
container: '#searchbox',
}),
instantsearch.widgets.clearRefinements({
container: '#clear-refinements',
}),
instantsearch.widgets.refinementList({
container: '#brand-list',
attribute: 'brand',
}),
instantsearch.widgets.infiniteHits({
transformItems: (items) => {
setTimeout(() => {
for (const item of items) {
document
.getElementById(item.objectID)
.querySelector('mark').innerHTML = 100; // see <mark> in hits template
}
}, 2000);

return items;
},
container: '#hits',
templates: {
item: `
<div id="{{objectID}}">
<img src="{{image}}" align="left" alt="{{name}}" />
<div class="hit-name">
{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}
</div>
<div class="hit-price">\${{price}}</div>
<mark></mark>
</div>
`,
},
}),
]);

search.start();
10 changes: 10 additions & 0 deletions InstantSearch.js/infinitehits-async-transformitems/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';
}
Loading