-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #395 from pooranjoyb/dev
Final Merge to Production : GSSoC'2024 🚀
- Loading branch information
Showing
12 changed files
with
6,667 additions
and
2,946 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { useEffect, useState } from "react"; | ||
import { supabase } from "../utils/client"; // Adjust the path as necessary | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
interface LikedProduct { | ||
id: number; | ||
name: string; | ||
image: string; | ||
price: number; | ||
desc: string; | ||
created_at: string; | ||
rating: string; | ||
} | ||
|
||
function Liked() { | ||
const [likedProducts, setLikedProducts] = useState<LikedProduct[]>([]); | ||
const [loading, setLoading] = useState<boolean>(true); | ||
const [error, setError] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
const fetchLikedProducts = async () => { | ||
const { data, error } = await supabase | ||
.from("liked_products") // Replace with your table name | ||
.select("*"); | ||
console.log("liked", data); | ||
if (error) { | ||
setError("Failed to fetch liked products"); | ||
console.error("Error fetching liked products:", error); | ||
} else { | ||
setLikedProducts(data || []); | ||
} | ||
setLoading(false); | ||
}; | ||
|
||
fetchLikedProducts(); | ||
}, []); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const handleAddToCart = (product: LikedProduct) => { | ||
navigate("/home/shop/product", { state: product }); | ||
}; | ||
|
||
if (loading) { | ||
return <p>Loading...</p>; | ||
} | ||
|
||
if (error) { | ||
return <p>{error}</p>; | ||
} | ||
|
||
return ( | ||
<div className="p-4"> | ||
<h1 className="text-2xl font-bold mb-4">Liked Products</h1> | ||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4"> | ||
{likedProducts.length === 0 ? ( | ||
<p>No liked products found.</p> | ||
) : ( | ||
likedProducts.map((product) => ( | ||
<div | ||
key={product.id} | ||
className="relative bg-white border border-gray-300 rounded-lg shadow-lg overflow-hidden" | ||
> | ||
<img | ||
src={product.image} | ||
alt={product.name} | ||
className="w-full h-64 object-cover" | ||
/> | ||
<div className="p-4"> | ||
<h3 className="text-lg font-semibold text-gray-800"> | ||
{product.name} | ||
</h3> | ||
<p className="text-gray-600 mt-2">{product.desc}</p> | ||
<div className="flex space-x-1"> | ||
<p className="text-xl font-bold text-gray-900 mt-2"> | ||
₹{product.price} | ||
</p>{" "} | ||
<span className="bg-mygreen px-4 py-2 font-bold text-mywhite rounded-md"> | ||
{product.rating} ⭐ | ||
</span> | ||
</div> | ||
<button | ||
onClick={() => handleAddToCart(product)} | ||
className="mt-4 px-4 py-2 bg-blue-500 text-white font-bold rounded hover:bg-blue-600 border border-gray-300" | ||
> | ||
Add to Cart | ||
</button> | ||
</div> | ||
</div> | ||
)) | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default Liked; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
@import 'font-awesome/css/font-awesome.min.css'; | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.