Skip to content

Commit

Permalink
Use scope instead of hardcoded params for get candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
cipick committed Nov 23, 2020
1 parent 6791601 commit d31e378
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/stories/APIIntegration.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand Down
10 changes: 3 additions & 7 deletions src/util/electionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ export interface ElectionAPI extends ElectionScopeAPI, ElectionMapAPI {
getBallot: (id: number, scope: ElectionScope) => APIInvocation<ElectionBallot>;
getBallots: () => APIInvocation<ElectionBallotMeta[]>;
getNewsFeed: (id: number) => APIInvocation<ElectionNewsFeed>;
getCandidates: (
ballotId: number,
division: string,
countyId: number | null,
) => APIInvocation<ElectionResultsPartyCandidates[]>;
getCandidates: (ballotId: number, scope: ElectionScope) => APIInvocation<ElectionResultsPartyCandidates[]>;
}

const scopeToQuery = (scope: ElectionScope) => {
Expand Down Expand Up @@ -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) }),
};
};

0 comments on commit d31e378

Please sign in to comment.