From 7afdff241f01b2f71c3a87963c9a6cbed2cd949c Mon Sep 17 00:00:00 2001 From: Vordgi Date: Wed, 16 Oct 2024 22:13:48 +0400 Subject: [PATCH] rd-332 add search results type --- docs/03-customization/03-search.md | 7 +++---- .../src/components/blocks/search/search-modal/index.tsx | 4 ++-- packages/robindoc/src/core/types/search.ts | 2 ++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/03-customization/03-search.md b/docs/03-customization/03-search.md index 1affbb84..6c8e4387 100644 --- a/docs/03-customization/03-search.md +++ b/docs/03-customization/03-search.md @@ -32,10 +32,9 @@ If you prefer to handle search logic entirely on the client side, you can provid Here’s an example callback function: ```ts filename="utils/searcher.ts" -const searcher = async ( - search: string, - abortController: AbortController -): { href: string; content: string; title: string }[] => { +import { type Searcher } from "robindoc/lib/core/types/search"; + +const searcher: Searcher = async (search, abortController) => { const results = await advancedSearcher(pagesData, search, abortController); return results; }; diff --git a/packages/robindoc/src/components/blocks/search/search-modal/index.tsx b/packages/robindoc/src/components/blocks/search/search-modal/index.tsx index 2640a10f..af023141 100644 --- a/packages/robindoc/src/components/blocks/search/search-modal/index.tsx +++ b/packages/robindoc/src/components/blocks/search/search-modal/index.tsx @@ -2,7 +2,7 @@ import React, { useEffect, useMemo, useRef, useState } from "react"; -import { type Searcher, type SearchItem } from "@src/core/types/search"; +import { type Searcher, type SearchResults } from "@src/core/types/search"; import { createBaseSearcher } from "@src/core/utils/create-base-searcher"; import { NavLink } from "@src/components/blocks/nav-link"; import { useDebouncer } from "@src/core/hooks/use-debouncer"; @@ -25,7 +25,7 @@ export interface SearchModalProps { export const SearchModal: React.FC = ({ translations, searcher, open, onClose, onInput }) => { const { typeSomething = "Type something...", nothingFound = "Nothing found" } = translations || {}; const inputRef = useRef(null); - const [results, setResults] = useState(null); + const [results, setResults] = useState(null); const targetSearcher = useMemo( () => (typeof searcher === "string" ? createBaseSearcher(searcher) : searcher), [searcher], diff --git a/packages/robindoc/src/core/types/search.ts b/packages/robindoc/src/core/types/search.ts index c169c672..5360c6fc 100644 --- a/packages/robindoc/src/core/types/search.ts +++ b/packages/robindoc/src/core/types/search.ts @@ -1,3 +1,5 @@ export type SearchItem = { title: string; href: string; description?: string }; +export type SearchResults = SearchItem[]; + export type Searcher = (search: string, abortController: AbortController) => Promise;