chore: save current changes
This commit is contained in:
@@ -32,20 +32,57 @@ export class MyCantiService {
|
||||
}
|
||||
}
|
||||
|
||||
async saveCanto(canto: Partial<Canto>) {
|
||||
async saveCanto(canto: Partial<Canto>): Promise<Canto> {
|
||||
const current = this.myCanti();
|
||||
const newCanto: Canto = {
|
||||
id: `my_${Date.now()}`,
|
||||
id_canti: Date.now(), // Fake ID for internal logic
|
||||
titolo: canto.titolo || 'Senza Titolo',
|
||||
testo: canto.testo || '',
|
||||
accordi: canto.accordi,
|
||||
autore: canto.autore,
|
||||
link_youtube: canto.link_youtube,
|
||||
id_momenti: canto.id_momenti || []
|
||||
};
|
||||
let updated: Canto[];
|
||||
let targetCanto: Canto;
|
||||
|
||||
if (canto.id && canto.id.startsWith('my_')) {
|
||||
// Update existing song
|
||||
updated = current.map(c => {
|
||||
if (c.id === canto.id) {
|
||||
targetCanto = {
|
||||
...c,
|
||||
titolo: canto.titolo || c.titolo,
|
||||
testo: canto.testo || c.testo,
|
||||
accordi: canto.accordi !== undefined ? canto.accordi : c.accordi,
|
||||
autore: canto.autore !== undefined ? canto.autore : c.autore,
|
||||
link_youtube: canto.link_youtube !== undefined ? canto.link_youtube : c.link_youtube,
|
||||
id_momenti: canto.id_momenti || c.id_momenti
|
||||
};
|
||||
return targetCanto;
|
||||
}
|
||||
return c;
|
||||
});
|
||||
// Fallback if not found in list (should not happen normally)
|
||||
if (!updated.some(c => c.id === canto.id)) {
|
||||
targetCanto = {
|
||||
id: canto.id,
|
||||
id_canti: canto.id_canti || Date.now(),
|
||||
titolo: canto.titolo || 'Senza Titolo',
|
||||
testo: canto.testo || '',
|
||||
accordi: canto.accordi,
|
||||
autore: canto.autore,
|
||||
link_youtube: canto.link_youtube,
|
||||
id_momenti: canto.id_momenti || []
|
||||
};
|
||||
updated.push(targetCanto);
|
||||
}
|
||||
} else {
|
||||
// Create new song
|
||||
targetCanto = {
|
||||
id: `my_${Date.now()}`,
|
||||
id_canti: Date.now(), // Fake ID for internal logic
|
||||
titolo: canto.titolo || 'Senza Titolo',
|
||||
testo: canto.testo || '',
|
||||
accordi: canto.accordi,
|
||||
autore: canto.autore,
|
||||
link_youtube: canto.link_youtube,
|
||||
id_momenti: canto.id_momenti || []
|
||||
};
|
||||
updated = [...current, targetCanto];
|
||||
}
|
||||
|
||||
const updated = [...current, newCanto];
|
||||
this.myCanti.set(updated);
|
||||
await this._storage?.set('my-canti', updated);
|
||||
|
||||
@@ -55,6 +92,8 @@ export class MyCantiService {
|
||||
color: 'success'
|
||||
});
|
||||
toast.present();
|
||||
|
||||
return targetCanto!;
|
||||
}
|
||||
|
||||
async deleteCanto(id: string) {
|
||||
|
||||
Reference in New Issue
Block a user