diff --git a/src/lib/backup.ts b/src/lib/backup.ts index 7430a4e..7b61a68 100644 --- a/src/lib/backup.ts +++ b/src/lib/backup.ts @@ -263,6 +263,23 @@ export function parseBackupRows( createdAt: parseOptionalDate(row.createdAt ?? ""), updatedAt: parseOptionalDate(row.updatedAt ?? ""), }) + // Extract embedded rating data from drink rows (e.g. manually edited CSVs) + if (row.score && row.score.trim() !== "") { + const score = parseInt(row.score, 10) + if (score >= 1 && score <= 5) { + data.ratings.push({ + _originalId: `${row._originalId ?? ""}_rating`, + _parentId: row._originalId ?? "", + _drinkName: row.name ?? "", + score, + notes: row.notes || undefined, + wouldReorder: parseBoolean(row.wouldReorder ?? "false"), + location: row.location || undefined, + createdAt: parseOptionalDate(row.createdAt ?? ""), + updatedAt: parseOptionalDate(row.updatedAt ?? ""), + }) + } + } break case "rating": diff --git a/src/lib/csv.ts b/src/lib/csv.ts index 50c1cdd..f9f2e9d 100644 --- a/src/lib/csv.ts +++ b/src/lib/csv.ts @@ -39,7 +39,9 @@ export function objectsToCsv( * Uses a state-machine parser to correctly handle quoted fields. */ export function csvToObjects(csvText: string): Record[] { - const rows = parseCsvRows(csvText) + // Strip UTF-8 BOM if present + const cleanText = csvText.charCodeAt(0) === 0xfeff ? csvText.slice(1) : csvText + const rows = parseCsvRows(cleanText) if (rows.length < 1) return [] const headers = rows[0]