From 7a3ea0766831deddb1d3f65af8f3bc9bb273b70f Mon Sep 17 00:00:00 2001 From: alcercu <333aleix333@gmail.com> Date: Fri, 15 Sep 2023 18:35:21 +0200 Subject: [PATCH] refactor(web): move totalAppealingDisputes to useUser query --- .../hooks/queries/useMyCasesCounterQuery.ts | 32 ------------------- web/src/hooks/queries/useUser.ts | 1 + web/src/pages/Dashboard/index.tsx | 5 +-- 3 files changed, 2 insertions(+), 36 deletions(-) delete mode 100644 web/src/hooks/queries/useMyCasesCounterQuery.ts diff --git a/web/src/hooks/queries/useMyCasesCounterQuery.ts b/web/src/hooks/queries/useMyCasesCounterQuery.ts deleted file mode 100644 index c12ba1324..000000000 --- a/web/src/hooks/queries/useMyCasesCounterQuery.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { graphql } from "src/graphql"; -import { Address } from "viem"; -import { useQuery } from "@tanstack/react-query"; -import { MyCasesCounterQuery, Dispute_Filter } from "src/graphql/graphql"; -import { graphqlQueryFnHelper } from "utils/graphqlQueryFnHelper"; -import { isUndefined } from "utils/index"; -export type { MyCasesCounterQuery }; - -const myCasesCounter = graphql(` - query MyCasesCounter($id: ID!, $where: Dispute_filter) { - user(id: $id) { - totalAppealingDisputes - disputes(orderBy: lastPeriodChange, where: $where) { - id - } - } - } -`); - -export const useMyCasesCounterQuery = (user?: Address, where?: Dispute_Filter) => { - const isEnabled = !isUndefined(user); - - return useQuery({ - queryKey: [`useMyCasesCounterQuery`, user], - enabled: isEnabled, - queryFn: async () => - await graphqlQueryFnHelper(myCasesCounter, { - id: user?.toLowerCase(), - where, - }), - }); -}; diff --git a/web/src/hooks/queries/useUser.ts b/web/src/hooks/queries/useUser.ts index c49eefab0..10f68859c 100644 --- a/web/src/hooks/queries/useUser.ts +++ b/web/src/hooks/queries/useUser.ts @@ -10,6 +10,7 @@ const userQuery = graphql(` user(id: $address) { totalDisputes totalResolvedDisputes + totalAppealingDisputes totalCoherent tokens { court { diff --git a/web/src/pages/Dashboard/index.tsx b/web/src/pages/Dashboard/index.tsx index 9043a0dc8..506b1956b 100644 --- a/web/src/pages/Dashboard/index.tsx +++ b/web/src/pages/Dashboard/index.tsx @@ -3,7 +3,6 @@ import styled from "styled-components"; import { useAccount } from "wagmi"; import { DisputeDetailsFragment, useMyCasesQuery } from "queries/useCasesQuery"; import { useFiltersContext } from "context/FilterProvider"; -import { useMyCasesCounterQuery } from "queries/useMyCasesCounterQuery"; import { useUserQuery, UserQuery } from "queries/useUser"; import { OrderDirection } from "src/graphql/graphql"; import JurorInfo from "./JurorInfo"; @@ -63,12 +62,10 @@ const Dashboard: React.FC = () => { const disputeSkip = debouncedSearch ? 0 : 3 * (currentPage - 1); const direction = timeFilter === 0 ? OrderDirection.Desc : OrderDirection.Asc; const courtChoice = courtFilter === 0 ? {} : { court: courtFilter.toString() }; - const { data: userAppealCases } = useMyCasesCounterQuery(address, { ...courtChoice }); - const userAppealCasesNumber = userAppealCases?.user?.totalAppealingDisputes; const queryFilters = { ...combinedQueryFilters, ...courtChoice }; const { data: disputesData } = useMyCasesQuery(address, disputeSkip, queryFilters, direction); const { data: userData } = useUserQuery(address); - const totalPages = calculatePages(statusFilter, userData, casesPerPage, userAppealCasesNumber); + const totalPages = calculatePages(statusFilter, userData, casesPerPage, userData?.user?.totalAppealingDisputes); useEffect(() => { setCurrentPage(1);