"use client"; import Image from "next/image"; import { FaBriefcase, FaUserGraduate, FaTools, FaFileUpload } from "react-icons/fa"; import { useState } from "react"; import CvSummaryPanel from "@/components/CvSummaryPanel"; // Import the new component export default function Home() { const [file, setFile] = useState(null); const [summary, setSummary] = useState(null); const [loading, setLoading] = useState(false); const [isSummaryVisible, setIsSummaryVisible] = useState(false); // State for panel visibility const handleFileChange = (event: React.ChangeEvent) => { if (event.target.files) { setFile(event.target.files[0]); setSummary(null); // Clear previous summary when file changes setIsSummaryVisible(false); // Hide summary panel on new file upload } }; const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); if (!file) return; console.log("handleSubmit: Start"); // ADDED LOGGING setLoading(true); setSummary(null); setIsSummaryVisible(false); // Hide summary panel while loading const formData = new FormData(); formData.append("cv", file); try { const response = await fetch("/api/upload-cv", { method: "POST", body: formData, }); if (response.ok) { const stream = response.body; if (!stream) { console.error("No response stream"); setLoading(false); return; } const reader = stream.getReader(); let chunks = ''; while (true) { const { done, value } = await reader.read(); if (done) { break; } chunks += new TextDecoder().decode(value); } const parsed = JSON.parse(chunks); console.log("handleSubmit: Parsed response:", parsed); // ADDED LOGGING console.log("handleSubmit: Before setSummary - summary:", summary, "isSummaryVisible:", isSummaryVisible); // ADDED LOGGING setSummary(parsed.summary); setIsSummaryVisible(true); // Show summary panel after successful upload console.log("Summary state updated:", parsed.summary); console.log("handleSubmit: After setSummary - summary:", summary, "isSummaryVisible:", isSummaryVisible); // ADDED LOGGING } else { alert("CV summary failed."); } } catch (error) { console.error("Error summarizing CV:", error); alert("An error occurred while summarizing the CV."); } finally { setLoading(false); console.log("handleSubmit: Finally block - loading:", loading); // ADDED LOGGING } console.log("handleSubmit: End"); // ADDED LOGGING }; return (

Welcome to Your CV Upgrade

This platform is designed to help you enhance your CV and showcase your skills effectively.

Highlight your professional experience and achievements.

Showcase your educational background and certifications.

Utilize our tools to create a standout CV that gets noticed.

{file &&

Selected file: {file.name}

}
{/* Right Column - CV Summary Panel */}
{loading ? (
) : ( isSummaryVisible && summary && )}
); }