import React, { useEffect } from "react"; import { useInView } from "react-intersection-observer"; import { RockingChair, LocateFixed, School, WorkflowIcon, Lock } from "lucide-react"; import PersonIcon from "@mui/icons-material/Person"; import StarIcon from "@mui/icons-material/Star"; import VisibilityIcon from "@mui/icons-material/Visibility"; import PersonAddIcon from "@mui/icons-material/PersonAdd"; import FilterModal from "../../feature/FilterModal"; import bride1 from "../../assets/images/bride1.jpg"; import bride2 from "../../assets/images/bride2.jpg"; import bride3 from "../../assets/images/bride3.jpg"; import bride4 from "../../assets/images/bride4.jpg"; import groom1 from "../../assets/images/groom1.jpg"; import groom2 from "../../assets/images/groom2.jpg"; import groom3 from "../../assets/images/groom3.jpg"; import groom4 from "../../assets/images/groom4.jpg"; import horoscope from "../../assets/images/horoscopeicon.png"; import { useNavigate } from "react-router-dom"; import toast from "react-hot-toast"; import { useSelector, useDispatch } from "react-redux"; import { updateFilter } from "../../redux/filterSlice"; import { useProfiles } from "../../hooks/useProfiles"; import ProfileCardUI from "../common/ProfileCardUI"; import ProfileCardSkeleton from "../common/ProfileCardSkeleton"; // Main Component export default function MatchesInterface() { const [showSkeleton, setShowSkeleton] = React.useState(false); const navigate = useNavigate(); const dispatch = useDispatch(); const filters = useSelector((state) => state.filters); const filterType = filters.filter_type; const selectedTab = filterType || "all_matches"; const isPaidMember = filters.isPaidMember; const { ref, inView } = useInView({ threshold: 0, rootMargin: "300px" }); // Fetch real profiles data const { data: profilesData, isLoading, fetchNextPage, hasNextPage, isFetchingNextPage, } = useProfiles(filters); const profiles = profilesData?.pages.flatMap((page) => page?.data|| []) || []; // const { ref, inView } = useInView(); // useEffect(() => { // if (inView && hasNextPage && !isFetchingNextPage) { // fetchNextPage(); // } // }, [inView, hasNextPage, isFetchingNextPage]); useEffect(() => { if (inView && hasNextPage && !isFetchingNextPage) { setShowSkeleton(true); // show skeleton const timer = setTimeout(() => { fetchNextPage(); setShowSkeleton(false); // hide skeleton after API call }, 120); // 0.5 seconds return () => clearTimeout(timer); } }, [inView, hasNextPage, isFetchingNextPage, fetchNextPage]); console.log("Fetched profiles:", profiles); console.log({ inView, hasNextPage, isFetchingNextPage, }); const tabs = [ { id: "all_matches", icon: , title: "Your Matches", description: "View all the profiles that match your preferences", category: "All Matches", }, { id: "shorlisted_by_you", icon: , title: "Shortlisted by you", description: "Matches you have shortlisted", category: "Based on activity", }, { id: "viewed_you", icon: , title: "Viewed you", description: "Matches who have viewed your profile", category: "Based on activity", }, { id: "shorlisted_you", icon: , title: "Shortlisted you", description: "Matches who have shortlisted your profile", category: "Based on activity", }, { id: "viewed_by_you", icon: , title: "Viewed by you", description: "Matches you have viewed", category: "Based on activity", }, { id: "newly_joined", icon: , title: "Newly Joined", description: "Matches who Joined within the last 30 days", category: "Based on activity", }, { id: "location_matches", icon: , title: "Location matches", description: "Matches near your location", category: "Based on activity", }, { id: "education_matches", icon: , title: "Education matches", description: "Matches near your education match", category: "Based on activity", }, { id: "job_matches", icon: , title: "Job matches", description: "Matches near your job", category: "Based on activity", }, ]; let currentCategory = ""; return ( <> {/*
*/}
{/* Left Sidebar - Fixed on desktop, scrollable on mobile */}

Filter Matches

{tabs.map((tab) => { const showCategory = tab.category !== currentCategory; if (showCategory) { currentCategory = tab.category; } return (
{showCategory && (

{tab.category}

)}
{ dispatch(updateFilter({ filter_type: tab.id })); }} className={`p-4 rounded-lg mb-3 cursor-pointer transition-all ${ selectedTab === tab.id ? "bg-green-50 border-l-4 border-green-600" : "hover:bg-gray-50" }`} >
{tab.icon}

{tab.title}

{tab.description}

); })}
{/* Right Content Area - Scrollable */}

{tabs.find((t) => t.id === selectedTab)?.title}

{ if (isPaidMember) { navigate("/horoscoper-generate"); } else { toast.error("Star Matching is locked for free members"); } }}> {!isPaidMember && (
)}
{isLoading && !isFetchingNextPage ? ( [...Array(6)].map((_, i) => ) ) : profiles.length > 0 ? ( profiles.map((profile) => ( )) ) : !isLoading && !isFetchingNextPage ? (
No profiles found
) : null} {/* {isFetchingNextPage && [...Array(5)].map((_, i) => ( ))} */} {(isFetchingNextPage || showSkeleton) && [...Array(6)].map((_, i) => ( ))}
{!isLoading && !hasNextPage && profiles.length > 0 && (

You've reached the end.

)}
); }