From 11f8681febf0650aa7df4738c44b69e9c6b16f56 Mon Sep 17 00:00:00 2001 From: Thorsten Bus Date: Mon, 2 Mar 2026 13:25:36 +0100 Subject: [PATCH] feat(songs): implement .pro file upload in SongDB page - Replace placeholder exception with real uploadProFiles() function - POST files to /api/songs/import-pro endpoint - Show success/error toast and refresh song list after import --- resources/js/Pages/Songs/Index.vue | 45 ++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/resources/js/Pages/Songs/Index.vue b/resources/js/Pages/Songs/Index.vue index 988d3bc..13851f4 100644 --- a/resources/js/Pages/Songs/Index.vue +++ b/resources/js/Pages/Songs/Index.vue @@ -2,6 +2,7 @@ import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue' import SongEditModal from '@/Components/SongEditModal.vue' import { Head } from '@inertiajs/vue3' +import axios from 'axios' import { ref, watch, onMounted } from 'vue' const songs = ref([]) @@ -139,11 +140,12 @@ function handleDragLeave() { isDragging.value = false } -function handleDrop(e) { +async function handleDrop(e) { e.preventDefault() isDragging.value = false - uploadError.value = 'ProPresenter-Import (.pro) ist noch nicht verfügbar. Kommt bald!' - setTimeout(() => { uploadError.value = '' }, 4000) + const droppedFiles = Array.from(e.dataTransfer?.files || []) + if (droppedFiles.length === 0) return + await uploadProFiles(droppedFiles) } function triggerFileInput() { @@ -151,9 +153,42 @@ function triggerFileInput() { } function handleFileSelect() { - uploadError.value = 'ProPresenter-Import (.pro) ist noch nicht verfügbar. Kommt bald!' + const selectedFiles = Array.from(fileInput.value?.files || []) if (fileInput.value) fileInput.value.value = '' - setTimeout(() => { uploadError.value = '' }, 4000) + if (selectedFiles.length === 0) return + uploadProFiles(selectedFiles) +} + +async function uploadProFiles(files) { + uploadError.value = '' + loading.value = true + let successCount = 0 + let errors = [] + + for (const file of files) { + const formData = new FormData() + formData.append('file', file) + + try { + await axios.post('/api/songs/import-pro', formData, { + headers: { 'Content-Type': 'multipart/form-data' }, + }) + successCount++ + } catch (err) { + const message = err.response?.data?.message || `Fehler bei "${file.name}"` + errors.push(message) + } + } + + if (successCount > 0) { + await fetchSongs(1) + } + + if (errors.length > 0) { + uploadError.value = errors.join(', ') + setTimeout(() => { uploadError.value = '' }, 6000) + } + loading.value = false } // Page range for pagination