-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(two-columns-layout-example): add faq plugin
- Loading branch information
1 parent
c1b9214
commit 3b137f9
Showing
5 changed files
with
96 additions
and
3 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
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,77 @@ | ||
/** @jsx h */ | ||
import { | ||
AutocompleteComponents, | ||
AutocompletePlugin, | ||
getAlgoliaResults, | ||
} from '@algolia/autocomplete-js'; | ||
import { h } from 'preact'; | ||
|
||
import { Breadcrumb } from '../components/Breadcrumb'; | ||
import { ALGOLIA_FAQ_INDEX_NAME } from '../constants'; | ||
import { searchClient } from '../searchClient'; | ||
import { FaqHit } from '../types'; | ||
|
||
export const faqPlugin: AutocompletePlugin<FaqHit, {}> = { | ||
getSources({ query }) { | ||
if (!query) { | ||
return []; | ||
} | ||
|
||
return [ | ||
{ | ||
sourceId: 'faqPlugin', | ||
getItems() { | ||
return getAlgoliaResults<FaqHit>({ | ||
searchClient, | ||
queries: [ | ||
{ | ||
indexName: ALGOLIA_FAQ_INDEX_NAME, | ||
query, | ||
params: { | ||
hitsPerPage: 1, | ||
}, | ||
}, | ||
], | ||
}); | ||
}, | ||
templates: { | ||
item({ item, components }) { | ||
return <FaqItem hit={item} components={components} />; | ||
}, | ||
}, | ||
}, | ||
]; | ||
}, | ||
}; | ||
|
||
type FaqItemProps = { | ||
hit: FaqHit; | ||
components: AutocompleteComponents; | ||
}; | ||
|
||
const FaqItem = ({ hit, components }: FaqItemProps) => { | ||
const breadcrumbItems = hit.list_categories; | ||
|
||
return ( | ||
<div className="aa-ItemWrapper aa-FaqItem"> | ||
<div className="aa-ItemContent"> | ||
<div className="aa-ItemIcon aa-ItemIcon--noBorder"> | ||
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor"> | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="2" | ||
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" | ||
/> | ||
</svg> | ||
</div> | ||
<div className="aa-ItemContentBody"> | ||
<div className="aa-ItemContentTitle"> | ||
<components.ReverseHighlight hit={hit} attribute="title" /> | ||
</div> | ||
</div> | ||
</div> | ||
<Breadcrumb items={breadcrumbItems} /> | ||
</div> | ||
); | ||
}; |
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 @@ | ||
import { Hit } from '@algolia/client-search'; | ||
|
||
type FaqRecord = { | ||
list_categories: string[]; | ||
title: string; | ||
description: string; | ||
}; | ||
|
||
export type FaqHit = Hit<FaqRecord>; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './ProductHit'; | ||
export * from './CategoryHit'; | ||
export * from './BrandHit'; | ||
export * from './FaqHit'; |
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