Skip to content

Commit

Permalink
Merge pull request #101 from cipick/feature/fix-get-candidates-types
Browse files Browse the repository at this point in the history
Fix get candidates params types
  • Loading branch information
RaduCStefanescu authored Nov 23, 2020
2 parents 67d7f43 + d31e378 commit 5425b1a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@code4ro/reusable-components",
"version": "0.1.51",
"version": "0.1.52",
"description": "Component library for code4ro",
"keywords": [
"code4ro",
Expand Down
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, 1, 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: number,
countyId: number,
) => 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: number, countyId: number) =>
fetch("GET", `/ballots/${ballotId}/candidates`, { query: { division: division, countyId: countyId } }),
getCandidates: (ballotId: number, scope: ElectionScope) =>
fetch("GET", `/ballots/${ballotId}/candidates`, { query: scopeToQuery(scope) }),
};
};
2 changes: 1 addition & 1 deletion src/util/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2399,7 +2399,7 @@ export const mockElectionAPI = makeElectionApi({

[
"GET",
"/ballots/*/candidates",
"/ballots/1/candidates",
(async () => {
await delay(1000);
return mockCandidatesList;
Expand Down

1 comment on commit 5425b1a

@vercel
Copy link

@vercel vercel bot commented on 5425b1a Nov 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.