Track data to update
Boolean indicating success or failure
export function updateSkippedTrack(track: SkippedTrack): boolean {
try {
// Get current tracks
const tracks = getSkippedTracks();
const now = new Date().toISOString();
// Find existing track or add new one
const existingIndex = tracks.findIndex((t) => t.id === track.id);
if (existingIndex >= 0) {
const existing = tracks[existingIndex];
// Update with incremented skip count
tracks[existingIndex] = {
...existing,
name: track.name || existing.name,
artist: track.artist || existing.artist,
skipCount: (existing.skipCount || 0) + 1,
lastSkipped: now,
skipTimestamps: [...(existing.skipTimestamps || []), now],
};
} else {
// Add new track
tracks.push({
...track,
skipCount: 1,
notSkippedCount: 0,
lastSkipped: now,
skipTimestamps: [now],
});
}
return saveSkippedTracks(tracks);
} catch (error) {
console.error("Failed to update skipped track:", error);
return false;
}
}
Updates or adds a skipped track entry