From ffba2d78c208ea1396d4af7dc0b3e6f3781e54a2 Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Tue, 27 Jan 2026 12:14:22 +0000 Subject: [PATCH] add two inputs for posts and comments --- frontend/src/App.tsx | 47 ++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 328ae8c..5c753b2 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,29 +1,42 @@ -import { useState } from 'react' import axios from 'axios' import './App.css' function App() { + let postFile: File | undefined + let commentFile: File | undefined - const uploadPosts = async (file: React.ChangeEvent) => { - if (file.target.files) { - const formData = new FormData() - formData.append('file', file.target.files[0]) - try { - const response = await axios.post('http://localhost:5000/upload_posts', formData, { - headers: { - 'Content-Type': 'multipart/form-data' - } - }) - console.log('File uploaded successfully:', response.data) - } catch (error) { - console.error('Error uploading file:', error) - } + const uploadFiles = async () => { + if (!postFile || !commentFile) { + alert('Please select both files before uploading.') + return + } + + const formData = new FormData() + formData.append('posts', postFile) + formData.append('comments', commentFile) + + try { + const response = await axios.post('http://localhost:5000/upload', formData, { + headers: { + 'Content-Type': 'multipart/form-data', + }, + }) + console.log('Files uploaded successfully:', response.data) + } catch (error) { + console.error('Error uploading files:', error) } } - return (
- +
+

Posts File

+ postFile = e.target.files?.[0]}> +
+
+

Comments File

+ commentFile = e.target.files?.[0]}> +
+
) }