Skip to content

Commit

Permalink
Rename storage methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jantoun-scottlogic committed Aug 2, 2024
1 parent d8f2631 commit 69edcb9
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/app/carbon-estimator-form/carbon-estimator-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ export class CarbonEstimatorFormComponent implements OnInit, OnDestroy {
this.estimatorForm.setValue(formValue);
}

const storedFormData = this.getSavedFormData();
const storedFormData = this.getStoredFormData();

if (storedFormData) {
this.estimatorForm.setValue(storedFormData);
}

const storedControlStates = this.getSavedControlStates();
const storedControlStates = this.getStoredControlStates();

if (storedControlStates) {
for (const [controlKey, controlState] of Object.entries(storedControlStates)) {
Expand All @@ -197,7 +197,7 @@ export class CarbonEstimatorFormComponent implements OnInit, OnDestroy {
}

ngOnDestroy(): void {
this.saveFormState();
this.storeFormState();
}

public handleSubmit() {
Expand All @@ -219,7 +219,7 @@ export class CarbonEstimatorFormComponent implements OnInit, OnDestroy {

public resetForm() {
this.estimatorForm.reset();
this.saveFormState();
this.storeFormState();
this.formReset.emit();
}

Expand All @@ -243,16 +243,16 @@ export class CarbonEstimatorFormComponent implements OnInit, OnDestroy {
}
}

private saveFormData() {
private storeFormData() {
this.storageService.set('formData', JSON.stringify(this.estimatorForm.getRawValue()));
}

private getSavedFormData() {
private getStoredFormData() {
const storedFormData = this.storageService.get('formData');
return storedFormData ? (JSON.parse(storedFormData) as EstimatorValues) : null;
}

private saveControlStates() {
private storeControlStates() {
const controlStates: Record<string, ControlState> = {};

for (const [groupName, formGroup] of Object.entries(this.estimatorForm.controls)) {
Expand All @@ -269,18 +269,18 @@ export class CarbonEstimatorFormComponent implements OnInit, OnDestroy {
this.storageService.set('controlStates', JSON.stringify(controlStates));
}

private getSavedControlStates() {
private getStoredControlStates() {
const storedControlStates = this.storageService.get('controlStates');
return storedControlStates ? (JSON.parse(storedControlStates) as Record<string, ControlState>) : null;
}

private saveFormState() {
this.saveFormData();
this.saveControlStates();
private storeFormState() {
this.storeFormData();
this.storeControlStates();
}

@HostListener('window:beforeunload', ['$event'])
onBeforeUnload(): void {
this.saveFormState();
this.storeFormState();
}
}

0 comments on commit 69edcb9

Please sign in to comment.