import { useEffect, useState } from 'react' import { useRouter } from 'next/router' import Head from 'next/head' import { ConnectButton } from '@/components/ConnectButton' import { UserProfile } from '@/components/UserProfile' import { UserArticles } from '@/components/UserArticles' import { SearchBar } from '@/components/SearchBar' import { ArticleFiltersComponent, type ArticleFilters } from '@/components/ArticleFilters' import { useNostrConnect } from '@/hooks/useNostrConnect' import { useUserArticles } from '@/hooks/useUserArticles' import { nostrService } from '@/lib/nostr' import type { NostrProfile } from '@/types/nostr' export default function ProfilePage() { const router = useRouter() const { connected, pubkey: currentPubkey } = useNostrConnect() const [profile, setProfile] = useState(null) const [loadingProfile, setLoadingProfile] = useState(true) const [searchQuery, setSearchQuery] = useState('') const [filters, setFilters] = useState({ authorPubkey: null, minPrice: null, maxPrice: null, sortBy: 'newest', }) // Use current user's pubkey if connected, otherwise redirect useEffect(() => { if (!connected || !currentPubkey) { router.push('/') return } }, [connected, currentPubkey, router]) // Load user profile useEffect(() => { if (!currentPubkey) return setLoadingProfile(true) nostrService .getProfile(currentPubkey) .then((loadedProfile) => { if (loadedProfile) { setProfile(loadedProfile) } else { // Create minimal profile if none exists setProfile({ pubkey: currentPubkey, name: undefined, about: undefined, picture: undefined, nip05: undefined, }) } }) .catch((e) => { console.error('Error loading profile:', e) // Create minimal profile on error setProfile({ pubkey: currentPubkey, name: undefined, about: undefined, picture: undefined, nip05: undefined, }) }) .finally(() => { setLoadingProfile(false) }) }, [currentPubkey]) const { articles, allArticles, loading, error, loadArticleContent } = useUserArticles( currentPubkey || '', searchQuery, filters ) if (!connected || !currentPubkey) { return null // Will redirect } return ( <> My Profile - Nostr Paywall

Nostr Paywall

{/* Profile Section */} {loadingProfile ? (

Loading profile...

) : profile ? ( ) : null} {/* Search and Filters */}

My Articles

{!loading && allArticles.length > 0 && ( )}
{/* Articles Count */} {!loading && articles.length > 0 && (
Showing {articles.length} of {allArticles.length} article{allArticles.length !== 1 ? 's' : ''}
)} {/* Articles List */}
) }