Bug Fixes

This commit is contained in:
2026-01-25 17:40:13 +00:00
parent 295be1ed8e
commit 64b62c2a74
2 changed files with 76 additions and 23 deletions

View File

@@ -92,21 +92,8 @@
capturedImage = imageData; capturedImage = imageData;
analyzing = true; analyzing = true;
setTimeout(() => { const result = await analyzeImage(imageData);
const newItem = { processResult(result, imageData);
id: Date.now(),
title: "Plastic Bottle",
date: new Date().toLocaleString(),
impact: "High",
imageUri: capturedImage,
};
onScanComplete(newItem);
analyzing = false;
showResult = true;
resultTranslateY = 0;
typeText();
}, 1200);
}; };
reader.readAsDataURL(file); reader.readAsDataURL(file);
} }
@@ -143,14 +130,47 @@
}, 1200); }, 1200);
} }
function typeText() { function processResult(data: any, imageUri: string) {
let i = 0; analyzing = false;
const txt = "Detected: Plastic Bottle"; if (!data) {
const interval = setInterval(() => { displayTitle = "Scan Failed";
displayTitle = txt.substring(0, i); alternatives = [];
i++; showResult = true;
if (i > txt.length) clearInterval(interval); resultTranslateY = 0;
}, 50); 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() { function handleClose() {

View File

@@ -11,6 +11,38 @@
image: "/water-bottle.png", image: "/water-bottle.png",
impact: "Negative Impact", 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 { interface ScanItem {
@@ -197,6 +229,7 @@
</script> </script>
<div class="min-h-screen bg-[#051f18] text-white px-5 pt-4 pb-32"> <div class="min-h-screen bg-[#051f18] text-white px-5 pt-4 pb-32">
<section class="flex gap-3 mb-7"> <section class="flex gap-3 mb-7">
<button <button
class="flex-1 flex flex-col items-center gap-2 py-4 px-2 bg-[#0d2e25] border border-emerald-500/30 rounded-2xl active:scale-95 transition-all shadow-[0_0_15px_rgba(16,185,129,0.1)] relative overflow-hidden group min-h-[100px] justify-center" class="flex-1 flex flex-col items-center gap-2 py-4 px-2 bg-[#0d2e25] border border-emerald-500/30 rounded-2xl active:scale-95 transition-all shadow-[0_0_15px_rgba(16,185,129,0.1)] relative overflow-hidden group min-h-[100px] justify-center"