Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 4x 4x 4x 36x 36x 24x 24x 36x | import {
InfiniteData,
useInfiniteQuery,
useQuery,
} from "@tanstack/react-query";
import { badgesKey, badgeUsersKey } from "features/queryKeys";
import { RpcError } from "grpc-web";
import { ListBadgeUsersRes } from "proto/api_pb";
import { Badge } from "proto/resources_pb";
import { service } from "service";
export const useBadges = () => {
const { data, ...rest } = useQuery({
queryKey: [badgesKey],
queryFn: async () => {
const result = await service.resources.getBadges();
return result.badgesList.reduce(
(badgesResult, badge) => {
badgesResult.badges[badge.id] = badge;
return badgesResult;
},
{
badges: {} as { [id: string]: Badge.AsObject },
},
);
},
});
return {
badges: data?.badges,
...rest,
};
};
export function useBadgeUsers(badgeId: string) {
const query = useInfiniteQuery<
ListBadgeUsersRes.AsObject,
RpcError,
InfiniteData<ListBadgeUsersRes.AsObject>,
string[],
string
>({
queryKey: badgeUsersKey({ badgeId }),
queryFn: ({ pageParam }) =>
service.api.listBadgeUsers({ badgeId, pageToken: pageParam }),
initialPageParam: "0",
getNextPageParam: (lastPage) => lastPage.nextPageToken || undefined,
});
const badgeUserIds = query.data?.pages.flatMap((res) => res.userIdsList);
return {
...query,
badgeUserIds,
};
}
|