generated from acdh-oeaw/template-app-next
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make faceted listing use instantsearch with single refinement list
- Loading branch information
1 parent
9392750
commit 03d55bb
Showing
6 changed files
with
84 additions
and
67 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { FacetedListing } from "@/components/faceted-listing"; | ||
|
||
export default function LanguagesPage() { | ||
return <FacetedListing queryArgToRefinementFields={{ language: "language" }} />; | ||
return <FacetedListing queryArgsToRefinementFields={{ language: "language" }} />; | ||
} |
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,11 +1,21 @@ | ||
import WorksPage from "./[work]/page"; | ||
import { getTranslations } from "next-intl/server"; | ||
|
||
interface BlankWorksPageProps { | ||
import { FacetedListing } from "@/components/faceted-listing"; | ||
|
||
interface WorksPageProps { | ||
params: { | ||
category: string; | ||
}; | ||
} | ||
|
||
export default function BlankWorksPage(props: BlankWorksPageProps) { | ||
return <WorksPage params={props.params} />; | ||
export default async function WorksPage(props: WorksPageProps) { | ||
const t = await getTranslations("BernhardCategories"); | ||
return ( | ||
<FacetedListing | ||
// 'category' values in the database are stored as the english category strings, not the URL slugs | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
filters={{ "contains.work.category": t(props.params.category as any) }} | ||
queryArgsToRefinementFields={{ work: "contains.work.title" }} | ||
/> | ||
); | ||
} |
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,20 +1,24 @@ | ||
import { MainContent } from "@/components/main-content"; | ||
|
||
import { InstantSearch } from "./instantsearch"; | ||
import { SingleRefinementList } from "./single-refinement-list"; | ||
|
||
export interface FacetedListingProps { | ||
queryArgToRefinementFields: Record<string, string>; | ||
queryArgsToRefinementFields: Record<string, string>; | ||
filters?: Record<string, string>; | ||
} | ||
|
||
export function FacetedListing(props: FacetedListingProps) { | ||
// const data = await getFaceted(props.facet, safeParams.facetValue); | ||
// const publications = data.hits?.map((h) => { | ||
// return h.document; | ||
// }); | ||
|
||
return ( | ||
<MainContent> | ||
<InstantSearch queryArgToRefinementFields={props.queryArgToRefinementFields}></InstantSearch> | ||
<InstantSearch | ||
filters={props.filters} | ||
queryArgsToRefinementFields={props.queryArgsToRefinementFields} | ||
> | ||
{Object.values(props.queryArgsToRefinementFields).map((attribute) => { | ||
return <SingleRefinementList key={attribute} attribute={attribute} />; | ||
})} | ||
</InstantSearch> | ||
</MainContent> | ||
); | ||
} |
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,27 @@ | ||
"use client"; | ||
import { useTranslations } from "next-intl"; | ||
import { RefinementList } from "react-instantsearch"; | ||
|
||
// a refinement list that is alphabetically ordered and only allows filtering for one value | ||
export function SingleRefinementList({ attribute }: { attribute: string }) { | ||
const t = useTranslations("SearchPage"); | ||
const attributePath = attribute.split("."); | ||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
const attributeKey = `filter_by.${attributePath[attributePath.length - 1]}`; | ||
return ( | ||
<RefinementList | ||
attribute={attribute} | ||
classNames={{ | ||
count: 'before:content-["("] after:content-[")"]', | ||
disabledShowMore: "hidden", | ||
labelText: "px-1", | ||
root: "p-2", | ||
}} | ||
limit={1000} | ||
searchable={true} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
searchablePlaceholder={`${t("filter")} ${t(attributeKey as any)}`} | ||
sortBy={["name"]} | ||
/> | ||
); | ||
} |
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