'use client' import Image from 'next/image' import { useRouter } from 'next/navigation' import { useEffect, useState } from 'react' import { useAuth } from '../lib/auth/hooks' import type { LocalProperty } from '../lib/local-storage/property-store' import { createLocalProperty, getLocalProperties } from '../lib/local-storage/property-store' import { getPublicProperties, getUserProperties } from '../lib/properties/actions' import type { Property } from '../lib/properties/types' import { CreatePropertyButton } from './create-property-button' import { NewPropertyDialog } from './new-property-dialog' import { ProfileDropdown } from './profile-dropdown' import { PropertyGrid } from './property-grid' import { SignInDialog } from './sign-in-dialog' export default function CommunityHub() { const { isAuthenticated, isLoading: authLoading, user } = useAuth() const router = useRouter() const [isSignInDialogOpen, setIsSignInDialogOpen] = useState(false) const [isNewPropertyDialogOpen, setIsNewPropertyDialogOpen] = useState(false) const [localPropertyToSave, setLocalPropertyToSave] = useState(null) const [publicProperties, setPublicProperties] = useState([]) const [userProperties, setUserProperties] = useState([]) const [localProperties, setLocalProperties] = useState([]) const [loading, setLoading] = useState(true) useEffect(() => { async function loadProperties() { setLoading(true) // Load public properties (always) const publicResult = await getPublicProperties() if (publicResult.success) { setPublicProperties(publicResult.data || []) } // Load user properties if authenticated if (isAuthenticated) { const userResult = await getUserProperties() if (userResult.success) { setUserProperties(userResult.data || []) } } // Always load local properties setLocalProperties(getLocalProperties()) setLoading(false) } if (!authLoading) { loadProperties() } }, [isAuthenticated, authLoading]) const handleCreateProperty = async () => { if (!isAuthenticated) { // Create local property for guest const property = createLocalProperty('Untitled Property') router.push(`/editor/${property.id}`) } else { // Open property creation dialog for authenticated users setIsNewPropertyDialogOpen(true) } } const handlePropertyCreated = async (propertyId: string) => { // If this was a local property being saved, delete it from localStorage if (localPropertyToSave) { const { deleteLocalProperty } = await import('../lib/local-storage/property-store') deleteLocalProperty(localPropertyToSave.id) setLocalProperties(getLocalProperties()) setLocalPropertyToSave(null) } // Reload properties and navigate to the new property const result = await getUserProperties() if (result.success) { setUserProperties(result.data || []) } router.push(`/editor/${propertyId}`) } const handleSaveLocalToCloud = (localProperty: LocalProperty) => { setLocalPropertyToSave(localProperty) setIsNewPropertyDialogOpen(true) } const handlePropertyClick = (propertyId: string) => { router.push(`/editor/${propertyId}`) } const handleViewProperty = (propertyId: string) => { router.push(`/viewer/${propertyId}`) } if (authLoading || loading) { return (

Loading...

) } return (
{/* Header */}
Pascal

Hub

{!isAuthenticated ? ( ) : ( )}
{/* User's Properties Section */} {isAuthenticated && (userProperties.length > 0 || localProperties.length > 0) && (

My Properties

{ // Reload properties after settings update if (!authLoading) { getUserProperties().then((result) => { if (result.success) { setUserProperties(result.data || []) } }) } }} />
)} {/* Local Properties Section (Guest Users) */} {!isAuthenticated && localProperties.length > 0 && (

My Local Projects

)} {/* Create First Property CTA */} {!isAuthenticated && localProperties.length === 0 && (

Get Started

Create your first property to start designing

)} {/* Public Properties Section */}

Community Properties

{publicProperties.length > 0 ? ( ) : (
No public properties yet
)}
) }