mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-07 05:12:31 +02:00
fix type error
This commit is contained in:
parent
c0c0f83f2d
commit
7b76e46277
6 changed files with 14 additions and 16 deletions
|
@ -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(
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -21,7 +21,6 @@ export default function ShowcaseSearchBar(): ReactNode {
|
|||
})}
|
||||
value={searchName}
|
||||
onInput={(e) => {
|
||||
// TODO fix typescript error ?
|
||||
setSearchName(e.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
|
|
|
@ -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.
|
||||
*/
|
|
@ -103,6 +103,7 @@ export {
|
|||
useQueryString,
|
||||
useQueryStringList,
|
||||
useClearQueryString,
|
||||
type ListUpdateFunction,
|
||||
} from './utils/historyUtils';
|
||||
|
||||
export {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue