- Rename all DB tables: properties → projects, properties_addresses → projects_addresses, properties_models → projects_models, property_likes → projects_likes - Add projects_likes as proper Drizzle schema table (was SQL-only before) - Rename ID prefixes: property_xxx → project_xxx - Rename auth_sessions column: active_property_id → active_project_id - Simplify project creation: address is now optional (no longer required to get started) - Update all actions, stores, types, components, and routes - Rename route: /editor/[propertyId] → /editor/[projectId] - Add SQL migration for table/column/index/policy/function renames - Update RPC functions: increment_project_views, get_project_like_count - Update storage bucket reference: project-thumbnails - All types/exports follow existing Drizzle patterns (pgTable, relations, zod schemas)
96 lines
2.9 KiB
TypeScript
96 lines
2.9 KiB
TypeScript
'use client'
|
|
|
|
import { initSpatialGridSync, useScene } from '@pascal-app/core'
|
|
import { Viewer } from '@pascal-app/viewer'
|
|
import { useParams } from 'next/navigation'
|
|
import { useEffect, useState } from 'react'
|
|
import { ViewerCameraControls } from './viewer-camera-controls'
|
|
import { ViewerOverlay } from './viewer-overlay'
|
|
import { ViewerZoneSystem } from './viewer-zone-system'
|
|
import { ThumbnailGenerator } from './thumbnail-generator'
|
|
import { getProjectModelPublic, incrementProjectViews } from '@/features/community/lib/projects/actions'
|
|
|
|
export default function ViewerPage() {
|
|
const params = useParams()
|
|
const id = params.id as string
|
|
const [loading, setLoading] = useState(true)
|
|
const [error, setError] = useState<string | null>(null)
|
|
const [projectId, setProjectId] = useState<string | null>(null)
|
|
const setScene = useScene((state) => state.setScene)
|
|
|
|
useEffect(() => {
|
|
const loadContent = async () => {
|
|
try {
|
|
// Check if it's a demo file (starts with 'demo_')
|
|
if (id.startsWith('demo_')) {
|
|
const response = await fetch(`/demos/${id}.json`)
|
|
if (!response.ok) {
|
|
throw new Error(`Demo "${id}" not found`)
|
|
}
|
|
const data = await response.json()
|
|
if (data.nodes && data.rootNodeIds) {
|
|
setScene(data.nodes, data.rootNodeIds)
|
|
initSpatialGridSync()
|
|
}
|
|
} else {
|
|
// Load from database (public project)
|
|
const result = await getProjectModelPublic(id)
|
|
|
|
if (result.success && result.data) {
|
|
const { project, model } = result.data
|
|
setProjectId(project.id)
|
|
|
|
if (model?.scene_graph) {
|
|
const { nodes, rootNodeIds } = model.scene_graph
|
|
setScene(nodes, rootNodeIds)
|
|
initSpatialGridSync()
|
|
}
|
|
|
|
// Increment view count
|
|
await incrementProjectViews(id)
|
|
} else {
|
|
throw new Error(result.error || 'Project not found')
|
|
}
|
|
}
|
|
|
|
setLoading(false)
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : 'Failed to load content')
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
loadContent()
|
|
}, [id, setScene])
|
|
|
|
if (loading) {
|
|
return (
|
|
<div className="flex h-screen w-full items-center justify-center bg-neutral-100">
|
|
<p className="text-muted-foreground">Loading...</p>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (error) {
|
|
return (
|
|
<div className="flex h-screen w-full items-center justify-center bg-neutral-100">
|
|
<p className="text-destructive">{error}</p>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div className="relative h-screen w-full">
|
|
<ViewerOverlay />
|
|
<Viewer>
|
|
{/* Custom Camera Controls */}
|
|
<ViewerCameraControls />
|
|
{/* Custom Zone System */}
|
|
<ViewerZoneSystem />
|
|
{/* Thumbnail Generator */}
|
|
<ThumbnailGenerator projectId={projectId || undefined} />
|
|
</Viewer>
|
|
</div>
|
|
)
|
|
}
|