diff --git a/client/app/category/[id]/page.tsx b/client/app/category/[id]/page.tsx index 5beb3cf..36c7aa3 100644 --- a/client/app/category/[id]/page.tsx +++ b/client/app/category/[id]/page.tsx @@ -1,47 +1,47 @@ -"use client"; +"use client" -import { FooterSection } from '@/app/components/FooterSection'; -import Navbar from '@/app/components/navSection'; -import React, { useState, useEffect } from 'react'; -import Link from "next/link"; -import Image from 'next/image'; -import { fetchBusinessesByCategory, fetchBusinessData } from '@/app/api'; +import { FooterSection } from '@/app/components/FooterSection' +import Navbar from '@/app/components/navSection' +import React, { useState, useEffect } from 'react' +import Link from "next/link" +import Image from 'next/image' +import { fetchBusinessesByCategory, fetchBusinessData } from '../../api/index' +import { Skeleton } from "../../components/ui/skelton" +import { BusinessCardSkeleton } from "../../components/businessCardSkeleton" interface CategoryPageProps { params: { - id: string; - }; + id: string + } } interface employ { - title: string; - src?: string; - location?: string; - type?: string; - slug: string; // Added slug to the interface + title: string + src?: string + location?: string + type?: string + slug: string } -export const runtime = 'edge'; - export default function CategoryPage({ params }: CategoryPageProps) { - const { id } = params; - const [searchTerm, setSearchTerm] = useState(""); - const [visibleEmploys, setVisibleEmploys] = useState(16); - const [categoryId, setCategoryId] = useState(""); - const [employs, setEmploys] = useState([]); - const [categoryName, setCategoryName] = useState(""); // Added state for category name + const { id } = params + const [searchTerm, setSearchTerm] = useState("") + const [visibleEmploys, setVisibleEmploys] = useState(16) + const [employs, setEmploys] = useState([]) + const [categoryName, setCategoryName] = useState("") + const [isLoading, setIsLoading] = useState(true) useEffect(() => { const fetchData = async () => { try { - const categoriesResponse = await fetchBusinessData(); + const categoriesResponse = await fetchBusinessData() const category = categoriesResponse.data.categories.find( - (cat: any) => cat.id === id // Changed to match by id instead of name - ); + (cat: any) => cat.id === id + ) if (category?.id) { - setCategoryName(category.name); // Store the category name - const response = await fetchBusinessesByCategory(category.id); + setCategoryName(category.name) + const response = await fetchBusinessesByCategory(category.id) const validBusinesses = response.data?.profiles?.map((business: any) => ({ title: business.title || business.name || 'Untitled', @@ -49,105 +49,123 @@ export default function CategoryPage({ params }: CategoryPageProps) { src: business.src || "/assets/media/defaultbusiness.png", location: business.location, type: business.type - })) || []; - setEmploys(validBusinesses); + })) || [] + setEmploys(validBusinesses) } } catch (error) { - console.error('Error:', error); - setEmploys([]); + console.error('Error:', error) + setEmploys([]) + } finally { + setIsLoading(false) } - }; + } - fetchData(); - }, [id]); + fetchData() + }, [id]) const filteredEmploys = employs.filter(employs => employs.title.toLowerCase().includes(searchTerm.toLowerCase()) - ); + ) const handleLoadMore = () => { - setVisibleEmploys(prev => prev + 16); - }; + setVisibleEmploys(prev => prev + 16) + } return (
- +
-

{categoryName}

{/* Display category name */} + {isLoading ? ( + + ) : ( +

{categoryName}

+ )}
- { - setSearchTerm(e.target.value); - setVisibleEmploys(15); - }} - className="w-full px-4 py-2 border border-green-500 rounded-full focus:outline-none focus:ring-transparent" - /> - - - + {isLoading ? ( + + ) : ( + <> + { + setSearchTerm(e.target.value) + setVisibleEmploys(15) + }} + className="w-full px-4 py-2 border border-green-500 rounded-full focus:outline-none focus:ring-transparent" + /> + + + + + )}
-
- {filteredEmploys.slice(0, visibleEmploys).map((s, index) => ( - -
- {s.title} -
- {s.title} -
- Mode: {s.type === "both" ? "offline/online" : s.type} -
- Location: {s.location || 'Not Specified'} - - ))} -
+ {isLoading ? ( + + ) : ( + <> +
+ {filteredEmploys.slice(0, visibleEmploys).map((s, index) => ( + +
+ {s.title} +
+ {s.title} +
+ Mode: {s.type === "both" ? "offline/online" : s.type} +
+ Location: {s.location || 'Not Specified'} + + ))} +
- {filteredEmploys.length > visibleEmploys && ( -
- -
- )} + {filteredEmploys.length > visibleEmploys && ( +
+ +
+ )} - {filteredEmploys.length === 0 && ( -
- No bussiness or freelancers found matching "{searchTerm}" -
+ {filteredEmploys.length === 0 && ( +
+ No bussiness or freelancers found matching "{searchTerm}" +
+ )} + )} -
- +
- ); -} \ No newline at end of file + ) +} + diff --git a/client/app/components/businessCardSkeleton.tsx b/client/app/components/businessCardSkeleton.tsx new file mode 100644 index 0000000..12f9fca --- /dev/null +++ b/client/app/components/businessCardSkeleton.tsx @@ -0,0 +1,20 @@ +import { Skeleton } from "./ui/skelton" + +export function BusinessCardSkeleton() { + return ( +
+ {Array.from({ length: 16 }).map((_, index) => ( +
+ + + + +
+ ))} +
+ ) +} + diff --git a/client/app/components/categorySkelton.tsx b/client/app/components/categorySkelton.tsx new file mode 100644 index 0000000..44ea496 --- /dev/null +++ b/client/app/components/categorySkelton.tsx @@ -0,0 +1,17 @@ +import { Skeleton } from "./ui/skelton" + +export function CategorySkeleton() { + return ( +
+ {Array.from({ length: 15 }).map((_, index) => ( +
+ +
+ ))} +
+ ) +} + diff --git a/client/app/components/signup/bussiness-overview.tsx b/client/app/components/signup/bussiness-overview.tsx index 9b821d5..18d98cb 100644 --- a/client/app/components/signup/bussiness-overview.tsx +++ b/client/app/components/signup/bussiness-overview.tsx @@ -431,8 +431,8 @@ export default function BusinessOverview({ -
-