modifiche face offline e 2 secondi di attesa

This commit is contained in:
David Frassi
2026-07-13 17:55:07 +02:00
parent 333858bf48
commit 9f9b164937
20 changed files with 936 additions and 128 deletions
+11 -5
View File
@@ -17,17 +17,21 @@ export class MyCantiService {
private _storage: Storage | null = null;
public myCanti = signal<Canto[]>([]);
private initPromise!: Promise<void>;
constructor() {
this.init();
this.initPromise = this.init();
}
async init() {
async init(): Promise<void> {
this._storage = this.cantiService.getStorage();
if (!this._storage) {
// If CantiService hasn't initialized storage yet, wait a bit
setTimeout(() => this.init(), 500);
return;
return new Promise<void>((resolve) => {
setTimeout(async () => {
await this.init();
resolve();
}, 500);
});
}
const saved = await this._storage.get('my-canti');
if (saved) {
@@ -36,6 +40,7 @@ export class MyCantiService {
}
async saveCanto(canto: Partial<Canto>): Promise<Canto> {
await this.initPromise;
const current = this.myCanti();
let updated: Canto[];
let targetCanto: Canto;
@@ -108,6 +113,7 @@ export class MyCantiService {
}
async deleteCanto(id: string) {
await this.initPromise;
const updated = this.myCanti().filter(c => c.id !== id);
this.myCanti.set(updated);
await this._storage?.set('my-canti', updated);