perf: speed up search

This commit is contained in:
rusconn
2023-05-24 13:17:20 +00:00
parent f1c3bd2971
commit 0cf5774e16
5 changed files with 48 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
import "@/styles/globals.css";
import { Metadata } from "next";
import { SearchTextProvider } from "@/contexts/search-text";
import { siteConfig } from "@/config/site";
import { fontMono, fontSans } from "@/lib/fonts";
@@ -44,16 +45,18 @@ export default function RootLayout({ children }: RootLayoutProps) {
)}
>
<ThemeProvider attribute="class" defaultTheme="system" disableTransitionOnChange>
<div className="relative flex h-full flex-col">
<SiteHeader />
<div className="flex flex-1 overflow-y-hidden">
<Sidebar />
<main className="h-full flex-1 overflow-y-auto rounded-tl-md border bg-page p-12">
{children}
</main>
<SearchTextProvider>
<div className="relative flex h-full flex-col">
<SiteHeader />
<div className="flex flex-1 overflow-y-hidden">
<Sidebar />
<main className="h-full flex-1 overflow-y-auto rounded-tl-md border bg-page p-12">
{children}
</main>
</div>
</div>
</div>
<TailwindIndicator />
<TailwindIndicator />
</SearchTextProvider>
</ThemeProvider>
</body>
</html>

View File

@@ -1,6 +1,6 @@
"use client";
import { useSearchParams } from "next/navigation";
import { useSearchText } from "@/contexts/search-text";
import Fuse from "fuse.js";
import { homeTools } from "@/config/tools";
@@ -8,9 +8,8 @@ import { PageRootSection } from "@/components/page-root-section";
import { ToolCards } from "@/components/tool-cards";
export default function Page() {
const params = useSearchParams();
const q = params.get("q")?.trim() ?? "";
// use search params in context
const q = useSearchText();
const fuse = new Fuse(homeTools, { keys: ["keywords"], threshold: 0.45 });
const keyWordsOptions = q.split(" ").map(word => ({ keywords: word }));