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;
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() {

View File

@@ -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 @@
</script>
<div class="min-h-screen bg-[#051f18] text-white px-5 pt-4 pb-32">
<section class="flex gap-3 mb-7">
<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"