Spaces:
Sleeping
Sleeping
File size: 1,644 Bytes
f85b485 19d90a0 66906f8 19d90a0 6f7ef5c 19d90a0 6f7ef5c f85b485 6f7ef5c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | const Item = ({ item, drag, itemImgObj, onDelete }) => {
const handleDelete = (e) => {
e.stopPropagation();
if (window.confirm('Delete this item?')) {
onDelete && onDelete(item.id);
}
};
// Helper function to guarantee the correct absolute image URL
const getImageUrl = (path) => {
if (!path) return '';
// If it's already a full absolute URL, leave it alone
if (path.startsWith('http')) return path;
// Remove leading slash if it exists
let cleanPath = path.startsWith('/') ? path.substring(1) : path;
// Strip out old or new folder prefixes so we just get 'uploads/filename.jpg'
cleanPath = cleanPath.replace('api/item/', '').replace('tierapp/item/', '');
// Route through the uploads proxy so HTTPS pages can load images safely
return `/api/item/uploads/${cleanPath}`;
};
// FIX: Look at the database row (item.image) first!
const imagePath = item.image || item.image_path || (itemImgObj ? itemImgObj.image : '');
return (
<div className="unranked-cell">
<img
id={`item-${item.id}`}
src={getImageUrl(imagePath)}
style={{ cursor: "pointer" }}
draggable="true"
onDragStart={drag}
alt={item.title || "Tier list item"}
/>
<button
className="delete-item-btn"
onClick={handleDelete}
title="Delete item"
>×</button>
</div>
)
}
export default Item; |