-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(js): autocomplete with results page
- Loading branch information
Showing
14 changed files
with
5,867 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/node_modules | ||
/dist | ||
/.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
extends: 'algolia', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"singleQuote": true, | ||
"proseWrap": "never", | ||
"trailingComma": "es5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# autocomplete-results-page | ||
|
||
_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. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!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/[email protected]/dist/instantsearch.min.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/instantsearch-theme-algolia.min.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/selectize.css"> | ||
<link rel="stylesheet" href="./src/index.css"> | ||
<link rel="stylesheet" href="./src/app.css"> | ||
|
||
<title>autocomplete-results-page</title> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<h1>InstantSearch.js - Results page with an autocomplete</h1> | ||
<div id="autocomplete"></div> | ||
<div id="hits"></div> | ||
</div> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/standalone/selectize.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/algoliasearchLite.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> | ||
<script src="./src/app.js"></script> | ||
</body> | ||
|
||
</html> |
15 changes: 15 additions & 0 deletions
15
InstantSearch.js/autocomplete-results-page/manifest.webmanifest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"short_name": "autocomplete-results-page", | ||
"name": "autocomplete-results-page 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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "autocomplete-results-page", | ||
"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": "8.2.6", | ||
"eslint": "5.5.0", | ||
"eslint-config-algolia": "13.2.3", | ||
"eslint-config-prettier": "3.0.1", | ||
"eslint-plugin-import": "2.14.0", | ||
"eslint-plugin-prettier": "2.6.2", | ||
"parcel-bundler": "1.9.7", | ||
"prettier": "1.14.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
h1 { | ||
margin-bottom: 1rem; | ||
} | ||
|
||
em { | ||
background: cyan; | ||
font-style: normal; | ||
} | ||
|
||
.container { | ||
max-width: 960px; | ||
margin: 0 auto; | ||
padding: 1em; | ||
} | ||
|
||
.ais-hits { | ||
margin-top: 1em; | ||
} | ||
|
||
.ais-Hits-item { | ||
margin-bottom: 2em; | ||
} | ||
|
||
.hit-name { | ||
margin-bottom: 0.5em; | ||
} | ||
|
||
.hit-description { | ||
color: #888; | ||
font-size: 14px; | ||
margin-bottom: 0.5em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* global $ instantsearch algoliasearch */ | ||
|
||
const searchClient = algoliasearch( | ||
'B1G2GM9NG0', | ||
'aadef574be1f9252bb48d4ea09b5cfe5' | ||
); | ||
|
||
const autocomplete = instantsearch.connectors.connectAutocomplete( | ||
({ indices, refine, widgetParams }, isFirstRendering) => { | ||
const { container, onSelectChange } = widgetParams; | ||
|
||
if (isFirstRendering) { | ||
container.html('<select id="ais-autocomplete"></select>'); | ||
|
||
container.find('select').selectize({ | ||
options: [], | ||
valueField: 'name', | ||
labelField: 'name', | ||
searchField: 'name', | ||
highlight: false, | ||
onType: refine, | ||
onChange(value) { | ||
onSelectChange(value); | ||
refine(value); | ||
}, | ||
}); | ||
|
||
return; | ||
} | ||
|
||
const [select] = container.find('select'); | ||
|
||
indices.forEach(index => { | ||
select.selectize.clearOptions(); | ||
index.results.hits.forEach(h => select.selectize.addOption(h)); | ||
select.selectize.refreshOptions(select.selectize.isOpen); | ||
}); | ||
} | ||
); | ||
|
||
const suggestions = instantsearch({ | ||
indexName: 'demo_ecommerce', | ||
searchClient, | ||
}); | ||
|
||
suggestions.addWidget( | ||
instantsearch.widgets.configure({ | ||
hitsPerPage: 5, | ||
}) | ||
); | ||
|
||
suggestions.addWidget( | ||
autocomplete({ | ||
container: $('#autocomplete'), | ||
onSelectChange(value) { | ||
// eslint-disable-next-line | ||
search.helper.setQuery(value).search(); | ||
}, | ||
}) | ||
); | ||
|
||
const search = instantsearch({ | ||
indexName: 'demo_ecommerce', | ||
searchClient, | ||
}); | ||
|
||
search.addWidget( | ||
instantsearch.widgets.configure({ | ||
hitsPerPage: 10, | ||
}) | ||
); | ||
|
||
search.addWidget( | ||
instantsearch.widgets.hits({ | ||
container: '#hits', | ||
templates: { | ||
item: ` | ||
<div class="ais-Hits-item"> | ||
<header class="hit-name"> | ||
{{{_highlightResult.name.value}}} | ||
</header> | ||
<p class="hit-description"> | ||
{{{_highlightResult.description.value}}} | ||
</p> | ||
</div> | ||
`, | ||
}, | ||
}) | ||
); | ||
|
||
suggestions.start(); | ||
search.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} |
Oops, something went wrong.