Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | 108x 108x 108x 108x 108x 108x 56x 56x 108x 108x 5x 108x 108x 1x 107x 107x 428x 107x 6x 1x 1x 24x 101x | // Main presentational component for project detail page — tabbed layout
import { useState, useEffect } from "react";
import { Link, useNavigate } from "@tanstack/react-router";
import { ArrowLeft } from "lucide-react";
import { Button } from "../ui/button";
import { Breadcrumb } from "../ui/breadcrumb";
import { Tabs, TabsList, TabsTrigger, TabsContent } from "../ui/tabs";
import { ProjectHeader } from "./ProjectHeader";
import { useIsMobile } from "../../hooks/useIsMobile";
import { DetailsTab } from "./tabs/DetailsTab";
import { SpecificsTab } from "./tabs/SpecificsTab";
import { PhotosTab } from "./tabs/PhotosTab";
import { SeoTab } from "./tabs/SeoTab";
import type { ProjectDetailContentProps } from "./types";
import type { Project } from "../../lib/api";
export function ProjectDetailContent({
project,
pro,
context,
isLoading,
isSaving,
onSave,
onPublish,
onArchive,
onDelete,
supportsRooms,
apiAdapter,
backLink,
initialTab,
}: ProjectDetailContentProps) {
const [photos, setPhotos] = useState(project.photos || []);
const [roomMediaCount, setRoomMediaCount] = useState(0);
const [activeTab, setActiveTab] = useState(initialTab || "details");
const isMobile = useIsMobile();
const navigate = useNavigate();
// Sync photos when project data changes
useEffect(() => {
Eif (project.photos) {
setPhotos(project.photos);
}
}, [project.photos]);
const PROJECT_TABS = [
{ value: "details", label: "Details" },
{ value: "specifics", label: "Specifics" },
{ value: "photos", label: "Photos" },
{ value: "seo", label: "SEO" },
];
// Save handler for tab modals
const handleSave = async (data: Partial<Project>) => {
await onSave(data);
};
// Determine proId for room operations
const proId = project.proId;
// Loading state
if (isLoading) {
return (
<div className="flex items-center justify-center h-64">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary-600" />
</div>
);
}
// Error state (no project)
Iif (!project) {
return (
<div className="text-center py-12">
<p className="text-error mb-4">Project not found</p>
<Link to={backLink}>
<Button variant="outline">
<ArrowLeft className="h-4 w-4 mr-2" />
Back to Projects
</Button>
</Link>
</div>
);
}
// Shared tab content
const tabContent = (
<Tabs value={activeTab} onValueChange={setActiveTab}>
{/* Desktop: tab bar */}
<TabsList className="hidden sm:inline-flex w-full gap-1">
{PROJECT_TABS.map((tab) => (
<TabsTrigger key={tab.value} value={tab.value}>
{tab.label}
</TabsTrigger>
))}
</TabsList>
<TabsContent value="details">
<DetailsTab project={project} onSave={handleSave} />
</TabsContent>
<TabsContent value="specifics">
<SpecificsTab project={project} onSave={handleSave} />
</TabsContent>
<TabsContent value="photos">
<PhotosTab
project={project}
supportsRooms={supportsRooms}
apiAdapter={apiAdapter}
onSave={handleSave}
proId={String(proId)}
onTotalMediaChange={setRoomMediaCount}
/>
</TabsContent>
<TabsContent value="seo">
<SeoTab project={project} onSave={handleSave} />
</TabsContent>
</Tabs>
);
// ─── Mobile: full-screen page ───────────────────────────────────────
if (isMobile) {
return (
<div className="fixed inset-0 z-[60] flex flex-col bg-background-base">
{/* Header */}
<div className="flex h-14 items-center gap-3 border-b border-border-default bg-background-elevated px-4 flex-shrink-0">
<button
type="button"
onClick={() => navigate({ to: backLink })}
className="p-2 -ml-2 text-foreground-muted hover:text-foreground-default rounded-md"
aria-label="Go back"
>
<ArrowLeft className="h-5 w-5" />
</button>
<h2 className="text-lg font-semibold text-foreground-default truncate">
{project.title}
</h2>
<div className="flex items-center gap-2 ml-auto">
<ProjectHeader
project={project}
pro={pro}
context={context}
backLink={backLink}
isSaving={isSaving}
photoCount={photos.length + roomMediaCount > 0 ? photos.length + roomMediaCount : (project.coverImage ? 1 : 0)}
onPublish={onPublish}
onArchive={onArchive}
onDelete={context === "admin" ? onDelete : undefined}
mobileActionsOnly
/>
</div>
</div>
{/* Tab selector */}
<div className="px-4 pt-3 pb-2 bg-background-base flex-shrink-0">
<select
aria-label="Project section"
value={activeTab}
onChange={(e) => setActiveTab(e.target.value)}
className="w-full h-10 px-3 rounded-md border border-border-default bg-background-elevated text-foreground-default text-sm focus:ring-2 focus:ring-primary-500"
>
{PROJECT_TABS.map((tab) => (
<option key={tab.value} value={tab.value}>
{tab.label}
</option>
))}
</select>
</div>
{/* Scrollable content */}
<div className="flex-1 overflow-y-auto p-4">
{tabContent}
</div>
</div>
);
}
// ─── Desktop: standard layout ───────────────────────────────────────
return (
<div className="space-y-4 sm:space-y-6">
{/* Breadcrumb */}
<Breadcrumb
items={[
{ label: "Projects", href: backLink },
{ label: project.title },
]}
/>
{/* Header */}
<ProjectHeader
project={project}
pro={pro}
context={context}
backLink={backLink}
isSaving={isSaving}
photoCount={photos.length + roomMediaCount > 0 ? photos.length + roomMediaCount : (project.coverImage ? 1 : 0)}
onPublish={onPublish}
onArchive={onArchive}
onDelete={context === "admin" ? onDelete : undefined}
/>
{/* Tabbed content */}
<div className="sm:max-w-4xl">
{tabContent}
</div>
</div>
);
}
|