'use client' import { ProfileForm, ProfileFormData } from '@/components/ProfileForm' import { AvatarUpload } from '@/components/AvatarUpload' import { useState, useEffect } from 'react' export default function ProfilePage() { const [user, setUser] = useState(null) const [loading, setLoading] = useState(true) const [isUpdatingProfile, setIsUpdatingProfile] = useState(false) const [isUploadingAvatar, setIsUploadingAvatar] = useState(false) useEffect(() => { fetchCurrentUser() }, []) const fetchCurrentUser = async () => { try { const res = await fetch('/api/users/me') if (res.ok) { const data = await res.json() setUser(data.user) } } catch (error) { console.error('Failed to fetch user:', error) } finally { setLoading(false) } } const handleAvatarUpload = async (file: File) => { setIsUploadingAvatar(true) try { // In a real app, upload to cloud storage and get URL // For now, create a local blob URL as placeholder const avatarUrl = URL.createObjectURL(file) const res = await fetch('/api/users/me', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ avatarUrl }), }) if (res.ok) { const data = await res.json() setUser(data.user) } } catch (error) { console.error('Failed to upload avatar:', error) } finally { setIsUploadingAvatar(false) } } const handleProfileSubmit = async (data: ProfileFormData) => { setIsUpdatingProfile(true) try { const res = await fetch('/api/users/me', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ displayName: data.username, bio: data.bio, }), }) if (res.ok) { const result = await res.json() setUser(result.user) } } catch (error) { console.error('Failed to update profile:', error) } finally { setIsUpdatingProfile(false) } } if (loading) { return (

Loading profile...

) } if (!user) { return (

Please log in to view your profile

Log In
) } return (
{/* Header */}

Profile Settings

Manage your account and preferences

{/* Avatar Section */}

Profile Picture

{/* Profile Form */}

Account Information

{/* Danger Zone */}

Danger Zone

Once you delete your account, there is no going back. Please be certain.

) }