Skip to content

Commit

Permalink
Actually just add the state locking feature now
Browse files Browse the repository at this point in the history
  • Loading branch information
oyamauchi committed Sep 28, 2023
1 parent d5a64f7 commit dbe35ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/rhode-island.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<h1>Rewiring America Incentives Calculator</h1>
<rewiring-america-state-calculator
api-key="{{ apiKey }}"
state="RI"
household-income="80000"
household-size="1"
tax-filing="single"
Expand Down
29 changes: 23 additions & 6 deletions src/state-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,28 @@ export class RewiringAmericaStateCalculator extends LitElement {
query.set('utility', this.utility);
}

return await fetchApi<APIResponse>(
const response = await fetchApi<APIResponse>(
this.apiKey,
this.apiHost,
'/api/v1/calculator',
query,
);

// If the "state" attribute is set, enforce that some other state's
// incentives aren't shown. But if coverage.state is null, we won't show
// the error: we'll only be showing federal incentives in that case.
if (
this.state &&
response.coverage.state &&
response.coverage.state !== this.state
) {
// Throw to put the task into the ERROR state for rendering.
throw new Error(
`That ZIP code is not in ${STATES[this.state]?.name ?? this.state}.`,
);
}

return response;
},
onComplete: () => {
this.tempState = null;
Expand Down Expand Up @@ -252,6 +268,10 @@ export class RewiringAmericaStateCalculator extends LitElement {
// - The loading spinner, if either utilities or incentives are still
// loading.

const showLoading =
this._utilitiesTask.status === TaskStatus.PENDING ||
this._task.status === TaskStatus.PENDING;

return html`
<div class="calculator">
<div class="card card-content">
Expand Down Expand Up @@ -305,11 +325,8 @@ export class RewiringAmericaStateCalculator extends LitElement {
),
]
: nothing}
${this._utilitiesTask.status === TaskStatus.PENDING ||
this._task.status === TaskStatus.PENDING
? loadingTemplate()
: nothing}
${this._task.status === TaskStatus.ERROR
${showLoading ? loadingTemplate() : nothing}
${this._task.status === TaskStatus.ERROR && !showLoading
? errorTemplate(this._task.error)
: nothing}
${CALCULATOR_FOOTER}
Expand Down

0 comments on commit dbe35ec

Please sign in to comment.