+
removeFromFavorites(item.id)}
className="absolute top-2 right-2 p-1 bg-white rounded-full shadow-sm text-red-500 hover:bg-red-50"
@@ -123,28 +181,38 @@ const Favorites = () => {
>
-
+
-
-
+
+
{item.title}
- ${item.price}
+
+ ${item.price}
+
-
+
{item.category}
•
{item.condition}
-
+
- Listed {item.datePosted}
- {item.seller}
+
+ Listed {item.datePosted}
+
+
+ {item.seller}
+
@@ -156,12 +224,13 @@ const Favorites = () => {
{/* Show count if there are favorites */}
{filteredFavorites.length > 0 && (
- Showing {filteredFavorites.length} {filteredFavorites.length === 1 ? 'item' : 'items'}
- {filterCategory !== 'All' && ` in ${filterCategory}`}
+ Showing {filteredFavorites.length}{" "}
+ {filteredFavorites.length === 1 ? "item" : "items"}
+ {filterCategory !== "All" && ` in ${filterCategory}`}
)}
);
};
-export default Favorites;
\ No newline at end of file
+export default Favorites;
diff --git a/frontend/src/pages/Selling.jsx b/frontend/src/pages/Selling.jsx
index 1ed5fdf..3495698 100644
--- a/frontend/src/pages/Selling.jsx
+++ b/frontend/src/pages/Selling.jsx
@@ -1,13 +1,155 @@
-import { useState } from 'react';
-import { Link } from 'react-router-dom';
-import { Tag, Book, Laptop, Sofa, Utensils, Gift, Heart } from 'lucide-react';
+import { useState } from "react";
+import { Pencil, Trash2, Plus } from "lucide-react";
+import ProductForm from "../components/ProductForm";
const Selling = () => {
+ const [products, setProducts] = useState([
+ {
+ id: 1,
+ name: "Green Sofa",
+ price: 299,
+ status: "Active",
+ images: [],
+ },
+ {
+ id: 2,
+ name: "Wooden Table",
+ price: 150,
+ status: "Inactive",
+ images: [],
+ },
+ ]);
+
+ const [editingProduct, setEditingProduct] = useState(null);
+ const [view, setView] = useState("list"); // "list" or "form"
+
+ const handleEdit = (product) => {
+ setEditingProduct({ ...product });
+ setView("form");
+ };
+
+ const handleAddNew = () => {
+ setEditingProduct({
+ id: null,
+ name: "",
+ price: "",
+ status: "Active",
+ images: [],
+ });
+ setView("form");
+ };
+
+ const handleDelete = (id) => {
+ setProducts((prev) => prev.filter((p) => p.id !== id));
+ };
+
+ const handleSave = () => {
+ if (!editingProduct.name || !editingProduct.price) {
+ alert("Please enter a name and price.");
+ return;
+ }
+ if (editingProduct.images.length < 1) {
+ alert("Please upload at least one image.");
+ return;
+ }
+
+ if (editingProduct.id === null) {
+ const newProduct = {
+ ...editingProduct,
+ id: Date.now(),
+ };
+ setProducts((prev) => [newProduct, ...prev]);
+ } else {
+ setProducts((prev) =>
+ prev.map((p) => (p.id === editingProduct.id ? editingProduct : p)),
+ );
+ }
+
+ setEditingProduct(null);
+ setView("list");
+ };
+
+ const handleCancel = () => {
+ setEditingProduct(null);
+ setView("list");
+ };
+
return (
-
-
+
+ {view === "list" && (
+ <>
+
+
My Listings
+
+ Add New Product
+
+
+
+
+ {products.map((product) => (
+
+
+
+ {product.images.length > 0 ? (
+
+ ) : (
+
No Image
+ )}
+
+
+
{product.name}
+
${product.price}
+
+ {product.status}
+
+
+
+
+
handleEdit(product)}
+ className="text-blue-600 hover:underline"
+ >
+
+
+
handleDelete(product.id)}
+ className="text-red-500 hover:underline"
+ >
+
+
+
+
+ ))}
+
+ >
+ )}
+
+ {view === "form" && (
+
+ )}
);
};
-export default Selling;
\ No newline at end of file
+export default Selling;
diff --git a/mysql-code/Schema.sql b/mysql-code/Schema.sql
index 7f94d78..8ac0497 100644
--- a/mysql-code/Schema.sql
+++ b/mysql-code/Schema.sql
@@ -102,7 +102,7 @@ CREATE TABLE Favorites (
ProductID INT,
FOREIGN KEY (UserID) REFERENCES User (UserID),
FOREIGN KEY (ProductID) REFERENCES Product (ProductID),
- UNIQUE (UserID, ProductID) -- Prevents duplicate favorites
+ UNIQUE (UserID, ProductID)
);
-- Product-Category Junction Table (Many-to-Many)