diff --git a/frontend/src/lib/components/CameraScreen.svelte b/frontend/src/lib/components/CameraScreen.svelte index c1c2cdc..d5d8228 100644 --- a/frontend/src/lib/components/CameraScreen.svelte +++ b/frontend/src/lib/components/CameraScreen.svelte @@ -92,21 +92,8 @@ capturedImage = imageData; analyzing = true; - setTimeout(() => { - const newItem = { - id: Date.now(), - title: "Plastic Bottle", - date: new Date().toLocaleString(), - impact: "High", - imageUri: capturedImage, - }; - - onScanComplete(newItem); - analyzing = false; - showResult = true; - resultTranslateY = 0; - typeText(); - }, 1200); + const result = await analyzeImage(imageData); + processResult(result, imageData); }; reader.readAsDataURL(file); } @@ -143,14 +130,47 @@ }, 1200); } - function typeText() { - let i = 0; - const txt = "Detected: Plastic Bottle"; - const interval = setInterval(() => { - displayTitle = txt.substring(0, i); - i++; - if (i > txt.length) clearInterval(interval); - }, 50); + function processResult(data: any, imageUri: string) { + analyzing = false; + if (!data) { + displayTitle = "Scan Failed"; + alternatives = []; + showResult = true; + resultTranslateY = 0; + return; + } + + console.log("Analysis Result:", data); + + const analysis = data.analysis; + const newItem = { + id: data.incident_id || Date.now(), + title: data.detected_brand !== "Unknown" ? data.detected_brand : "Scanned Product", + date: new Date().toLocaleString(), + impact: analysis.verdict || (analysis.is_greenwashing ? "Potential Greenwashing Detected" : "No Issues Found"), + imageUri: imageUri, + severity: analysis.severity || "low", + is_greenwashing: analysis.is_greenwashing || false, + analysis: analysis, + }; + + if (analysis.alternatives && analysis.alternatives.length > 0) { + alternatives = analysis.alternatives.map((alt: string, idx: number) => ({ + name: alt, + reason: alt, + impact_reduction: true + })); + } else { + alternatives = []; + } + + displayTitle = newItem.is_greenwashing + ? `⚠️ ${newItem.title}` + : `✓ ${newItem.title}`; + + onScanComplete(newItem); + showResult = true; + resultTranslateY = 0; } function handleClose() { diff --git a/frontend/src/lib/components/MobileHomePage.svelte b/frontend/src/lib/components/MobileHomePage.svelte index 6d90bfc..3adb751 100644 --- a/frontend/src/lib/components/MobileHomePage.svelte +++ b/frontend/src/lib/components/MobileHomePage.svelte @@ -11,6 +11,38 @@ image: "/water-bottle.png", impact: "Negative Impact", }, + { + id: 2, + name: "Organic Banana", + date: "Yesterday, 3:20 PM", + severity: "Low", + image: "/banana.png", + impact: "Positive Choice", + }, + { + id: 3, + name: "Aluminum Soda Can", + date: "Mon, 12:15 PM", + severity: "Low", + image: "/soda-can.png", + impact: "Recyclable", + }, + { + id: 4, + name: "Takeout Container", + date: "Sun, 8:30 PM", + severity: "Medium", + image: "/container.png", + impact: "Mixed Materials", + }, + { + id: 5, + name: "Shampoo Bottle", + date: "Sat, 11:00 AM", + severity: "High", + image: "/shampoo.png", + impact: "High Plastic", + }, ]; interface ScanItem { @@ -197,6 +229,7 @@