From 5102ca86cb0572aee95d46f7975a07076fd1e03e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=B6rdle=20Bot?= Date: Tue, 25 Nov 2025 09:34:55 +0100 Subject: [PATCH] feat: Add batch genre assignment functionality to song uploads, including UI for selection and post-upload API calls. --- app/admin/page.tsx | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/app/admin/page.tsx b/app/admin/page.tsx index 4c8a181..56e8712 100644 --- a/app/admin/page.tsx +++ b/app/admin/page.tsx @@ -106,6 +106,9 @@ export default function AdminPage() { const [uploadGenreIds, setUploadGenreIds] = useState([]); const [uploadExcludeFromGlobal, setUploadExcludeFromGlobal] = useState(false); + // Batch upload genre selection + const [batchUploadGenreIds, setBatchUploadGenreIds] = useState([]); + // AI Categorization state const [isCategorizing, setIsCategorizing] = useState(false); const [categorizationResults, setCategorizationResults] = useState(null); @@ -548,6 +551,28 @@ export default function AdminPage() { setUploadResults(results); setFiles([]); setIsUploading(false); + + // Assign genres to successfully uploaded songs + if (batchUploadGenreIds.length > 0) { + const successfulUploads = results.filter(r => r.success && r.song); + for (const result of successfulUploads) { + try { + await fetch('/api/songs', { + method: 'PUT', + headers: getAuthHeaders(), + body: JSON.stringify({ + id: result.song.id, + title: result.song.title, + artist: result.song.artist, + genreIds: batchUploadGenreIds + }), + }); + } catch (error) { + console.error(`Failed to assign genres to ${result.song.title}:`, error); + } + } + } + fetchSongs(); fetchGenres(); fetchSpecials(); // Update special counts @@ -564,6 +589,13 @@ export default function AdminPage() { if (failedCount > 0) { msg += `\n❌ ${failedCount} failed`; } + if (batchUploadGenreIds.length > 0) { + const selectedGenreNames = genres + .filter(g => batchUploadGenreIds.includes(g.id)) + .map(g => g.name) + .join(', '); + msg += `\n🏷️ Assigned genres: ${selectedGenreNames}`; + } msg += '\n\n🤖 Starting auto-categorization...'; setMessage(msg); // Small delay to let user see the message @@ -1219,6 +1251,48 @@ export default function AdminPage() { )} +
+ +
+ {genres.map(genre => ( + + ))} +
+

+ Selected genres will be assigned to all uploaded songs. +

+
+