mirror of
https://github.com/ershisan99/DevToysWeb.git
synced 2025-12-16 20:49:23 +00:00
perf: speed up search
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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 }));
|
||||
|
||||
Reference in New Issue
Block a user