Skip to content

Commit

Permalink
Merge pull request #63 from rubberduck-vba/webhook
Browse files Browse the repository at this point in the history
Fix indenter storage glitches
  • Loading branch information
retailcoder authored Feb 11, 2025
2 parents b375169 + 08bb423 commit 04db83b
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions rubberduckvba.client/src/app/routes/indenter/indenter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,23 @@ export class IndenterComponent implements OnInit, IndenterOptionGroups {
}

ngOnInit(): void {
this.load();
}

private load(): void {
const localModel = localStorage.getItem('indenter.model');
const localOptionGroups = localStorage.getItem('indenter.options');
this.isLocalStorageOK = localModel != null && localOptionGroups != null;

if (!this.isLocalStorageOK) {
this.getDefaults();
return;
}

if (localModel) {
this.model = <IndenterViewModel>JSON.parse(localModel);
}

const localOptionGroups = localStorage.getItem('indenter.options');
if (localOptionGroups) {
const optionGroups = <IndenterOptionGroups>JSON.parse(localOptionGroups);
this.isExpanded = optionGroups.isExpanded;
Expand All @@ -46,13 +57,13 @@ export class IndenterComponent implements OnInit, IndenterOptionGroups {
this.isVerticalOptionsExpanded = optionGroups.isVerticalOptionsExpanded;
this.isApiAboutBoxExpanded = optionGroups.isApiAboutBoxExpanded;
}

this.isLocalStorageOK = localModel != null || localOptionGroups != null;
if (!this.isLocalStorageOK) {
this.getDefaults();
}
}

private clearStorage(): void {
localStorage.removeItem('indenter.model');
localStorage.removeItem('indenter.options');
}

public getDefaults(): void {
this.service.getIndenterDefaults().subscribe(model => {
this.model = model;
Expand All @@ -68,7 +79,17 @@ export class IndenterComponent implements OnInit, IndenterOptionGroups {
private _isApiAboutBoxExpanded: boolean = false;

public isIndenterBusy: boolean = false;
public isLocalStorageOK: boolean = false;

private _isLocalStorageOK: boolean = false;
public get isLocalStorageOK(): boolean {
return this._isLocalStorageOK;
}
public set isLocalStorageOK(value: boolean) {
this._isLocalStorageOK = value;
if (!value) {
this.clearStorage();
}
}

public get model(): IndenterViewModel {
return this._model;
Expand All @@ -77,9 +98,7 @@ export class IndenterComponent implements OnInit, IndenterOptionGroups {
private set model(value: IndenterViewModel) {
this._model = value;
this.invalidateClipboard();
if (this.isLocalStorageOK) {
localStorage.setItem('indenter.model', JSON.stringify(this.model))
};
this.saveModel();
}

public get asJson(): string {
Expand All @@ -98,7 +117,6 @@ export class IndenterComponent implements OnInit, IndenterOptionGroups {
public get isIndentOptionsExpanded(): boolean {
return this._isIndentOptionsExpanded;
}

public set isIndentOptionsExpanded(value: boolean) {
this._isIndentOptionsExpanded = value;
this.saveOptions();
Expand All @@ -117,15 +135,13 @@ export class IndenterComponent implements OnInit, IndenterOptionGroups {
this._isVerticalOptionsExpanded = value;
this.saveOptions();
}

public get isApiAboutBoxExpanded(): boolean {
return this._isApiAboutBoxExpanded;
}
public set isApiAboutBoxExpanded(value: boolean) {
this._isApiAboutBoxExpanded = value;
this.saveOptions();
}

public get isOutdentOptionsExpanded(): boolean {
return this._isOutdentOptionsExpanded;
}
Expand Down Expand Up @@ -159,7 +175,9 @@ export class IndenterComponent implements OnInit, IndenterOptionGroups {
}
}
private saveOptions(): void {
localStorage.setItem('indenter.options', JSON.stringify(this.asOptionGroups));
if (this.isLocalStorageOK) {
localStorage.setItem('indenter.options', JSON.stringify(this.asOptionGroups));
}
}

public indent(): void {
Expand Down

0 comments on commit 04db83b

Please sign in to comment.