Skip to content

Commit

Permalink
Merge pull request #1 from coveo/DOC-15369-Resurrect-initial-Headless…
Browse files Browse the repository at this point in the history
…-tutorial

DOC-15369 update readme
  • Loading branch information
telmaq authored Aug 7, 2024
2 parents 7797bd8 + 3cf03c9 commit 0ab4bbf
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This project was set up with [Vite](https://vitejs.dev/guide/#scaffolding-your-f

## Setup

Vite requires `Node.js` version 18+ or 20+, please upgrade if warned.
Vite requires `Node.js` version 18+ or 20+, please upgrade if warned by your package manager.

Clone or download the project and run `npm install` in the project directory.

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Coveo Headless Search Interface</title>
<title>Headless Tutorial</title>
</head>
<body>
<div id="root"></div>
Expand Down
5 changes: 5 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
text-align: center;
}

img {
max-width: 40%;
}

.search-section {
display: flex;
justify-content: center;
margin-bottom: 2rem;
text-align: left;
}

.search-box {
Expand Down
3 changes: 0 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import {
facet as FacetController,
resultList as ResultListController,
sort as SortController,
pager as PagerController
} from './controllers/controllers'
import './App.css'

import { headlessEngine } from "./Engine";
import { criteria, Sort } from './components/Sort';
import Pager from './components/Pager';

let didInit = false;

Expand All @@ -39,7 +37,6 @@ function App() {
<div className="results-section column">
<Sort controller={SortController} criteria={criteria}/>
<ResultList controller={ResultListController} />
<Pager controller={PagerController} />
</div>
</div>
</>
Expand Down
25 changes: 22 additions & 3 deletions src/Engine.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import {
buildSearchEngine,
getSampleSearchEngineConfiguration
getSampleSearchEngineConfiguration,
loadFieldActions,
SearchEngine,
} from "@coveo/headless";


export const headlessEngine = buildSearchEngine({
const FIELDS = [
"ec_brand",
"ec_images",
"ec_price",
"ec_promo_price",
"ec_rating",
"ec_reviews",
];

const registerAdditionalFields = (headlessEngine: SearchEngine) => {
const fieldActions = loadFieldActions(headlessEngine);
headlessEngine.dispatch(fieldActions.registerFieldsToInclude(FIELDS));
return headlessEngine;
}

const buildEngine = buildSearchEngine({
configuration: getSampleSearchEngineConfiguration(),
});
});

export const headlessEngine = registerAdditionalFields(buildEngine);
File renamed without changes.
29 changes: 0 additions & 29 deletions src/components/Pager.tsx

This file was deleted.

5 changes: 4 additions & 1 deletion src/components/ResultList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect, FunctionComponent } from "react";
import { ResultList as ResultListController } from "@coveo/headless";
import { InteractiveResult } from "./Interative-result";
import { InteractiveResult } from "./InteractiveResult";

interface ResultListProps {
controller: ResultListController;
Expand Down Expand Up @@ -28,6 +28,9 @@ const ResultList: FunctionComponent<ResultListProps> = (props) => {
<h2>{result.title}</h2>
</InteractiveResult>
<p>{result.excerpt}</p>
{typeof result.raw.ec_images === 'string' && (
<img src={result.raw.ec_images} alt="" />
)}
</article>
</li>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
buildResultList,
buildFacet,
buildSort,
buildPager,
} from "@coveo/headless";
import { criteria } from "../components/Sort";
import { headlessEngine } from "../Engine";
Expand All @@ -18,5 +17,3 @@ const initialCriterion = criteria[0][1];
export const sort = buildSort(headlessEngine, {
initialState: { criterion: initialCriterion },
});

export const pager = buildPager(headlessEngine);

0 comments on commit 0ab4bbf

Please sign in to comment.