import React, { useState, useEffect } from 'react' import { profileAPI, likeAPI, API_BASE_URL } from '../api' import '../styles/discover.css' export default function Discover() { const [profiles, setProfiles] = useState([]) const [currentIndex, setCurrentIndex] = useState(0) const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState('') useEffect(() => { loadProfiles() }, []) const loadProfiles = async () => { try { setIsLoading(true) const response = await profileAPI.discoverProfiles() setProfiles(response.data || []) } catch (err) { setError('Failed to load profiles') } finally { setIsLoading(false) } } const handleLike = async () => { if (currentIndex >= profiles.length) return const profile = profiles[currentIndex] try { const response = await likeAPI.likeUser(profile.id) if (response.data.is_match) { alert(`It's a match with ${profile.display_name}!`) } nextProfile() } catch (err) { setError(err.response?.data?.detail || 'Failed to like profile') } } const handlePass = () => { nextProfile() } const nextProfile = () => { if (currentIndex < profiles.length - 1) { setCurrentIndex((prev) => prev + 1) } else { setError('No more profiles to discover') } } if (isLoading) { return
Loading profiles...
} if (currentIndex >= profiles.length) { return (

No more profiles

Come back later for new matches!

) } const profile = profiles[currentIndex] return (

Discover

{error &&
{error}
}
{profile.photos && profile.photos.length > 0 ? ( {profile.display_name} ) : (
No photo
)}

{profile.display_name}, {profile.age}

{profile.location}

{profile.bio &&

{profile.bio}

} {profile.interests && profile.interests.length > 0 && (
{profile.interests.map((interest) => ( {interest} ))}
)}
Profile {currentIndex + 1} of {profiles.length}
) }