-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathuseTopUsersByCoherenceScore.ts
45 lines (40 loc) · 1.38 KB
/
useTopUsersByCoherenceScore.ts
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
import { useQuery } from "@tanstack/react-query";
import { useGraphqlBatcher } from "context/GraphqlBatcher";
import { DEFAULT_CHAIN } from "consts/chains";
import { isUndefined } from "utils/index";
import { graphql } from "src/graphql";
import { TopUsersByCoherenceScoreQuery } from "src/graphql/graphql";
export type { TopUsersByCoherenceScoreQuery };
const topUsersByCoherenceScoreQuery = graphql(`
query TopUsersByCoherenceScore($first: Int!, $orderBy: User_orderBy, $orderDirection: OrderDirection) {
users(first: $first, orderBy: $orderBy, orderDirection: $orderDirection) {
id
coherenceScore
totalCoherentVotes
totalResolvedVotes
totalResolvedDisputes
}
}
`);
export const useTopUsersByCoherenceScore = (first = 5) => {
const isEnabled = !isUndefined(first);
const { graphqlBatcher } = useGraphqlBatcher();
return useQuery<TopUsersByCoherenceScoreQuery>({
queryKey: [`TopUsersByCoherenceScore${first}`],
enabled: isEnabled,
staleTime: Infinity,
queryFn: async () =>
isEnabled
? await graphqlBatcher.fetch({
id: crypto.randomUUID(),
document: topUsersByCoherenceScoreQuery,
chainId: DEFAULT_CHAIN,
variables: {
first: first,
orderBy: "coherenceScore",
orderDirection: "desc",
},
})
: undefined,
});
};