Skip to content

Commit 23e3859

Browse files
committed
Connect Algolia search page to live product results
1 parent ac230b5 commit 23e3859

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
NODE_ENV="development"
22
GRAPHQL_URL = "change me"
3-
PLACEHOLDER_SMALL_IMAGE_URL = "change me"
3+
PLACEHOLDER_SMALL_IMAGE_URL = "change me"
4+
ALGOLIA_APPLICATION_ID = "change me"
5+
ALGOLIA_SEARCH_ONLY_API_KEY = "change me"
6+
ALGOLIA_INDEX_NAME = "change me"

components/Products/ShowAllProducts.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export default {
5252
name: 'ShowProducts',
5353
props: {
5454
products: { type: Array, required: true },
55-
// TODO Add more prop types here
5655
},
5756
methods: {
5857
productImage(product) {

nuxt.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export default {
77
env: {
88
graphqlUrl: process.env.GRAPHQL_URL || 'http://localhost:3000/graphql',
99
placeholderSmallImage: process.env.PLACEHOLDER_SMALL_IMAGE_URL || '',
10+
AlgoliaApplicationId: process.env.ALGOLIA_APPLICATION_ID || '',
11+
AlgoliaSearchOnlyAPIKey: process.env.ALGOLIA_SEARCH_ONLY_API_KEY || '',
12+
AlgoliaIndexName: process.env.ALGOLIA_INDEX_NAME || '',
1013
},
1114
// Global page headers (https://go.nuxtjs.dev/config-head)
1215
head: {

pages/search.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
<ais-hits>
77
<template slot="item" slot-scope="{ item }">
88
<p>
9-
<ais-highlight attribute="name" :hit="item" />
9+
<ais-highlight attribute="product_name" :hit="item" />
1010
</p>
1111
<p>
12-
<ais-highlight attribute="brand" :hit="item" />
12+
<ais-highlight attribute="short_description" :hit="item" />
13+
</p>
14+
<p>
15+
<img :src="item.product_image" alt="item.product_name" />
1316
</p>
1417
</template>
1518
</ais-hits>
@@ -28,11 +31,12 @@ import {
2831
AisPagination,
2932
createServerRootMixin,
3033
} from 'vue-instantsearch'
34+
3135
import algoliasearch from 'algoliasearch/lite'
3236
3337
const searchClient = algoliasearch(
34-
'latency',
35-
'6be0576ff61c053d5f9a3225e2a90f76'
38+
process.env.AlgoliaApplicationId,
39+
process.env.AlgoliaSearchOnlyAPIKey
3640
)
3741
3842
export default {
@@ -48,7 +52,7 @@ export default {
4852
mixins: [
4953
createServerRootMixin({
5054
searchClient,
51-
indexName: 'instant_search',
55+
indexName: process.env.AlgoliaIndexName,
5256
}),
5357
],
5458
serverPrefetch() {

0 commit comments

Comments
 (0)