Spaces:
Running
Running
Update frontend/src/pages/Dashboard.jsx
Browse files
frontend/src/pages/Dashboard.jsx
CHANGED
|
@@ -2,37 +2,56 @@
|
|
| 2 |
|
| 3 |
import React, { useState } from "react";
|
| 4 |
import { motion } from "framer-motion";
|
| 5 |
-
import { Sparkles, Zap, FileText, TrendingUp, Clock } from "lucide-react";
|
| 6 |
import { Button } from "@/components/ui/button";
|
| 7 |
import UploadZone from "@/components/ocr/UploadZone";
|
| 8 |
import DocumentPreview from "@/components/ocr/DocumentPreview";
|
| 9 |
import ExtractionOutput from "@/components/ocr/ExtractionOutput";
|
| 10 |
import ExportButtons from "@/components/ExportButtons";
|
| 11 |
import ProcessingStatus from "@/components/ocr/ProcessingStatus";
|
|
|
|
| 12 |
|
| 13 |
export default function Dashboard() {
|
| 14 |
const [selectedFile, setSelectedFile] = useState(null);
|
| 15 |
const [isProcessing, setIsProcessing] = useState(false);
|
| 16 |
const [isComplete, setIsComplete] = useState(false);
|
|
|
|
|
|
|
| 17 |
|
| 18 |
const handleFileSelect = (file) => {
|
| 19 |
setSelectedFile(file);
|
| 20 |
setIsComplete(false);
|
|
|
|
|
|
|
| 21 |
};
|
| 22 |
|
| 23 |
const handleClear = () => {
|
| 24 |
setSelectedFile(null);
|
| 25 |
setIsProcessing(false);
|
| 26 |
setIsComplete(false);
|
|
|
|
|
|
|
| 27 |
};
|
| 28 |
|
| 29 |
-
const handleExtract = () => {
|
|
|
|
|
|
|
| 30 |
setIsProcessing(true);
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
setIsComplete(true);
|
| 35 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
};
|
| 37 |
|
| 38 |
return (
|
|
@@ -104,6 +123,29 @@ export default function Dashboard() {
|
|
| 104 |
)}
|
| 105 |
</motion.div>
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
{/* Processing Status */}
|
| 108 |
{(isProcessing || isComplete) && (
|
| 109 |
<div className="max-w-4xl mx-auto mb-8">
|
|
@@ -128,6 +170,7 @@ export default function Dashboard() {
|
|
| 128 |
hasFile={!!selectedFile}
|
| 129 |
isProcessing={isProcessing}
|
| 130 |
isComplete={isComplete}
|
|
|
|
| 131 |
/>
|
| 132 |
</motion.div>
|
| 133 |
)}
|
|
|
|
| 2 |
|
| 3 |
import React, { useState } from "react";
|
| 4 |
import { motion } from "framer-motion";
|
| 5 |
+
import { Sparkles, Zap, FileText, TrendingUp, Clock, AlertCircle } from "lucide-react";
|
| 6 |
import { Button } from "@/components/ui/button";
|
| 7 |
import UploadZone from "@/components/ocr/UploadZone";
|
| 8 |
import DocumentPreview from "@/components/ocr/DocumentPreview";
|
| 9 |
import ExtractionOutput from "@/components/ocr/ExtractionOutput";
|
| 10 |
import ExportButtons from "@/components/ExportButtons";
|
| 11 |
import ProcessingStatus from "@/components/ocr/ProcessingStatus";
|
| 12 |
+
import { extractDocument } from "@/services/api";
|
| 13 |
|
| 14 |
export default function Dashboard() {
|
| 15 |
const [selectedFile, setSelectedFile] = useState(null);
|
| 16 |
const [isProcessing, setIsProcessing] = useState(false);
|
| 17 |
const [isComplete, setIsComplete] = useState(false);
|
| 18 |
+
const [extractionResult, setExtractionResult] = useState(null);
|
| 19 |
+
const [error, setError] = useState(null);
|
| 20 |
|
| 21 |
const handleFileSelect = (file) => {
|
| 22 |
setSelectedFile(file);
|
| 23 |
setIsComplete(false);
|
| 24 |
+
setExtractionResult(null);
|
| 25 |
+
setError(null);
|
| 26 |
};
|
| 27 |
|
| 28 |
const handleClear = () => {
|
| 29 |
setSelectedFile(null);
|
| 30 |
setIsProcessing(false);
|
| 31 |
setIsComplete(false);
|
| 32 |
+
setExtractionResult(null);
|
| 33 |
+
setError(null);
|
| 34 |
};
|
| 35 |
|
| 36 |
+
const handleExtract = async () => {
|
| 37 |
+
if (!selectedFile) return;
|
| 38 |
+
|
| 39 |
setIsProcessing(true);
|
| 40 |
+
setIsComplete(false);
|
| 41 |
+
setError(null);
|
| 42 |
+
setExtractionResult(null);
|
| 43 |
+
|
| 44 |
+
try {
|
| 45 |
+
const result = await extractDocument(selectedFile);
|
| 46 |
+
setExtractionResult(result);
|
| 47 |
setIsComplete(true);
|
| 48 |
+
} catch (err) {
|
| 49 |
+
console.error("Extraction error:", err);
|
| 50 |
+
setError(err.message || "Failed to extract document. Please try again.");
|
| 51 |
+
setIsComplete(false);
|
| 52 |
+
} finally {
|
| 53 |
+
setIsProcessing(false);
|
| 54 |
+
}
|
| 55 |
};
|
| 56 |
|
| 57 |
return (
|
|
|
|
| 123 |
)}
|
| 124 |
</motion.div>
|
| 125 |
|
| 126 |
+
{/* Error Message */}
|
| 127 |
+
{error && (
|
| 128 |
+
<motion.div
|
| 129 |
+
initial={{ opacity: 0, y: -10 }}
|
| 130 |
+
animate={{ opacity: 1, y: 0 }}
|
| 131 |
+
className="max-w-3xl mx-auto mb-6"
|
| 132 |
+
>
|
| 133 |
+
<div className="bg-red-50 border border-red-200 rounded-2xl p-4 flex items-start gap-3">
|
| 134 |
+
<AlertCircle className="h-5 w-5 text-red-600 flex-shrink-0 mt-0.5" />
|
| 135 |
+
<div className="flex-1">
|
| 136 |
+
<h3 className="font-semibold text-red-900 mb-1">Extraction Failed</h3>
|
| 137 |
+
<p className="text-sm text-red-700">{error}</p>
|
| 138 |
+
</div>
|
| 139 |
+
<button
|
| 140 |
+
onClick={() => setError(null)}
|
| 141 |
+
className="text-red-400 hover:text-red-600 transition-colors"
|
| 142 |
+
>
|
| 143 |
+
×
|
| 144 |
+
</button>
|
| 145 |
+
</div>
|
| 146 |
+
</motion.div>
|
| 147 |
+
)}
|
| 148 |
+
|
| 149 |
{/* Processing Status */}
|
| 150 |
{(isProcessing || isComplete) && (
|
| 151 |
<div className="max-w-4xl mx-auto mb-8">
|
|
|
|
| 170 |
hasFile={!!selectedFile}
|
| 171 |
isProcessing={isProcessing}
|
| 172 |
isComplete={isComplete}
|
| 173 |
+
extractionResult={extractionResult}
|
| 174 |
/>
|
| 175 |
</motion.div>
|
| 176 |
)}
|