Persist cover scale preference per device using LocalStorage
- Store cover scale preference locally to allow different settings per device (desktop, mobile) - Disabled backend saving for cover scale but kept code commented for future reference - Load scale preference from LocalStorage on init for faster and device-specific UX
This commit is contained in:
committed by
Aditya Chandel
parent
ca5a09f740
commit
49c4519cf7
@@ -0,0 +1,25 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class LocalStorageService {
|
||||
|
||||
get<T>(key: string): T | null {
|
||||
try {
|
||||
const value = localStorage.getItem(key);
|
||||
return value ? JSON.parse(value) as T : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
set<T>(key: string, value: T): void {
|
||||
try {
|
||||
localStorage.setItem(key, JSON.stringify(value));
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
|
||||
remove(key: string): void {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user