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:
sdarbinyan
2026-07-15 03:01:25 +04:00
parent 3cf732797c
commit cc885c009a

View File

@@ -15,6 +15,7 @@ import { UserExperienceFacade } from '../../../../facades/platform/user-experien
import { CartService } from '../../../../services';
import { LanguageService } from '../../../../services/language.service';
import { PrefetchService } from '../../../../services/prefetch.service';
import { LocalStorageService } from '../../../../core/storage/local-storage.service';
import { TranslatePipe } from '../../../../i18n/translate.pipe';
import { TranslateService } from '../../../../i18n/translate.service';
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 notifications = inject(UserNotificationService);
private readonly translate = inject(TranslateService);
private readonly storage = inject(LocalStorageService);
readonly catalogConfig = signal(this.resolveCatalogConfig());
readonly userExperienceConfig = signal(this.resolveUserExperienceConfig());
@@ -150,7 +152,7 @@ export class CatalogContainerComponent {
});
effect(() => {
const saved = typeof localStorage !== 'undefined' ? localStorage.getItem('catalog.layout.preference') : null;
const saved = this.storage.getItem('catalog.layout.preference');
if (!saved) {
return;
}
@@ -521,9 +523,7 @@ export class CatalogContainerComponent {
changeLayout(layout: CatalogLayoutMode): void {
const normalized = this.normalizeLayout(layout);
this.state.update(current => ({ ...current, layout: normalized }));
if (typeof localStorage !== 'undefined') {
localStorage.setItem('catalog.layout.preference', normalized);
}
this.storage.setItem('catalog.layout.preference', normalized);
this.syncUrlFromState();
this.persistContinueBrowsing();
}
@@ -920,7 +920,7 @@ export class CatalogContainerComponent {
}
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);
}