refactor: route catalog-container localStorage calls through LocalStorageService
Sprint 2 high-priority cleanup: layout preference read/write called raw localStorage from a component, violating the no-raw-localStorage rule. Now uses the shared core/storage/LocalStorageService (same as cart/language/location services). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import { UserExperienceFacade } from '../../../../facades/platform/user-experien
|
|||||||
import { CartService } from '../../../../services';
|
import { CartService } from '../../../../services';
|
||||||
import { LanguageService } from '../../../../services/language.service';
|
import { LanguageService } from '../../../../services/language.service';
|
||||||
import { PrefetchService } from '../../../../services/prefetch.service';
|
import { PrefetchService } from '../../../../services/prefetch.service';
|
||||||
|
import { LocalStorageService } from '../../../../core/storage/local-storage.service';
|
||||||
import { TranslatePipe } from '../../../../i18n/translate.pipe';
|
import { TranslatePipe } from '../../../../i18n/translate.pipe';
|
||||||
import { TranslateService } from '../../../../i18n/translate.service';
|
import { TranslateService } from '../../../../i18n/translate.service';
|
||||||
import { DEFAULT_CATALOG_CONFIG, DEFAULT_USER_EXPERIENCE_CONFIG } from '../../../../shared/models/config';
|
import { DEFAULT_CATALOG_CONFIG, DEFAULT_USER_EXPERIENCE_CONFIG } from '../../../../shared/models/config';
|
||||||
@@ -68,6 +69,7 @@ export class CatalogContainerComponent {
|
|||||||
private readonly shareService = inject(ProductShareService);
|
private readonly shareService = inject(ProductShareService);
|
||||||
private readonly notifications = inject(UserNotificationService);
|
private readonly notifications = inject(UserNotificationService);
|
||||||
private readonly translate = inject(TranslateService);
|
private readonly translate = inject(TranslateService);
|
||||||
|
private readonly storage = inject(LocalStorageService);
|
||||||
|
|
||||||
readonly catalogConfig = signal(this.resolveCatalogConfig());
|
readonly catalogConfig = signal(this.resolveCatalogConfig());
|
||||||
readonly userExperienceConfig = signal(this.resolveUserExperienceConfig());
|
readonly userExperienceConfig = signal(this.resolveUserExperienceConfig());
|
||||||
@@ -150,7 +152,7 @@ export class CatalogContainerComponent {
|
|||||||
});
|
});
|
||||||
|
|
||||||
effect(() => {
|
effect(() => {
|
||||||
const saved = typeof localStorage !== 'undefined' ? localStorage.getItem('catalog.layout.preference') : null;
|
const saved = this.storage.getItem('catalog.layout.preference');
|
||||||
if (!saved) {
|
if (!saved) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -521,9 +523,7 @@ export class CatalogContainerComponent {
|
|||||||
changeLayout(layout: CatalogLayoutMode): void {
|
changeLayout(layout: CatalogLayoutMode): void {
|
||||||
const normalized = this.normalizeLayout(layout);
|
const normalized = this.normalizeLayout(layout);
|
||||||
this.state.update(current => ({ ...current, layout: normalized }));
|
this.state.update(current => ({ ...current, layout: normalized }));
|
||||||
if (typeof localStorage !== 'undefined') {
|
this.storage.setItem('catalog.layout.preference', normalized);
|
||||||
localStorage.setItem('catalog.layout.preference', normalized);
|
|
||||||
}
|
|
||||||
this.syncUrlFromState();
|
this.syncUrlFromState();
|
||||||
this.persistContinueBrowsing();
|
this.persistContinueBrowsing();
|
||||||
}
|
}
|
||||||
@@ -920,7 +920,7 @@ export class CatalogContainerComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private resolveInitialLayout(): CatalogLayoutMode {
|
private resolveInitialLayout(): CatalogLayoutMode {
|
||||||
const stored = typeof localStorage !== 'undefined' ? localStorage.getItem('catalog.layout.preference') : null;
|
const stored = this.storage.getItem('catalog.layout.preference');
|
||||||
return this.normalizeLayout((stored as CatalogLayoutMode) || this.catalogConfig().layout);
|
return this.normalizeLayout((stored as CatalogLayoutMode) || this.catalogConfig().layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user