From d31e3788a74d959928f4faef801f53ea32c818be Mon Sep 17 00:00:00 2001 From: Ciprian Platica Date: Mon, 23 Nov 2020 13:01:08 +0200 Subject: [PATCH] Use scope instead of hardcoded params for get candidates --- src/stories/APIIntegration.stories.tsx | 4 +++- src/util/electionApi.ts | 10 +++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/stories/APIIntegration.stories.tsx b/src/stories/APIIntegration.stories.tsx index 1519042..a6df384 100644 --- a/src/stories/APIIntegration.stories.tsx +++ b/src/stories/APIIntegration.stories.tsx @@ -124,7 +124,9 @@ ElectionScopeComponent.argTypes = { export const ElectionCandidatesComponent = (args: { api: string; apiUrl: string }) => { const electionApi: ElectionAPI = useApi(args.api, args.apiUrl); - const { data, loading, error } = useApiResponse(() => electionApi.getCandidates(1, "county", 1), [electionApi]); + const { data, loading, error } = useApiResponse(() => electionApi.getCandidates(1, { type: "county", countyId: 1 }), [ + electionApi, + ]); return ( <> diff --git a/src/util/electionApi.ts b/src/util/electionApi.ts index 5865207..04d9656 100644 --- a/src/util/electionApi.ts +++ b/src/util/electionApi.ts @@ -26,11 +26,7 @@ export interface ElectionAPI extends ElectionScopeAPI, ElectionMapAPI { getBallot: (id: number, scope: ElectionScope) => APIInvocation; getBallots: () => APIInvocation; getNewsFeed: (id: number) => APIInvocation; - getCandidates: ( - ballotId: number, - division: string, - countyId: number | null, - ) => APIInvocation; + getCandidates: (ballotId: number, scope: ElectionScope) => APIInvocation; } const scopeToQuery = (scope: ElectionScope) => { @@ -77,7 +73,7 @@ export const makeElectionApi = (options?: { return fetch("GET", "/winners/countries", { query: { BallotId: ballotId } }); } }, - getCandidates: (ballotId: number, division: string, countyId: number | null) => - fetch("GET", `/ballots/${ballotId}/candidates`, { query: { Division: division, CountyId: countyId } }), + getCandidates: (ballotId: number, scope: ElectionScope) => + fetch("GET", `/ballots/${ballotId}/candidates`, { query: scopeToQuery(scope) }), }; };