mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-06 04:42:40 +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,
|
usePluralForm,
|
||||||
useQueryString,
|
useQueryString,
|
||||||
useQueryStringList,
|
useQueryStringList,
|
||||||
|
type ListUpdateFunction,
|
||||||
} from '@docusaurus/theme-common';
|
} from '@docusaurus/theme-common';
|
||||||
import type {
|
import type {
|
||||||
TagType,
|
TagType,
|
||||||
|
@ -51,25 +52,28 @@ export function filterUsers({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSearchName(): string | undefined {
|
export function useSearchName(): [
|
||||||
return useQueryString('name')[0];
|
string,
|
||||||
|
(newValue: string | null, options?: {push: boolean}) => void,
|
||||||
|
] {
|
||||||
|
return useQueryString('name');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useTags() {
|
export function useTags(): [string[], ListUpdateFunction] {
|
||||||
return useQueryStringList('tags');
|
return useQueryStringList('tags');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useOperator() {
|
export function useOperator(): [Operator, () => void] {
|
||||||
const [searchOperator, setSearchOperator] = useQueryString('operator');
|
const [searchOperator, setSearchOperator] = useQueryString('operator');
|
||||||
const operator: Operator = searchOperator === 'AND' ? 'AND' : 'OR';
|
const operator: Operator = searchOperator === 'AND' ? 'AND' : 'OR';
|
||||||
const toggleOperator = useCallback(() => {
|
const toggleOperator = useCallback(() => {
|
||||||
const newOperator = operator === 'OR' ? 'AND' : null;
|
const newOperator = operator === 'OR' ? 'AND' : null;
|
||||||
setSearchOperator(newOperator);
|
setSearchOperator(newOperator);
|
||||||
}, [operator, setSearchOperator]);
|
}, [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 [tags] = useTags();
|
||||||
const [searchName] = useSearchName() ?? [''];
|
const [searchName] = useSearchName() ?? [''];
|
||||||
const [operator] = useOperator();
|
const [operator] = useOperator();
|
||||||
|
@ -85,7 +89,7 @@ export function useFilteredUsers(users: ShowcaseItem[]) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSiteCountPlural() {
|
export function useSiteCountPlural(): (sitesCount: number) => string {
|
||||||
const {selectMessage} = usePluralForm();
|
const {selectMessage} = usePluralForm();
|
||||||
return (sitesCount: number) =>
|
return (sitesCount: number) =>
|
||||||
selectMessage(
|
selectMessage(
|
||||||
|
|
|
@ -50,7 +50,7 @@ declare module '@docusaurus/plugin-content-showcase' {
|
||||||
readonly preview: string | null; // null = use our serverless screenshot service
|
readonly preview: string | null; // null = use our serverless screenshot service
|
||||||
readonly website: string;
|
readonly website: string;
|
||||||
readonly source: string | null;
|
readonly source: string | null;
|
||||||
readonly tags: string[];
|
readonly tags: TagType[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ShowcaseItems = {
|
export type ShowcaseItems = {
|
||||||
|
|
|
@ -21,7 +21,6 @@ export default function ShowcaseSearchBar(): ReactNode {
|
||||||
})}
|
})}
|
||||||
value={searchName}
|
value={searchName}
|
||||||
onInput={(e) => {
|
onInput={(e) => {
|
||||||
// TODO fix typescript error ?
|
|
||||||
setSearchName(e.currentTarget.value);
|
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,
|
useQueryString,
|
||||||
useQueryStringList,
|
useQueryStringList,
|
||||||
useClearQueryString,
|
useClearQueryString,
|
||||||
|
type ListUpdateFunction,
|
||||||
} from './utils/historyUtils';
|
} from './utils/historyUtils';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
|
@ -115,7 +115,7 @@ function useQueryStringListValues(key: string): string[] {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListUpdate = string[] | ((oldValues: string[]) => string[]);
|
type ListUpdate = string[] | ((oldValues: string[]) => string[]);
|
||||||
type ListUpdateFunction = (
|
export type ListUpdateFunction = (
|
||||||
update: ListUpdate,
|
update: ListUpdate,
|
||||||
options?: {push: boolean},
|
options?: {push: boolean},
|
||||||
) => void;
|
) => void;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue