diff --git a/.gitignore b/.gitignore
index b89e42c..4d61660 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,6 +22,7 @@ __pycache__/
__pycache__/
+db.sqlite3
# Editor directories and files
.vscode/*
diff --git a/backend/db.sqlite3 b/backend/db.sqlite3
index 5e35f87..a3975f6 100644
Binary files a/backend/db.sqlite3 and b/backend/db.sqlite3 differ
diff --git a/src/components/BrowseItemDisplay.jsx b/src/components/BrowseItemDisplay.jsx
index d1997e9..f5a2046 100644
--- a/src/components/BrowseItemDisplay.jsx
+++ b/src/components/BrowseItemDisplay.jsx
@@ -2,15 +2,15 @@ import ItemCard from "./ItemCard";
import { Wrap, WrapItem } from "@chakra-ui/react";
export default function BrowseItemDisplay({ items }) {
- if (!items) {
- return
no items match your search
;
+ if (!items || items.length === 0) {
+ return No items match your search.
;
}
return (
{items.map((item) => {
return (
-
+
);
diff --git a/src/components/ItemCard.jsx b/src/components/ItemCard.jsx
index 6c58dde..811b15b 100644
--- a/src/components/ItemCard.jsx
+++ b/src/components/ItemCard.jsx
@@ -8,6 +8,8 @@ import {
Heading,
Text,
} from "@chakra-ui/react";
+import axios from "axios";
+import AWS from 'aws-sdk';
// item fields:
// title, imageUrl, category,
@@ -15,6 +17,59 @@ const ItemCard = ({ item }) => {
const imageUrls = item.imageURLs.split(",");
const firstImage = imageUrls[0];
+ AWS.config.update({
+ region: 'us-east-2',
+ credentials: new AWS.Credentials(
+ import.meta.env.VITE_AWS_ACCESS_KEY,
+ import.meta.env.VITE_AWS_SECRET_KEY
+ ),
+ });
+
+ const s3 = new AWS.S3();
+
+ const handleDelete = async (item) => {
+ // setLoading(true);
+ try {
+ // Find the listing to be deleted using the provided id
+ // const listing = allListings.find(listing => listing.id === id);
+ // if (!listing) {
+ // throw new Error("Listing not found");
+ // }
+
+ // Delete the listing from the database
+ await axios.delete(`http://127.0.0.1:8000/api/delete/${item.id}`);
+
+ // Delete images from AWS S3
+ for (const imageUrl of imageUrls) {
+ const imageKey = imageUrl.split('/').pop();
+ if (imageKey.length !== 0) {
+ const information = {
+ Bucket: 'gradgoodsimages',
+ Key: imageKey,
+ };
+ await s3.deleteObject(information).promise();
+ }
+ }
+
+ // // Update the local state to remove the deleted listing
+ // const updatedListings = allListings.filter(listing => listing.id !== id);
+
+ // // Update the user's listings if called from Profile to re-render the listings joined by the user
+ // if (changeUserListing) {
+ // await changeUserListing(updatedListings);
+ // }
+ // else{
+ // await refreshListing(updatedListings);
+ // }
+
+ } catch (error) {
+ console.error('Error deleting listing:', error);
+ } finally {
+ // setLoading(false);
+ // setConfirm(false);
+ }
+};
+
return (
{
${item.price}
+