Skip to content

Commit

Permalink
refactor: move instantsearch components to dedicated folder
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinstadler committed Dec 9, 2024
1 parent 22f017c commit 29a3aa4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 18 deletions.
6 changes: 3 additions & 3 deletions app/[locale]/translators/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { MenuItem } from "instantsearch.js/es/connectors/menu/connectMenu";
import { useTranslations } from "next-intl";
import { useMenu } from "react-instantsearch";

import { InstantSearch } from "@/components/instantsearch";
import { InstantSearchProvider } from "@/components/instantsearch/instantsearchprovider";
import { MainContent } from "@/components/main-content";
import { SingleRefinementDropdown } from "@/components/single-refinement-dropdown";
import { TranslatorLink } from "@/components/translator-link";
Expand Down Expand Up @@ -49,7 +49,7 @@ export default function TranslatorsPage() {
const tl = useTranslations("Languages");
return (
<MainContent className="mx-auto w-screen max-w-screen-lg p-6">
<InstantSearch
<InstantSearchProvider
filters="contains.has_translators:true"
queryArgsToMenuFields={{ language: "language" }}
>
Expand All @@ -74,7 +74,7 @@ export default function TranslatorsPage() {
/>
</div>
<TranslatorsList />
</InstantSearch>
</InstantSearchProvider>
</MainContent>
);
}
17 changes: 10 additions & 7 deletions components/instantsearch-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { type ReactNode, useState } from "react";
import { Switch } from "react-aria-components";
import { SearchBox } from "react-instantsearch";

import { InstantSearch } from "./instantsearch";
import { InfiniteScroll } from "./instantsearch-infinitescroll";
import { PaginatedTable } from "./instantsearch-paginated-table";
import { InstantSearchSortBy } from "./instantsearch-sortby";
import { InstantSearchStats } from "./instantsearch-stats";
import { InfiniteScroll } from "./instantsearch/infinitescroll";
import { InstantSearchProvider } from "./instantsearch/instantsearchprovider";
import { PaginatedTable } from "./instantsearch/paginated-table";
import { InstantSearchSortBy } from "./instantsearch/sortby";
import { InstantSearchStats } from "./instantsearch/stats";
import { SingleRefinementDropdown } from "./single-refinement-dropdown";

interface InstantSearchProps {
Expand All @@ -27,7 +27,10 @@ export function InstantSearchView(props: InstantSearchProps): ReactNode {
const [view, setView] = useState<"covers" | "detail">("covers");

return (
<InstantSearch filters={props.filters} queryArgsToMenuFields={props.queryArgsToMenuFields}>
<InstantSearchProvider
filters={props.filters}
queryArgsToMenuFields={props.queryArgsToMenuFields}
>
<div className="grid grid-cols-[25%_75%] p-2">
<div className="mr-10">{props.children}</div>
<div>
Expand Down Expand Up @@ -61,6 +64,6 @@ export function InstantSearchView(props: InstantSearchProps): ReactNode {
{view === "covers" ? <InfiniteScroll /> : <PaginatedTable />}
</div>
</div>
</InstantSearch>
</InstantSearchProvider>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useInfiniteHits } from "react-instantsearch";

import type { Publication } from "@/lib/model";

import { PublicationGrid } from "./publication-grid";
import { Button } from "./ui/button";
import { PublicationGrid } from "../publication-grid";
import { Button } from "../ui/button";

export function InfiniteScroll(): ReactNode {
const t = useTranslations("InstantSearch");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import TypesenseInstantSearchAdapter, { type SearchClient } from "typesense-inst
import { env } from "@/config/env.config";
import { collectionName } from "@/lib/data";

interface InstantSearchProps {
interface InstantSearchProviderProps {
queryArgsToMenuFields: Record<string, string>;
children?: ReactNode;
filters?: string;
Expand All @@ -36,7 +36,7 @@ const searchClient = typesenseInstantsearchAdapter.searchClient as unknown as Se

type RouteState = Record<string, string | undefined>;

export function InstantSearch(props: InstantSearchProps): ReactNode {
export function InstantSearchProvider(props: InstantSearchProviderProps): ReactNode {
const { children, filters, queryArgsToMenuFields } = props;
const filter = filters
? // '&&' is typesense convention, not instantsearch!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Hits } from "react-instantsearch";

import type { Publication } from "@/lib/model";

import { InlineList } from "./inline-list";
import { ClickablePublicationThumbnail } from "./publication-cover";
import { PublicationLink } from "./publication-link";
import { InlineList } from "../inline-list";
import { ClickablePublicationThumbnail } from "../publication-cover";
import { PublicationLink } from "../publication-link";

function TableRow({ hit }: { hit: Hit<Publication> }) {
const lt = useTranslations("Languages");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useSortBy } from "react-instantsearch";

import { collectionName } from "@/lib/data";

import { Select, SelectContent, SelectItem, SelectPopover, SelectTrigger } from "./ui/select";
import { Select, SelectContent, SelectItem, SelectPopover, SelectTrigger } from "../ui/select";

interface InstantSearchSortByProps {
sortOptions: Array<string>;
Expand Down
File renamed without changes.

0 comments on commit 29a3aa4

Please sign in to comment.