fix type error

This commit is contained in:
ozakione 2024-04-16 16:38:03 +02:00
parent c0c0f83f2d
commit 7b76e46277
6 changed files with 14 additions and 16 deletions

View file

@ -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(

View file

@ -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 = {

View file

@ -21,7 +21,6 @@ export default function ShowcaseSearchBar(): ReactNode {
})}
value={searchName}
onInput={(e) => {
// TODO fix typescript error ?
setSearchName(e.currentTarget.value);
}}
/>

View file

@ -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.
*/

View file

@ -103,6 +103,7 @@ export {
useQueryString,
useQueryStringList,
useClearQueryString,
type ListUpdateFunction,
} from './utils/historyUtils';
export {

View file

@ -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;