updating frontend code
This commit is contained in:
@@ -52,6 +52,11 @@ function App() {
|
|||||||
return () => window.removeEventListener("resize", handleResize);
|
return () => window.removeEventListener("resize", handleResize);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
sendSessionDataToServer();
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Send verification code
|
// Send verification code
|
||||||
const sendVerificationCode = async (userData) => {
|
const sendVerificationCode = async (userData) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ const Navbar = ({ onLogout, userName }) => {
|
|||||||
alt="Campus Plug"
|
alt="Campus Plug"
|
||||||
className="h-8 px-2"
|
className="h-8 px-2"
|
||||||
/>
|
/>
|
||||||
<span className="hidden md:block [color:#009966] font-bold text-xl">
|
<span className="hidden md:block text-green-500 font-bold text-xl">
|
||||||
Campus Plug
|
Campus Plug
|
||||||
</span>
|
</span>
|
||||||
</Link>
|
</Link>
|
||||||
@@ -48,7 +48,7 @@ const Navbar = ({ onLogout, userName }) => {
|
|||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Search for anything..."
|
placeholder="Search for anything..."
|
||||||
className="w-full p-2 pl-10 pr-4 border border-gray-300 focus:outline-none focus:border-green-500 focus:ring-1 focus:ring-green-500"
|
className="w-full p-2 pl-10 pr-4 border border-gray-300 focus:outline-none focus:border-[#ed7f30]-500 focus:ring-1 focus:ring-[#ed7f30]-500"
|
||||||
value={searchQuery}
|
value={searchQuery}
|
||||||
onChange={handleSearchChange}
|
onChange={handleSearchChange}
|
||||||
/>
|
/>
|
||||||
@@ -57,7 +57,7 @@ const Navbar = ({ onLogout, userName }) => {
|
|||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
className="absolute inset-y-0 right-0 flex items-center px-3 text-gray-500 hover:text-green-500"
|
className="absolute inset-y-0 right-0 flex items-center px-3 text-gray-500 hover:text-[#ed7f30]-500"
|
||||||
>
|
>
|
||||||
Search
|
Search
|
||||||
</button>
|
</button>
|
||||||
@@ -70,7 +70,7 @@ const Navbar = ({ onLogout, userName }) => {
|
|||||||
{/* Favorites Button */}
|
{/* Favorites Button */}
|
||||||
<Link
|
<Link
|
||||||
to="/favorites"
|
to="/favorites"
|
||||||
className="p-2 text-gray-600 hover:text-green-600"
|
className="p-2 text-gray-600 hover:text-[#ed7f30]-600"
|
||||||
>
|
>
|
||||||
<Heart className="h-6 w-6" />
|
<Heart className="h-6 w-6" />
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
|
import { X, ChevronLeft, Plus, Trash2 } from "lucide-react";
|
||||||
|
|
||||||
const ProductForm = ({
|
const ProductForm = ({
|
||||||
editingProduct,
|
editingProduct,
|
||||||
@@ -50,63 +51,64 @@ const ProductForm = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-white border-2 border-gray-200 rounded-md p-6 shadow-lg">
|
<div className="bg-white border border-gray-200 shadow-md p-6">
|
||||||
{/* Back Button */}
|
{/* Back Button */}
|
||||||
<button
|
<button
|
||||||
onClick={onCancel}
|
onClick={onCancel}
|
||||||
className="mb-4 text-sm text-emerald-600 hover:text-emerald-800 flex items-center font-medium"
|
className="mb-4 text-blue-600 hover:text-blue-800 flex items-center gap-1"
|
||||||
>
|
>
|
||||||
← Back to Listings
|
<ChevronLeft size={16} />
|
||||||
|
<span>Back to Listings</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<h3 className="text-xl font-bold text-gray-800 mb-6 border-b-2 border-gray-100 pb-3">
|
<h3 className="text-xl font-bold text-gray-800 mb-6 border-b border-gray-200 pb-3">
|
||||||
{editingProduct?.id ? "Edit Your Product" : "List a New Product"}
|
{editingProduct?.id ? "Edit Your Product" : "List a New Product"}
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
{/* Product Name */}
|
{/* Product Name */}
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
Product Name
|
Product Name
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={editingProduct.name}
|
value={editingProduct.name || ""}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setEditingProduct({ ...editingProduct, name: e.target.value })
|
setEditingProduct({ ...editingProduct, name: e.target.value })
|
||||||
}
|
}
|
||||||
className="w-full px-4 py-2 border-2 border-gray-200 rounded-md focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500"
|
className="w-full px-3 py-2 border border-gray-300 focus:border-blue-500 focus:outline-none"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Price */}
|
{/* Price */}
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
Price ($)
|
Price ($)
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
value={editingProduct.price}
|
value={editingProduct.price || ""}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setEditingProduct({
|
setEditingProduct({
|
||||||
...editingProduct,
|
...editingProduct,
|
||||||
price: e.target.value,
|
price: e.target.value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
className="w-full px-4 py-2 border-2 border-gray-200 rounded-md focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500"
|
className="w-full px-3 py-2 border border-gray-300 focus:border-blue-500 focus:outline-none"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Categories - Dropdown with Add button */}
|
{/* Categories */}
|
||||||
<div className="md:col-span-2">
|
<div className="md:col-span-2">
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
Categories
|
Categories
|
||||||
</label>
|
</label>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<select
|
<select
|
||||||
value={selectedCategory}
|
value={selectedCategory}
|
||||||
onChange={(e) => setSelectedCategory(e.target.value)}
|
onChange={(e) => setSelectedCategory(e.target.value)}
|
||||||
className="flex-1 px-4 py-2 border-2 border-gray-200 rounded-md focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500"
|
className="flex-1 px-3 py-2 border border-gray-300 focus:border-blue-500 focus:outline-none"
|
||||||
>
|
>
|
||||||
<option value="" disabled>
|
<option value="" disabled>
|
||||||
Select a category
|
Select a category
|
||||||
@@ -125,61 +127,62 @@ const ProductForm = ({
|
|||||||
type="button"
|
type="button"
|
||||||
onClick={addCategory}
|
onClick={addCategory}
|
||||||
disabled={!selectedCategory}
|
disabled={!selectedCategory}
|
||||||
className="px-4 py-2 bg-emerald-600 text-white rounded-md hover:bg-emerald-700 disabled:bg-gray-300 disabled:cursor-not-allowed"
|
className="px-3 py-2 bg-blue-600 text-white hover:bg-blue-700 disabled:bg-gray-300 disabled:cursor-not-allowed flex items-center gap-1"
|
||||||
>
|
>
|
||||||
Add
|
<Plus size={16} />
|
||||||
|
<span>Add</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Selected Categories */}
|
{/* Selected Categories */}
|
||||||
{(editingProduct.categories || []).length > 0 ? (
|
{(editingProduct.categories || []).length > 0 ? (
|
||||||
<div className="mt-3 flex flex-wrap gap-2">
|
<div className="mt-2 flex flex-wrap gap-2">
|
||||||
{(editingProduct.categories || []).map((category) => (
|
{(editingProduct.categories || []).map((category) => (
|
||||||
<span
|
<span
|
||||||
key={category}
|
key={category}
|
||||||
className="inline-flex items-center px-3 py-1 rounded-md text-sm font-medium bg-emerald-100 text-emerald-800"
|
className="inline-flex items-center px-2 py-1 bg-blue-100 text-blue-800"
|
||||||
>
|
>
|
||||||
{category}
|
{category}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => removeCategory(category)}
|
onClick={() => removeCategory(category)}
|
||||||
className="ml-2 text-emerald-600 hover:text-emerald-800"
|
className="ml-1 text-blue-600 hover:text-blue-800"
|
||||||
>
|
>
|
||||||
×
|
<X size={14} />
|
||||||
</button>
|
</button>
|
||||||
</span>
|
</span>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-xs text-gray-500 mt-2">
|
<p className="text-xs text-gray-500 mt-1">
|
||||||
Please select at least one category
|
Please select at least one category
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Status - Updated to Unsold/Sold */}
|
{/* Status */}
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
Status
|
Status
|
||||||
</label>
|
</label>
|
||||||
<select
|
<select
|
||||||
value={editingProduct.status}
|
value={editingProduct.status || "Unsold"}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setEditingProduct({
|
setEditingProduct({
|
||||||
...editingProduct,
|
...editingProduct,
|
||||||
status: e.target.value,
|
status: e.target.value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
className="w-full px-4 py-2 border-2 border-gray-200 rounded-md focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500"
|
className="w-full px-3 py-2 border border-gray-300 focus:border-blue-500 focus:outline-none"
|
||||||
>
|
>
|
||||||
<option value="Unsold">Unsold</option>
|
<option value="Unsold">Unsold</option>
|
||||||
<option value="Sold">Sold</option>
|
<option value="Sold">Sold</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Description - New Field */}
|
{/* Description */}
|
||||||
<div className="md:col-span-2">
|
<div className="md:col-span-2">
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
Description
|
Description
|
||||||
</label>
|
</label>
|
||||||
<textarea
|
<textarea
|
||||||
@@ -191,19 +194,17 @@ const ProductForm = ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
rows="4"
|
rows="4"
|
||||||
className="w-full px-4 py-2 border-2 border-gray-200 rounded-md focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500"
|
className="w-full px-3 py-2 border border-gray-300 focus:border-blue-500 focus:outline-none"
|
||||||
placeholder="Describe your product in detail..."
|
placeholder="Describe your product in detail..."
|
||||||
></textarea>
|
></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Simplified Image Upload */}
|
{/* Image Upload */}
|
||||||
<div className="md:col-span-2">
|
<div className="md:col-span-2">
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
Product Images{" "}
|
Product Images <span className="text-gray-500">(Max 5)</span>
|
||||||
<span className="text-gray-500 text-sm">(Max 5)</span>
|
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
{/* Simple file input */}
|
|
||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
accept="image/*"
|
accept="image/*"
|
||||||
@@ -212,7 +213,7 @@ const ProductForm = ({
|
|||||||
const files = Array.from(e.target.files).slice(0, 5);
|
const files = Array.from(e.target.files).slice(0, 5);
|
||||||
setEditingProduct((prev) => ({
|
setEditingProduct((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
images: [...prev.images, ...files].slice(0, 5),
|
images: [...(prev.images || []), ...files].slice(0, 5),
|
||||||
}));
|
}));
|
||||||
}}
|
}}
|
||||||
className="hidden"
|
className="hidden"
|
||||||
@@ -220,30 +221,41 @@ const ProductForm = ({
|
|||||||
/>
|
/>
|
||||||
<label
|
<label
|
||||||
htmlFor="image-upload"
|
htmlFor="image-upload"
|
||||||
className="block w-full p-3 border-2 border-dashed border-emerald-200 bg-emerald-50 rounded-md text-center cursor-pointer hover:bg-emerald-100 transition-colors"
|
className="block w-full p-3 border border-gray-300 bg-gray-50 text-center cursor-pointer hover:bg-gray-100"
|
||||||
>
|
>
|
||||||
<span className="text-emerald-700 font-medium">
|
<span className="text-blue-600 font-medium">
|
||||||
Click to upload images
|
Click to upload images
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
{/* Image previews */}
|
{/* Image previews */}
|
||||||
{editingProduct.images.length > 0 && (
|
{(editingProduct.images || []).length > 0 && (
|
||||||
<div className="mt-4">
|
<div className="mt-3">
|
||||||
<p className="text-sm text-gray-600 mb-2">
|
<div className="flex justify-between items-center mb-2">
|
||||||
|
<p className="text-sm text-gray-600">
|
||||||
{editingProduct.images.length}{" "}
|
{editingProduct.images.length}{" "}
|
||||||
{editingProduct.images.length === 1 ? "image" : "images"}{" "}
|
{editingProduct.images.length === 1 ? "image" : "images"}{" "}
|
||||||
selected
|
selected
|
||||||
</p>
|
</p>
|
||||||
<div className="flex flex-wrap gap-3">
|
<button
|
||||||
|
onClick={() =>
|
||||||
|
setEditingProduct((prev) => ({ ...prev, images: [] }))
|
||||||
|
}
|
||||||
|
className="text-sm text-red-600 hover:text-red-800 flex items-center gap-1"
|
||||||
|
>
|
||||||
|
<Trash2 size={14} />
|
||||||
|
<span>Clear all</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
{editingProduct.images.map((img, idx) => (
|
{editingProduct.images.map((img, idx) => (
|
||||||
<div
|
<div
|
||||||
key={idx}
|
key={idx}
|
||||||
className="relative w-20 h-20 border-2 border-gray-200 rounded-md overflow-hidden"
|
className="relative w-20 h-20 border border-gray-200 overflow-hidden"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
src={URL.createObjectURL(img)}
|
src={URL.createObjectURL(img)}
|
||||||
alt={`Product image ${idx + 1}`}
|
alt={`Product ${idx + 1}`}
|
||||||
className="w-full h-full object-cover"
|
className="w-full h-full object-cover"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
@@ -256,22 +268,11 @@ const ProductForm = ({
|
|||||||
}));
|
}));
|
||||||
}}
|
}}
|
||||||
className="absolute top-0 right-0 bg-white bg-opacity-80 w-6 h-6 flex items-center justify-center text-gray-700 hover:text-red-600"
|
className="absolute top-0 right-0 bg-white bg-opacity-80 w-6 h-6 flex items-center justify-center text-gray-700 hover:text-red-600"
|
||||||
title="Remove image"
|
|
||||||
>
|
>
|
||||||
×
|
<X size={14} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
{editingProduct.images.length > 0 && (
|
|
||||||
<button
|
|
||||||
onClick={() =>
|
|
||||||
setEditingProduct((prev) => ({ ...prev, images: [] }))
|
|
||||||
}
|
|
||||||
className="text-sm text-red-600 hover:text-red-800 mt-2"
|
|
||||||
>
|
|
||||||
Clear all
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -279,16 +280,16 @@ const ProductForm = ({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Actions */}
|
{/* Actions */}
|
||||||
<div className="mt-8 flex justify-end gap-4 border-t-2 border-gray-100 pt-4">
|
<div className="mt-6 flex justify-end gap-3 border-t border-gray-200 pt-4">
|
||||||
<button
|
<button
|
||||||
onClick={onCancel}
|
onClick={onCancel}
|
||||||
className="bg-gray-100 text-gray-700 px-6 py-2 rounded-md hover:bg-gray-200 font-medium"
|
className="bg-gray-100 text-gray-700 px-4 py-2 hover:bg-gray-200"
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={onSave}
|
onClick={onSave}
|
||||||
className="bg-emerald-600 text-white px-8 py-2 rounded-md hover:bg-emerald-700 font-medium"
|
className="bg-blue-600 text-white px-6 py-2 hover:bg-blue-700"
|
||||||
>
|
>
|
||||||
{editingProduct.id ? "Update Product" : "Add Product"}
|
{editingProduct.id ? "Update Product" : "Add Product"}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useState, useRef, useEffect } from 'react';
|
import { useState, useRef, useEffect } from "react";
|
||||||
import { Link, useNavigate } from 'react-router-dom';
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
import { User, Settings, ShoppingBag, DollarSign, LogOut } from 'lucide-react';
|
import { User, Settings, ShoppingBag, DollarSign, LogOut } from "lucide-react";
|
||||||
|
|
||||||
const UserDropdown = ({ onLogout, userName }) => {
|
const UserDropdown = ({ onLogout, userName }) => {
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
@@ -8,7 +8,7 @@ const UserDropdown = ({ onLogout, userName }) => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
// Use passed userName or fallback to default
|
// Use passed userName or fallback to default
|
||||||
const displayName = userName || 'User';
|
const displayName = userName || "User";
|
||||||
|
|
||||||
const toggleDropdown = () => {
|
const toggleDropdown = () => {
|
||||||
setIsOpen(!isOpen);
|
setIsOpen(!isOpen);
|
||||||
@@ -22,9 +22,9 @@ const UserDropdown = ({ onLogout, userName }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
document.addEventListener('mousedown', handleClickOutside);
|
document.addEventListener("mousedown", handleClickOutside);
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener('mousedown', handleClickOutside);
|
document.removeEventListener("mousedown", handleClickOutside);
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ const UserDropdown = ({ onLogout, userName }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Navigate to login page (this may be redundant as App.jsx should handle redirection)
|
// Navigate to login page (this may be redundant as App.jsx should handle redirection)
|
||||||
navigate('/login');
|
navigate("/login");
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,34 +1,24 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { Heart, Tag, Trash2 } from "lucide-react";
|
import { Heart, Trash2 } from "lucide-react";
|
||||||
|
|
||||||
const Favorites = () => {
|
const Favorites = () => {
|
||||||
const [favorites, setFavorites] = useState([]);
|
const [favorites, setFavorites] = useState([]);
|
||||||
const [showFilters, setShowFilters] = useState(false);
|
|
||||||
const [sortBy, setSortBy] = useState("dateAdded");
|
const [sortBy, setSortBy] = useState("dateAdded");
|
||||||
const [filterCategory, setFilterCategory] = useState("All");
|
|
||||||
const storedUser = JSON.parse(sessionStorage.getItem("user"));
|
const storedUser = JSON.parse(sessionStorage.getItem("user"));
|
||||||
|
|
||||||
const mapCategory = (id) => {
|
|
||||||
const categories = {
|
|
||||||
1: "Electronics",
|
|
||||||
2: "Textbooks",
|
|
||||||
3: "Furniture",
|
|
||||||
4: "Clothing",
|
|
||||||
5: "Kitchen",
|
|
||||||
6: "Other",
|
|
||||||
};
|
|
||||||
return categories[id] || "Other";
|
|
||||||
};
|
|
||||||
|
|
||||||
function reloadPage() {
|
function reloadPage() {
|
||||||
var doctTimestamp = new Date(performance.timing.domLoading).getTime();
|
const docTimestamp = new Date(performance.timing.domLoading).getTime();
|
||||||
var now = Date.now();
|
const now = Date.now();
|
||||||
if (now > doctTimestamp) {
|
if (now > docTimestamp) {
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mapCategory = (id) => {
|
||||||
|
return id || "Other";
|
||||||
|
};
|
||||||
|
|
||||||
const removeFromFavorites = async (itemID) => {
|
const removeFromFavorites = async (itemID) => {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
"http://localhost:3030/api/product/delFavorite",
|
"http://localhost:3030/api/product/delFavorite",
|
||||||
@@ -43,14 +33,13 @@ const Favorites = () => {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
reloadPage();
|
reloadPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response.ok) throw new Error("Failed to fetch products");
|
if (!response.ok) throw new Error("Failed to remove from favorites");
|
||||||
console.log(response);
|
|
||||||
console.log(`Add Product -> History: ${itemID}`);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -68,7 +57,6 @@ const Favorites = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
const favoritesData = data.favorites;
|
const favoritesData = data.favorites;
|
||||||
|
|
||||||
if (!Array.isArray(favoritesData)) {
|
if (!Array.isArray(favoritesData)) {
|
||||||
@@ -78,10 +66,11 @@ const Favorites = () => {
|
|||||||
|
|
||||||
const transformed = favoritesData.map((item) => ({
|
const transformed = favoritesData.map((item) => ({
|
||||||
id: item.ProductID,
|
id: item.ProductID,
|
||||||
title: item.Name,
|
name: item.Name,
|
||||||
price: parseFloat(item.Price),
|
price: parseFloat(item.Price),
|
||||||
category: mapCategory(item.CategoryID),
|
categories: [mapCategory(item.Category)],
|
||||||
image: item.image_url || "/default-image.jpg",
|
image: item.image_url || "/default-image.jpg",
|
||||||
|
description: item.Description || "",
|
||||||
seller: item.SellerName,
|
seller: item.SellerName,
|
||||||
datePosted: formatDatePosted(item.Date),
|
datePosted: formatDatePosted(item.Date),
|
||||||
dateAdded: item.Date || new Date().toISOString(),
|
dateAdded: item.Date || new Date().toISOString(),
|
||||||
@@ -112,19 +101,13 @@ const Favorites = () => {
|
|||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
const filteredFavorites =
|
|
||||||
filterCategory === "All"
|
|
||||||
? sortedFavorites
|
|
||||||
: sortedFavorites.filter((item) => item.category === filterCategory);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="max-w-6xl mx-auto">
|
<div className="max-w-6xl mx-auto">
|
||||||
<div className="flex justify-between items-center mb-6">
|
<div className="flex justify-between items-center mb-6">
|
||||||
<h1 className="text-2xl font-bold text-gray-800">My Favorites</h1>
|
<h1 className="text-2xl font-bold text-gray-800">My Favorites</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Favorites List */}
|
{sortedFavorites.length === 0 ? (
|
||||||
{filteredFavorites.length === 0 ? (
|
|
||||||
<div className="bg-white border border-gray-200 p-8 text-center">
|
<div className="bg-white border border-gray-200 p-8 text-center">
|
||||||
<Heart className="h-12 w-12 text-gray-300 mx-auto mb-4" />
|
<Heart className="h-12 w-12 text-gray-300 mx-auto mb-4" />
|
||||||
<h3 className="text-xl font-medium text-gray-700 mb-2">
|
<h3 className="text-xl font-medium text-gray-700 mb-2">
|
||||||
@@ -142,50 +125,62 @@ const Favorites = () => {
|
|||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
{filteredFavorites.map((item) => (
|
{sortedFavorites.map((product) => (
|
||||||
<div
|
<div
|
||||||
key={item.id}
|
key={product.id}
|
||||||
className="bg-white border border-gray-200 hover:shadow-md transition-shadow relative"
|
className="border-2 border-gray-200 rounded overflow-hidden hover:shadow-md transition-shadow"
|
||||||
>
|
>
|
||||||
<button
|
<Link to={`/product/${product.id}`}>
|
||||||
onClick={() => removeFromFavorites(item.id)}
|
<div className="h-48 bg-gray-200 flex items-center justify-center">
|
||||||
className="absolute top-2 right-2 p-1 bg-white rounded-full shadow-sm text-red-500 hover:bg-red-50"
|
{product.image ? (
|
||||||
title="Remove from favorites"
|
|
||||||
>
|
|
||||||
<Trash2 className="h-5 w-5" />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<Link to={`/product/${item.id}`}>
|
|
||||||
<img
|
<img
|
||||||
src={item.image}
|
src={product.image}
|
||||||
alt={item.title}
|
alt={product.name}
|
||||||
className="w-full h-48 object-cover"
|
className="w-full h-full object-cover"
|
||||||
/>
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="text-gray-400">No image</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
<div className="flex justify-between items-start mb-2">
|
<div className="flex justify-between items-start">
|
||||||
<h3 className="text-lg font-medium text-gray-800 leading-tight">
|
<h3 className="text-lg font-semibold text-gray-800">
|
||||||
{item.title}
|
{product.name}
|
||||||
</h3>
|
</h3>
|
||||||
<span className="font-semibold text-green-600">
|
<button
|
||||||
${item.price}
|
onClick={() => removeFromFavorites(product.id)}
|
||||||
</span>
|
className="text-red-500 hover:text-red-600"
|
||||||
|
>
|
||||||
|
<Trash2 size={18} />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center text-sm text-gray-500 mb-3">
|
<p className="text-emerald-600 font-bold mt-1">
|
||||||
<Tag className="h-4 w-4 mr-1" />
|
${product.price.toFixed(2)}
|
||||||
<span>{item.category}</span>
|
</p>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex justify-between items-center pt-2 border-t border-gray-100">
|
{product.categories.length > 0 && (
|
||||||
<span className="text-xs text-gray-500">
|
<div className="mt-2 flex flex-wrap gap-1">
|
||||||
Listed {item.datePosted}
|
{product.categories.map((category) => (
|
||||||
</span>
|
<span
|
||||||
<span className="text-sm font-medium text-gray-700">
|
key={category}
|
||||||
{item.seller}
|
className="text-xs bg-gray-100 text-gray-600 px-2 py-1"
|
||||||
|
>
|
||||||
|
{category}
|
||||||
</span>
|
</span>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<p className="text-gray-500 text-sm mt-2 line-clamp-2">
|
||||||
|
{product.description}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p className="text-gray-400 text-xs mt-2">
|
||||||
|
Posted {product.datePosted}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
@@ -193,14 +188,66 @@ const Favorites = () => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Show count if there are favorites */}
|
{sortedFavorites.length > 0 && (
|
||||||
{filteredFavorites.length > 0 && (
|
|
||||||
<div className="mt-6 text-sm text-gray-500">
|
<div className="mt-6 text-sm text-gray-500">
|
||||||
Showing {filteredFavorites.length}{" "}
|
Showing {sortedFavorites.length}{" "}
|
||||||
{filteredFavorites.length === 1 ? "item" : "items"}
|
{sortedFavorites.length === 1 ? "item" : "items"}
|
||||||
{filterCategory !== "All" && ` in ${filterCategory}`}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<footer className="bg-gray-800 text-white py-6 mt-12">
|
||||||
|
<div className="container mx-auto px-4">
|
||||||
|
<div className="flex flex-col md:flex-row justify-between items-center">
|
||||||
|
<div className="mb-4 md:mb-0">
|
||||||
|
<h3 className="text-lg font-semibold mb-2">Campus Marketplace</h3>
|
||||||
|
<p className="text-gray-400 text-sm">
|
||||||
|
Your trusted university trading platform
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex space-x-6">
|
||||||
|
<div>
|
||||||
|
<h4 className="font-medium mb-2">Quick Links</h4>
|
||||||
|
<ul className="text-sm text-gray-400">
|
||||||
|
<li className="mb-1">
|
||||||
|
<Link to="/" className="hover:text-white transition">
|
||||||
|
Home
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
<li className="mb-1">
|
||||||
|
<Link to="/selling" className="hover:text-white transition">
|
||||||
|
Sell an Item
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
<li className="mb-1">
|
||||||
|
<Link
|
||||||
|
to="/favorites"
|
||||||
|
className="hover:text-white transition"
|
||||||
|
>
|
||||||
|
My Favorites
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h4 className="font-medium mb-2">Contact</h4>
|
||||||
|
<ul className="text-sm text-gray-400">
|
||||||
|
<li className="mb-1">support@campusmarket.com</li>
|
||||||
|
<li className="mb-1">University of Calgary</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="border-t border-gray-700 mt-6 pt-6 text-center text-sm text-gray-400">
|
||||||
|
<p>
|
||||||
|
© {new Date().getFullYear()} Campus Marketplace. All rights
|
||||||
|
reserved.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
import { Tag } from "lucide-react";
|
import { Tag, ChevronLeft, ChevronRight } from "lucide-react";
|
||||||
|
|
||||||
import FloatingAlert from "../components/FloatingAlert"; // adjust path if needed
|
import FloatingAlert from "../components/FloatingAlert"; // adjust path if needed
|
||||||
|
|
||||||
@@ -15,7 +15,6 @@ const Home = () => {
|
|||||||
//After user data storing the session.
|
//After user data storing the session.
|
||||||
const storedUser = JSON.parse(sessionStorage.getItem("user"));
|
const storedUser = JSON.parse(sessionStorage.getItem("user"));
|
||||||
|
|
||||||
|
|
||||||
const toggleFavorite = async (id) => {
|
const toggleFavorite = async (id) => {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
"http://localhost:3030/api/product/addFavorite",
|
"http://localhost:3030/api/product/addFavorite",
|
||||||
@@ -187,7 +186,8 @@ const Home = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="flex flex-col min-h-screen">
|
||||||
|
<div className="flex-grow">
|
||||||
{/* Hero Section with School Background */}
|
{/* Hero Section with School Background */}
|
||||||
<div className="relative py-12 px-4 mb-8 shadow-sm">
|
<div className="relative py-12 px-4 mb-8 shadow-sm">
|
||||||
{/* Background Image - Positioned at bottom */}
|
{/* Background Image - Positioned at bottom */}
|
||||||
@@ -206,8 +206,8 @@ const Home = () => {
|
|||||||
Buy and Sell on Campus
|
Buy and Sell on Campus
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-white mb-6">
|
<p className="text-white mb-6">
|
||||||
The marketplace exclusively for university students. Find everything
|
The marketplace exclusively for university students. Find
|
||||||
you need or sell what you don't.
|
everything you need or sell what you don't.
|
||||||
</p>
|
</p>
|
||||||
<button
|
<button
|
||||||
onClick={handleSelling}
|
onClick={handleSelling}
|
||||||
@@ -240,7 +240,7 @@ const Home = () => {
|
|||||||
}
|
}
|
||||||
className="absolute left-0 top-1/2 transform -translate-y-1/2 bg-gray-800 bg-opacity-70 text-white p-4 rounded-full z-20 hidden md:flex items-center justify-center w-12 h-12"
|
className="absolute left-0 top-1/2 transform -translate-y-1/2 bg-gray-800 bg-opacity-70 text-white p-4 rounded-full z-20 hidden md:flex items-center justify-center w-12 h-12"
|
||||||
>
|
>
|
||||||
◀
|
<ChevronLeft size={24} />{" "}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{/* Scrollable Listings Container */}
|
{/* Scrollable Listings Container */}
|
||||||
@@ -308,7 +308,7 @@ const Home = () => {
|
|||||||
}
|
}
|
||||||
className="absolute right-0 top-1/2 transform -translate-y-1/2 bg-gray-800 bg-opacity-70 text-white p-4 rounded-full z-20 hidden md:flex items-center justify-center w-12 h-12"
|
className="absolute right-0 top-1/2 transform -translate-y-1/2 bg-gray-800 bg-opacity-70 text-white p-4 rounded-full z-20 hidden md:flex items-center justify-center w-12 h-12"
|
||||||
>
|
>
|
||||||
▶
|
<ChevronRight size={24} />{" "}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -335,7 +335,7 @@ const Home = () => {
|
|||||||
}
|
}
|
||||||
className="absolute left-0 top-1/2 transform -translate-y-1/2 bg-gray-800 bg-opacity-70 text-white p-4 rounded-full z-20 hidden md:flex items-center justify-center w-12 h-12"
|
className="absolute left-0 top-1/2 transform -translate-y-1/2 bg-gray-800 bg-opacity-70 text-white p-4 rounded-full z-20 hidden md:flex items-center justify-center w-12 h-12"
|
||||||
>
|
>
|
||||||
◀
|
<ChevronLeft size={24} />{" "}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{/* Scrollable Listings Container */}
|
{/* Scrollable Listings Container */}
|
||||||
@@ -403,12 +403,12 @@ const Home = () => {
|
|||||||
}
|
}
|
||||||
className="absolute right-0 top-1/2 transform -translate-y-1/2 bg-gray-800 bg-opacity-70 text-white p-4 rounded-full z-20 hidden md:flex items-center justify-center w-12 h-12"
|
className="absolute right-0 top-1/2 transform -translate-y-1/2 bg-gray-800 bg-opacity-70 text-white p-4 rounded-full z-20 hidden md:flex items-center justify-center w-12 h-12"
|
||||||
>
|
>
|
||||||
▶
|
<ChevronRight size={24} />{" "}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Recent Listings */}
|
{/* History Section */}
|
||||||
{showAlert && (
|
{showAlert && (
|
||||||
<FloatingAlert
|
<FloatingAlert
|
||||||
message="Product added to favorites!"
|
message="Product added to favorites!"
|
||||||
@@ -428,7 +428,7 @@ const Home = () => {
|
|||||||
}
|
}
|
||||||
className="absolute left-0 top-1/2 transform -translate-y-1/2 bg-gray-800 bg-opacity-70 text-white p-4 rounded-full z-20 hidden md:flex items-center justify-center w-12 h-12"
|
className="absolute left-0 top-1/2 transform -translate-y-1/2 bg-gray-800 bg-opacity-70 text-white p-4 rounded-full z-20 hidden md:flex items-center justify-center w-12 h-12"
|
||||||
>
|
>
|
||||||
◀
|
<ChevronLeft size={24} />{" "}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{/* Scrollable Listings Container */}
|
{/* Scrollable Listings Container */}
|
||||||
@@ -495,11 +495,67 @@ const Home = () => {
|
|||||||
}
|
}
|
||||||
className="absolute right-0 top-1/2 transform -translate-y-1/2 bg-gray-800 bg-opacity-70 text-white p-4 rounded-full z-20 hidden md:flex items-center justify-center w-12 h-12"
|
className="absolute right-0 top-1/2 transform -translate-y-1/2 bg-gray-800 bg-opacity-70 text-white p-4 rounded-full z-20 hidden md:flex items-center justify-center w-12 h-12"
|
||||||
>
|
>
|
||||||
▶
|
<ChevronRight size={24} />{" "}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Footer - Added here */}
|
||||||
|
<footer className="bg-gray-800 text-white py-6 mt-12">
|
||||||
|
<div className="container mx-auto px-4">
|
||||||
|
<div className="flex flex-col md:flex-row justify-between items-center">
|
||||||
|
<div className="mb-4 md:mb-0">
|
||||||
|
<h3 className="text-lg font-semibold mb-2">Campus Marketplace</h3>
|
||||||
|
<p className="text-gray-400 text-sm">
|
||||||
|
Your trusted university trading platform
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex space-x-6">
|
||||||
|
<div>
|
||||||
|
<h4 className="font-medium mb-2">Quick Links</h4>
|
||||||
|
<ul className="text-sm text-gray-400">
|
||||||
|
<li className="mb-1">
|
||||||
|
<Link to="/" className="hover:text-white transition">
|
||||||
|
Home
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
<li className="mb-1">
|
||||||
|
<Link to="/selling" className="hover:text-white transition">
|
||||||
|
Sell an Item
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
<li className="mb-1">
|
||||||
|
<Link
|
||||||
|
to="/favorites"
|
||||||
|
className="hover:text-white transition"
|
||||||
|
>
|
||||||
|
My Favorites
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h4 className="font-medium mb-2">Contact</h4>
|
||||||
|
<ul className="text-sm text-gray-400">
|
||||||
|
<li className="mb-1">support@campusmarket.com</li>
|
||||||
|
<li className="mb-1">University of Calgary</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="border-t border-gray-700 mt-6 pt-6 text-center text-sm text-gray-400">
|
||||||
|
<p>
|
||||||
|
© {new Date().getFullYear()} Campus Marketplace. All rights
|
||||||
|
reserved.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import {
|
|||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import FloatingAlert from "../components/FloatingAlert"; // adjust path if needed
|
import FloatingAlert from "../components/FloatingAlert"; // adjust path if needed
|
||||||
|
|
||||||
|
|
||||||
const ProductDetail = () => {
|
const ProductDetail = () => {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const [product, setProduct] = useState(null);
|
const [product, setProduct] = useState(null);
|
||||||
@@ -34,7 +33,6 @@ const ProductDetail = () => {
|
|||||||
const [showAlert, setShowAlert] = useState(false);
|
const [showAlert, setShowAlert] = useState(false);
|
||||||
const storedUser = JSON.parse(sessionStorage.getItem("user"));
|
const storedUser = JSON.parse(sessionStorage.getItem("user"));
|
||||||
|
|
||||||
|
|
||||||
const toggleFavorite = async (id) => {
|
const toggleFavorite = async (id) => {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
"http://localhost:3030/api/product/addFavorite",
|
"http://localhost:3030/api/product/addFavorite",
|
||||||
@@ -56,7 +54,6 @@ const ProductDetail = () => {
|
|||||||
console.log(`Add Product -> History: ${id}`);
|
console.log(`Add Product -> History: ${id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const [reviewForm, setReviewForm] = useState({
|
const [reviewForm, setReviewForm] = useState({
|
||||||
rating: 3,
|
rating: 3,
|
||||||
comment: "",
|
comment: "",
|
||||||
@@ -94,11 +91,14 @@ const ProductDetail = () => {
|
|||||||
userId: storedUser.ID,
|
userId: storedUser.ID,
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await fetch(`http://localhost:3030/api/review/addReview`, {
|
const response = await fetch(
|
||||||
|
`http://localhost:3030/api/review/addReview`,
|
||||||
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify(reviewData),
|
body: JSON.stringify(reviewData),
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
|
|
||||||
@@ -208,7 +208,6 @@ const ProductDetail = () => {
|
|||||||
fetchReviews();
|
fetchReviews();
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
|
|
||||||
// Image navigation
|
// Image navigation
|
||||||
const nextImage = () => {
|
const nextImage = () => {
|
||||||
if (product?.images?.length > 0) {
|
if (product?.images?.length > 0) {
|
||||||
@@ -248,7 +247,7 @@ const ProductDetail = () => {
|
|||||||
if (loading.product) {
|
if (loading.product) {
|
||||||
return (
|
return (
|
||||||
<div className="flex justify-center items-center h-screen">
|
<div className="flex justify-center items-center h-screen">
|
||||||
<div className="animate-spin rounded-full h-32 w-32 border-t-2 border-green-500"></div>
|
<div className="animate-spin h-32 w-32 border-t-2 border-green-500"></div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -262,7 +261,7 @@ const ProductDetail = () => {
|
|||||||
<p className="text-gray-600">{error.product}</p>
|
<p className="text-gray-600">{error.product}</p>
|
||||||
<Link
|
<Link
|
||||||
to="/"
|
to="/"
|
||||||
className="mt-4 inline-block bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600"
|
className="mt-4 inline-block bg-green-500 text-white px-4 py-2 hover:bg-green-600"
|
||||||
>
|
>
|
||||||
Back to Listings
|
Back to Listings
|
||||||
</Link>
|
</Link>
|
||||||
@@ -279,7 +278,7 @@ const ProductDetail = () => {
|
|||||||
<h2 className="text-2xl text-red-500 mb-4">Product Not Found</h2>
|
<h2 className="text-2xl text-red-500 mb-4">Product Not Found</h2>
|
||||||
<Link
|
<Link
|
||||||
to="/"
|
to="/"
|
||||||
className="mt-4 inline-block bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600"
|
className="mt-4 inline-block bg-green-500 text-white px-4 py-2 hover:bg-green-600"
|
||||||
>
|
>
|
||||||
Back to Listings
|
Back to Listings
|
||||||
</Link>
|
</Link>
|
||||||
@@ -290,7 +289,6 @@ const ProductDetail = () => {
|
|||||||
|
|
||||||
// Render product details
|
// Render product details
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<div className="max-w-6xl mx-auto px-4 py-8">
|
<div className="max-w-6xl mx-auto px-4 py-8">
|
||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
<Link
|
<Link
|
||||||
@@ -320,8 +318,7 @@ const ProductDetail = () => {
|
|||||||
onClick={nextImage}
|
onClick={nextImage}
|
||||||
onError={(e) => {
|
onError={(e) => {
|
||||||
e.target.onerror = null;
|
e.target.onerror = null;
|
||||||
e.target.src =
|
e.target.src = "https://via.placeholder.com/400x300";
|
||||||
"https://via.placeholder.com/400x300?text=Image+Not+Available";
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{product.images.length > 1 && (
|
{product.images.length > 1 && (
|
||||||
@@ -331,11 +328,11 @@ const ProductDetail = () => {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
prevImage();
|
prevImage();
|
||||||
}}
|
}}
|
||||||
className="bg-white/70 p-1 rounded-full"
|
className="bg-white/70 p-1"
|
||||||
>
|
>
|
||||||
<ArrowLeft className="h-5 w-5" />
|
<ArrowLeft className="h-5 w-5" />
|
||||||
</button>
|
</button>
|
||||||
<div className="text-sm bg-white/70 px-2 py-1 rounded">
|
<div className="text-sm bg-white/70 px-2 py-1 ">
|
||||||
{currentImage + 1}/{product.images.length}
|
{currentImage + 1}/{product.images.length}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -353,7 +350,7 @@ const ProductDetail = () => {
|
|||||||
{product.images.map((image, index) => (
|
{product.images.map((image, index) => (
|
||||||
<div
|
<div
|
||||||
key={index}
|
key={index}
|
||||||
className={`bg-white border ${currentImage === index ? "border-green-500" : "border-gray-200"} min-w-[100px] cursor-pointer`}
|
className={`bg-white border ${currentImage === index ? "border-green-500 border-2" : "border-gray-200"} min-w-[100px] cursor-pointer`}
|
||||||
onClick={() => selectImage(index)}
|
onClick={() => selectImage(index)}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
@@ -379,14 +376,12 @@ const ProductDetail = () => {
|
|||||||
</h1>
|
</h1>
|
||||||
<button
|
<button
|
||||||
onClick={() => toggleFavorite(product.ProductID)}
|
onClick={() => toggleFavorite(product.ProductID)}
|
||||||
className="p-2 hover:bg-gray-100 rounded-full"
|
className="p-2 hover:bg-gray-100"
|
||||||
aria-label={
|
aria-label={
|
||||||
isFavorite ? "Remove from favorites" : "Add to favorites"
|
isFavorite ? "Remove from favorites" : "Add to favorites"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Heart
|
<Heart className={`h-6 w-6 ext-red-500 fill-red-500`} />
|
||||||
className={`h-6 w-6 ${isFavorite ? "text-red-500 fill-red-500" : "text-gray-400"}`}
|
|
||||||
/>
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -455,7 +450,7 @@ const ProductDetail = () => {
|
|||||||
{/* Seller Info */}
|
{/* Seller Info */}
|
||||||
<div className="flex items-center mb-3">
|
<div className="flex items-center mb-3">
|
||||||
<div className="mr-3">
|
<div className="mr-3">
|
||||||
<div className="h-12 w-12 rounded-full bg-gray-200 flex items-center justify-center">
|
<div className="h-12 w-12 bg-gray-200 flex items-center justify-center">
|
||||||
<User className="h-6 w-6 text-gray-600" />
|
<User className="h-6 w-6 text-gray-600" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -480,7 +475,7 @@ const ProductDetail = () => {
|
|||||||
<div className="bg-white border border-gray-200 p-6">
|
<div className="bg-white border border-gray-200 p-6">
|
||||||
{loading.reviews ? (
|
{loading.reviews ? (
|
||||||
<div className="flex justify-center py-8">
|
<div className="flex justify-center py-8">
|
||||||
<div className="animate-spin rounded-full h-8 w-8 border-t-2 border-green-500"></div>
|
<div className="animate-spin h-8 w-8 border-t-2 border-green-500"></div>
|
||||||
</div>
|
</div>
|
||||||
) : error.reviews ? (
|
) : error.reviews ? (
|
||||||
<div className="text-red-500 mb-4">
|
<div className="text-red-500 mb-4">
|
||||||
@@ -527,7 +522,7 @@ const ProductDetail = () => {
|
|||||||
<div className="mt-4">
|
<div className="mt-4">
|
||||||
<button
|
<button
|
||||||
onClick={() => setShowReviewForm(true)}
|
onClick={() => setShowReviewForm(true)}
|
||||||
className="bg-green-500 hover:bg-green-600 text-white font-medium py-2 px-4 rounded"
|
className="bg-green-500 hover:bg-green-600 text-white font-medium py-2 px-4"
|
||||||
>
|
>
|
||||||
Write a Review
|
Write a Review
|
||||||
</button>
|
</button>
|
||||||
@@ -536,7 +531,7 @@ const ProductDetail = () => {
|
|||||||
{/* Review Popup Form */}
|
{/* Review Popup Form */}
|
||||||
{showReviewForm && (
|
{showReviewForm && (
|
||||||
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4">
|
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4">
|
||||||
<div className="bg-white rounded-lg shadow-xl max-w-md w-full p-6">
|
<div className="bg-white shadow-xl max-w-md w-full p-6">
|
||||||
<div className="flex justify-between items-center mb-4">
|
<div className="flex justify-between items-center mb-4">
|
||||||
<h3 className="text-xl font-bold text-gray-800">
|
<h3 className="text-xl font-bold text-gray-800">
|
||||||
Write a Review
|
Write a Review
|
||||||
@@ -585,7 +580,7 @@ const ProductDetail = () => {
|
|||||||
id="comment"
|
id="comment"
|
||||||
value={reviewForm.comment}
|
value={reviewForm.comment}
|
||||||
onChange={handleReviewInputChange}
|
onChange={handleReviewInputChange}
|
||||||
className="w-full p-3 border border-gray-300 rounded focus:outline-none focus:border-green-500"
|
className="w-full p-3 border border-gray-300 focus:outline-none focus:border-green-500"
|
||||||
rows="4"
|
rows="4"
|
||||||
required
|
required
|
||||||
></textarea>
|
></textarea>
|
||||||
@@ -595,13 +590,13 @@ const ProductDetail = () => {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setShowReviewForm(false)}
|
onClick={() => setShowReviewForm(false)}
|
||||||
className="px-4 py-2 border border-gray-300 rounded text-gray-700 hover:bg-gray-100"
|
className="px-4 py-2 border border-gray-300 text-gray-700 hover:bg-gray-100"
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
className="px-4 py-2 bg-green-500 text-white rounded hover:bg-green-600"
|
className="px-4 py-2 bg-green-500 text-white hover:bg-green-600"
|
||||||
disabled={loading.submitting}
|
disabled={loading.submitting}
|
||||||
>
|
>
|
||||||
{loading.submitting ? "Submitting..." : "Submit Review"}
|
{loading.submitting ? "Submitting..." : "Submit Review"}
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ const SearchPage = () => {
|
|||||||
const [priceRange, setPriceRange] = useState({ min: 0, max: 1000 });
|
const [priceRange, setPriceRange] = useState({ min: 0, max: 1000 });
|
||||||
const [isFilterOpen, setIsFilterOpen] = useState(false);
|
const [isFilterOpen, setIsFilterOpen] = useState(false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchProducts(initialSearchQuery);
|
fetchProducts(initialSearchQuery);
|
||||||
}, [initialSearchQuery]);
|
}, [initialSearchQuery]);
|
||||||
@@ -199,6 +196,60 @@ const SearchPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{/* Footer - Added here */}
|
||||||
|
<footer className="bg-gray-800 text-white py-6 mt-12">
|
||||||
|
<div className="container mx-auto px-4">
|
||||||
|
<div className="flex flex-col md:flex-row justify-between items-center">
|
||||||
|
<div className="mb-4 md:mb-0">
|
||||||
|
<h3 className="text-lg font-semibold mb-2">Campus Marketplace</h3>
|
||||||
|
<p className="text-gray-400 text-sm">
|
||||||
|
Your trusted university trading platform
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex space-x-6">
|
||||||
|
<div>
|
||||||
|
<h4 className="font-medium mb-2">Quick Links</h4>
|
||||||
|
<ul className="text-sm text-gray-400">
|
||||||
|
<li className="mb-1">
|
||||||
|
<Link to="/" className="hover:text-white transition">
|
||||||
|
Home
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
<li className="mb-1">
|
||||||
|
<Link to="/selling" className="hover:text-white transition">
|
||||||
|
Sell an Item
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
<li className="mb-1">
|
||||||
|
<Link
|
||||||
|
to="/favorites"
|
||||||
|
className="hover:text-white transition"
|
||||||
|
>
|
||||||
|
My Favorites
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h4 className="font-medium mb-2">Contact</h4>
|
||||||
|
<ul className="text-sm text-gray-400">
|
||||||
|
<li className="mb-1">support@campusmarket.com</li>
|
||||||
|
<li className="mb-1">University of Calgary</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="border-t border-gray-700 mt-6 pt-6 text-center text-sm text-gray-400">
|
||||||
|
<p>
|
||||||
|
© {new Date().getFullYear()} Campus Marketplace. All rights
|
||||||
|
reserved.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -452,5 +452,4 @@ VALUES
|
|||||||
1,
|
1,
|
||||||
'This is a great fake product! Totally recommend it.',
|
'This is a great fake product! Totally recommend it.',
|
||||||
5,
|
5,
|
||||||
NOW ()
|
|
||||||
);
|
);
|
||||||
|
|||||||
BIN
recommondation-engine/__pycache__/app.cpython-313.pyc
Normal file
BIN
recommondation-engine/__pycache__/app.cpython-313.pyc
Normal file
Binary file not shown.
Reference in New Issue
Block a user