Skip to content

Commit

Permalink
Feature/store values to session (#24)
Browse files Browse the repository at this point in the history
* store data to session storage, thanks chatgpt

* change gross to undefined

* define all values to undefined
  • Loading branch information
zcarroll4 authored Dec 21, 2024
1 parent 5ac58ba commit 9c683e6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1>2024 Tax Estimator Calculator</h1>
<h3>Tax Year</h3>
</div>
<div class="col">
<select class="form-select w-75 m-auto text-center" [disabled]="taxesCalculated" [(ngModel)]="tax_year">
<select class="form-select w-75 m-auto text-center" [disabled]="taxesCalculated" [(ngModel)]="tax_year" (ngModelChange)="saveToSessionStorage()">
<option sel>2024</option>
<option>2023</option>
<option>2022</option>
Expand All @@ -26,7 +26,7 @@ <h3>Filing Status</h3>
</div>
<div class="col">
<select class="form-select w-75 m-auto text-center" [disabled]="taxesCalculated"
[(ngModel)]="filing_status">
[(ngModel)]="filing_status" (ngModelChange)="saveToSessionStorage()">
<option>Single</option>
<option>Married Filing Jointly</option>
<option>Married Filing Separately</option>
Expand All @@ -38,15 +38,15 @@ <h3>Filing Status</h3>
<h3>Gross Income</h3>
</div>
<div class="col"><input type="tel" [disabled]="taxesCalculated" step="1000"
class="text-center w-75 m-auto form-control" [(ngModel)]="gross_income" />
class="text-center w-75 m-auto form-control" [(ngModel)]="gross_income" (ngModelChange)="saveToSessionStorage()"/>
</div>
</div>
<div class="row my-1">
<div class="col-7">
<h3>State</h3>
</div>
<div class="col">
<select class="form-select w-75 m-auto text-center" [disabled]="true" [(ngModel)]="filing_state">
<select class="form-select w-75 m-auto text-center" [disabled]="true" [(ngModel)]="filing_state" (ngModelChange)="saveToSessionStorage()">
<option>WV</option>
</select>
</div>
Expand All @@ -59,7 +59,7 @@ <h3>Self Employment Income</h3>
<button *ngIf="!hasSelfEmploymentIncome" [disabled]="taxesCalculated" class="btn btn-success w-50"
(click)="toggleSelfEmploymentIncome()">Add</button>
<input *ngIf="hasSelfEmploymentIncome" type="tel" [disabled]="taxesCalculated" step="1000"
class="text-center w-75 m-auto form-control" [(ngModel)]="self_employment_income" />
class="text-center w-75 m-auto form-control" [(ngModel)]="self_employment_income" (ngModelChange)="saveToSessionStorage()"/>
</div>
</div>
<div class="row my-1">
Expand All @@ -70,7 +70,7 @@ <h3>401K (Traditional)</h3>
<button *ngIf="!hasRetirementContributions" [disabled]="taxesCalculated" class="btn btn-success w-50"
(click)="toggleRetirementContributions()">Add</button>
<input *ngIf="hasRetirementContributions" type="tel" [disabled]="taxesCalculated" step="1000"
class="text-center w-75 m-auto form-control" [(ngModel)]="traditional_retirement_contributions" />
class="text-center w-75 m-auto form-control" [(ngModel)]="traditional_retirement_contributions" (ngModelChange)="saveToSessionStorage()" />
</div>
</div>
<div class="row my-1">
Expand All @@ -81,7 +81,7 @@ <h3>401K (Roth)</h3>
<button *ngIf="!hasRetirementRothContributions" [disabled]="taxesCalculated" class="btn btn-success w-50"
(click)="toggleRetirementRothContributions()">Add</button>
<input *ngIf="hasRetirementRothContributions" type="tel" [disabled]="taxesCalculated" step="1000"
class="text-center w-75 m-auto form-control" [(ngModel)]="roth_retirement_contributions" />
class="text-center w-75 m-auto form-control" [(ngModel)]="roth_retirement_contributions" (ngModelChange)="saveToSessionStorage()"/>
</div>
</div>
<div class="row my-1">
Expand All @@ -92,7 +92,7 @@ <h3>HSA Contributions</h3>
<button *ngIf="!hasHSAContributions" [disabled]="taxesCalculated" class="btn btn-success w-50"
(click)="toggleHSAContributions()">Add</button>
<input *ngIf="hasHSAContributions" type="tel" [disabled]="taxesCalculated" step="1000"
class="text-center w-75 m-auto form-control" [(ngModel)]="hsa_contributions" />
class="text-center w-75 m-auto form-control" [(ngModel)]="hsa_contributions" (ngModelChange)="saveToSessionStorage()"/>
</div>
</div>
<div class="row my-1">
Expand All @@ -104,7 +104,7 @@ <h3>Insurance Premiums</h3>
<button *ngIf="!hasInsurancePremiums" [disabled]="taxesCalculated" class="btn btn-success w-50"
(click)="toggleInsurancePremiums()">Add</button>
<input *ngIf="hasInsurancePremiums" type="tel" [disabled]="taxesCalculated" step="1000"
class="text-center w-75 m-auto form-control" [(ngModel)]="insurance_premiums" />
class="text-center w-75 m-auto form-control" [(ngModel)]="insurance_premiums" (ngModelChange)="saveToSessionStorage()"/>
</div>
</div>
</div>
Expand Down
30 changes: 28 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,36 @@ export class AppComponent implements OnInit {
constructor() { }

ngOnInit(): void {
this.filing_state = 'WV';
this.tax_year = 2024;
this.filing_state = sessionStorage.getItem('filing_state') || 'WV'; // default to 'WV' if not found
this.filing_status = sessionStorage.getItem('filing_status') || '';
this.tax_year = +(sessionStorage.getItem('tax_year')??0) || 2024; // default to 2024 if not found
this.gross_income = +(sessionStorage.getItem('gross_income')??0) || undefined;
this.self_employment_income = +(sessionStorage.getItem('self_employment_income')??0) || undefined;
this.traditional_retirement_contributions = +(sessionStorage.getItem('traditional_retirement_contributions')??0) || undefined;
this.roth_retirement_contributions = +(sessionStorage.getItem('roth_retirement_contributions')??0) || undefined;
this.hsa_contributions = +(sessionStorage.getItem('hsa_contributions')??0) || undefined;
this.insurance_premiums = +(sessionStorage.getItem('insurance_premiums')??0) || undefined;
}

saveToSessionStorage() {
// Save all relevant data to sessionStorage
sessionStorage.setItem('filing_state', this.filing_state || '');
sessionStorage.setItem('filing_status', this.filing_status || '');
sessionStorage.setItem('tax_year', this.tax_year?.toString() || '');
sessionStorage.setItem('gross_income', this.gross_income?.toString() || '');
sessionStorage.setItem('self_employment_income', this.self_employment_income?.toString() || '');
sessionStorage.setItem('traditional_retirement_contributions', this.traditional_retirement_contributions?.toString() || '');
sessionStorage.setItem('roth_retirement_contributions', this.roth_retirement_contributions?.toString() || '');
sessionStorage.setItem('hsa_contributions', this.hsa_contributions?.toString() || '');
sessionStorage.setItem('insurance_premiums', this.insurance_premiums?.toString() || '');
}

clearSessionStorage() {
// Clear all sessionStorage data
sessionStorage.clear();
}


updateStandardDeduction() {
if (this.tax_year == 2024) {
switch (this.filing_status) {
Expand Down

0 comments on commit 9c683e6

Please sign in to comment.