diff --git a/packages/docusaurus-plugin-content-showcase/src/client/index.ts b/packages/docusaurus-plugin-content-showcase/src/client/index.ts index 4abb6a86fa..065578ba69 100644 --- a/packages/docusaurus-plugin-content-showcase/src/client/index.ts +++ b/packages/docusaurus-plugin-content-showcase/src/client/index.ts @@ -11,6 +11,7 @@ import { usePluralForm, useQueryString, useQueryStringList, + type ListUpdateFunction, } from '@docusaurus/theme-common'; import type { TagType, @@ -51,25 +52,28 @@ export function filterUsers({ }); } -export function useSearchName(): string | undefined { - return useQueryString('name')[0]; +export function useSearchName(): [ + string, + (newValue: string | null, options?: {push: boolean}) => void, +] { + return useQueryString('name'); } -export function useTags() { +export function useTags(): [string[], ListUpdateFunction] { return useQueryStringList('tags'); } -export function useOperator() { +export function useOperator(): [Operator, () => void] { const [searchOperator, setSearchOperator] = useQueryString('operator'); const operator: Operator = searchOperator === 'AND' ? 'AND' : 'OR'; const toggleOperator = useCallback(() => { const newOperator = operator === 'OR' ? 'AND' : null; setSearchOperator(newOperator); }, [operator, setSearchOperator]); - return [operator, toggleOperator] as const; + return [operator, toggleOperator]; } -export function useFilteredUsers(users: ShowcaseItem[]) { +export function useFilteredUsers(users: ShowcaseItem[]): ShowcaseItem[] { const [tags] = useTags(); const [searchName] = useSearchName() ?? ['']; const [operator] = useOperator(); @@ -85,7 +89,7 @@ export function useFilteredUsers(users: ShowcaseItem[]) { ); } -export function useSiteCountPlural() { +export function useSiteCountPlural(): (sitesCount: number) => string { const {selectMessage} = usePluralForm(); return (sitesCount: number) => selectMessage( diff --git a/packages/docusaurus-plugin-content-showcase/src/plugin-content-showcase.d.ts b/packages/docusaurus-plugin-content-showcase/src/plugin-content-showcase.d.ts index d307e56238..703031d06d 100644 --- a/packages/docusaurus-plugin-content-showcase/src/plugin-content-showcase.d.ts +++ b/packages/docusaurus-plugin-content-showcase/src/plugin-content-showcase.d.ts @@ -50,7 +50,7 @@ declare module '@docusaurus/plugin-content-showcase' { readonly preview: string | null; // null = use our serverless screenshot service readonly website: string; readonly source: string | null; - readonly tags: string[]; + readonly tags: TagType[]; }; export type ShowcaseItems = { diff --git a/packages/docusaurus-theme-classic/src/theme/Showcase/ShowcaseSearchBar/index.tsx b/packages/docusaurus-theme-classic/src/theme/Showcase/ShowcaseSearchBar/index.tsx index 15e6476530..db55fc63ec 100644 --- a/packages/docusaurus-theme-classic/src/theme/Showcase/ShowcaseSearchBar/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Showcase/ShowcaseSearchBar/index.tsx @@ -21,7 +21,6 @@ export default function ShowcaseSearchBar(): ReactNode { })} value={searchName} onInput={(e) => { - // TODO fix typescript error ? setSearchName(e.currentTarget.value); }} /> diff --git a/packages/docusaurus-theme-classic/src/theme/Showcase/_utils.tsx b/packages/docusaurus-theme-classic/src/theme/Showcase/_utils.tsx deleted file mode 100644 index b5c0e33b4a..0000000000 --- a/packages/docusaurus-theme-classic/src/theme/Showcase/_utils.tsx +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ diff --git a/packages/docusaurus-theme-common/src/index.ts b/packages/docusaurus-theme-common/src/index.ts index 6859089b5a..bc08100ce2 100644 --- a/packages/docusaurus-theme-common/src/index.ts +++ b/packages/docusaurus-theme-common/src/index.ts @@ -103,6 +103,7 @@ export { useQueryString, useQueryStringList, useClearQueryString, + type ListUpdateFunction, } from './utils/historyUtils'; export { diff --git a/packages/docusaurus-theme-common/src/utils/historyUtils.ts b/packages/docusaurus-theme-common/src/utils/historyUtils.ts index 4695896a1e..108d79cb0d 100644 --- a/packages/docusaurus-theme-common/src/utils/historyUtils.ts +++ b/packages/docusaurus-theme-common/src/utils/historyUtils.ts @@ -115,7 +115,7 @@ function useQueryStringListValues(key: string): string[] { } type ListUpdate = string[] | ((oldValues: string[]) => string[]); -type ListUpdateFunction = ( +export type ListUpdateFunction = ( update: ListUpdate, options?: {push: boolean}, ) => void;