sendou.ink/app/hooks/swr.ts
Kalle fd7d1ea2dc
User search (#1468)
* Initial

* Search users from API

* Better feeling search

* Fix TODO

* Search via url, discord id & id

* Load initial user

* UserSearch on admin page

* UserSearch on tournaments page

* UserSearch for badges

* Plus suggestions

* Vod page

* Remove unused code

* Fix test
2023-08-26 22:10:01 +03:00

45 lines
1.1 KiB
TypeScript

import useSWRImmutable from "swr/immutable";
import type { WeaponUsageLoaderData } from "~/features/sendouq/routes/weapon-usage";
import type { ModeShort, StageId } from "~/modules/in-game-lists";
import type { EventsWithMapPoolsLoaderData } from "~/routes/calendar/map-pool-events";
import {
GET_ALL_EVENTS_WITH_MAP_POOLS_ROUTE,
getWeaponUsage,
} from "~/utils/urls";
const fetcher = async (url: string) => {
const res = await fetch(url);
return res.json();
};
export function useAllEventsWithMapPools() {
const { data, error } = useSWRImmutable<EventsWithMapPoolsLoaderData>(
GET_ALL_EVENTS_WITH_MAP_POOLS_ROUTE,
fetcher
);
return {
events: data?.events,
isLoading: !error && !data,
isError: error,
};
}
export function useWeaponUsage(args: {
userId: number;
season: number;
modeShort: ModeShort;
stageId: StageId;
}) {
const { data, error } = useSWRImmutable<WeaponUsageLoaderData>(
getWeaponUsage(args),
fetcher
);
return {
weaponUsage: data?.usage,
isLoading: !error && !data,
isError: error,
};
}