Added persistence to generators scope #13

Merged
mastah merged 1 commits from feature/more_storage into develop 2026-01-30 23:58:47 +01:00
2 changed files with 30 additions and 6 deletions

View File

@@ -5,12 +5,12 @@
@if (showControls) { @if (showControls) {
<div class="controls"> <div class="controls">
<mat-button-toggle-group vertical multiple class="generator-toggles"> <mat-button-toggle-group vertical multiple class="generator-toggles">
<mat-button-toggle [checked]="showRegon" (change)="showRegon = $event.source.checked">REGON</mat-button-toggle> <mat-button-toggle [checked]="showRegon" (change)="showRegon = $event.source.checked; saveGeneratorSettings()">REGON</mat-button-toggle>
<mat-button-toggle [checked]="showNip" (change)="showNip = $event.source.checked">NIP</mat-button-toggle> <mat-button-toggle [checked]="showNip" (change)="showNip = $event.source.checked; saveGeneratorSettings()">NIP</mat-button-toggle>
<mat-button-toggle [checked]="showPesel" (change)="showPesel = $event.source.checked">PESEL</mat-button-toggle> <mat-button-toggle [checked]="showPesel" (change)="showPesel = $event.source.checked; saveGeneratorSettings()">PESEL</mat-button-toggle>
<mat-button-toggle [checked]="showIdentityCard" (change)="showIdentityCard = $event.source.checked">DOWÓD</mat-button-toggle> <mat-button-toggle [checked]="showIdentityCard" (change)="showIdentityCard = $event.source.checked; saveGeneratorSettings()">DOWÓD</mat-button-toggle>
<mat-button-toggle [checked]="showMobile" (change)="showMobile = $event.source.checked">KOMÓRA</mat-button-toggle> <mat-button-toggle [checked]="showMobile" (change)="showMobile = $event.source.checked; saveGeneratorSettings()">KOMÓRA</mat-button-toggle>
<mat-button-toggle [checked]="showIban" (change)="showIban = $event.source.checked">IBAN</mat-button-toggle> <mat-button-toggle [checked]="showIban" (change)="showIban = $event.source.checked; saveGeneratorSettings()">IBAN</mat-button-toggle>
</mat-button-toggle-group> </mat-button-toggle-group>
<mat-button-toggle-group vertical class="theme-toggles"> <mat-button-toggle-group vertical class="theme-toggles">

View File

@@ -36,6 +36,18 @@ export class AppComponent implements OnInit {
this.selectedTheme = savedTheme; this.selectedTheme = savedTheme;
this.applyTheme(savedTheme); this.applyTheme(savedTheme);
} }
const savedGenerators = localStorage.getItem('generatorSettings');
if (savedGenerators) {
const settings = JSON.parse(savedGenerators);
this.showRegon = settings.showRegon ?? true;
this.showNip = settings.showNip ?? true;
this.showPesel = settings.showPesel ?? true;
this.showIdentityCard = settings.showIdentityCard ?? true;
this.showIban = settings.showIban ?? true;
this.showMobile = settings.showMobile ?? true;
}
setTimeout(() => { setTimeout(() => {
this.isInitialVisible = false; this.isInitialVisible = false;
this.cdr.detectChanges(); this.cdr.detectChanges();
@@ -48,6 +60,18 @@ export class AppComponent implements OnInit {
this.applyTheme(theme); this.applyTheme(theme);
} }
saveGeneratorSettings() {
const settings = {
showRegon: this.showRegon,
showNip: this.showNip,
showPesel: this.showPesel,
showIdentityCard: this.showIdentityCard,
showIban: this.showIban,
showMobile: this.showMobile
};
localStorage.setItem('generatorSettings', JSON.stringify(settings));
}
private applyTheme(theme: string) { private applyTheme(theme: string) {
const body = document.body; const body = document.body;
this.themes.forEach(t => { this.themes.forEach(t => {