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 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | 8x 8x 107x 107x 107x 107x 107x 107x 50x 107x 107x 5x 107x 107x 107x 107x 1x 106x 424x 106x 5x 1x 1x 20x 101x | // Presentational shell for the project detail page — header, rule, tab rail.
import { useNavigate } from "@tanstack/react-router";
import { ArrowLeft } from "lucide-react";
import { useEffect, useState } from "react";
import { useIsMobile } from "../../hooks/useIsMobile";
import type { Project } from "../../lib/api";
import { Select } from "../ui/select";
import { Separator } from "../ui/separator";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs";
import { ProjectHeader } from "./ProjectHeader";
import { RankBetterPanel } from "./RankBetterPanel";
import { VisibilityPanel } from "./VisibilityPanel";
import { DetailsTab } from "./tabs/DetailsTab";
import { PhotosTab } from "./tabs/PhotosTab";
import { SeoTab } from "./tabs/SeoTab";
import { SpecificsTab } from "./tabs/SpecificsTab";
import type { ProjectDetailContentProps } from "./types";
/**
* The tab rail is a **2px underline rail**, not a filled segmented control —
* `project-detail-details.html`, `.tabrail` in `_base.css`. The die-cut
* red-filled tab stays nav-only (the Index Red Rule: index red marks the
* current item as a 3px inset bar and nothing else, and never state).
*
* The underline is expressed as `aria-selected:` variants rather than a prop
* the primitive does not have: `TabsTrigger` already sets `aria-selected`, and
* these classes are merged over its own by `cn`/`tailwind-merge`, so the
* primitive keeps owning the ARIA wiring and the roving tabindex.
*/
const TAB_RAIL_LIST =
"h-auto w-full justify-start gap-5 overflow-x-auto rounded-none border-b border-border-default bg-transparent p-0";
const TAB_RAIL_TRIGGER =
"shrink-0 rounded-none border-b-2 border-transparent bg-transparent px-0 pb-2 text-sm font-semibold text-foreground-muted shadow-none " +
"hover:text-foreground-default " +
"aria-selected:border-foreground-default aria-selected:bg-transparent aria-selected:text-foreground-default aria-selected:shadow-none";
export function ProjectDetailContent({
project,
pro,
context,
isLoading,
isSaving,
onSave,
onAction,
photoMinimum,
blockingRequirements,
publishRefused,
canMoveToDraft,
canDelete,
supportsRooms,
apiAdapter,
backLink,
initialTab,
}: ProjectDetailContentProps) {
const [roomMediaCount, setRoomMediaCount] = useState(0);
const [activeTab, setActiveTab] = useState(initialTab || "details");
const [editSection, setEditSection] = useState<string | null>(null);
const isMobile = useIsMobile();
const navigate = useNavigate();
// A deep link (`?tab=photos` off the no-photos chip) must still land on the
// right tab when the page is already mounted.
useEffect(() => {
if (initialTab) setActiveTab(initialTab);
}, [initialTab]);
const PROJECT_TABS = [
{ value: "details", label: "Details" },
{ value: "specifics", label: "Specifics" },
{ value: "photos", label: "Photos" },
{ value: "seo", label: "SEO" },
];
const handleSave = async (data: Partial<Project>) => {
await onSave(data);
};
const proId = project.proId;
// Photos on this project: room media is the real store; a legacy project's
// `photos` array and its denormalised cover are the fallback.
const photoCount =
roomMediaCount > 0
? roomMediaCount
: project.photos?.length || (project.coverImage ? 1 : 0);
const publishBlockedBy =
photoMinimum !== undefined && photoCount < photoMinimum
? blockingRequirements?.[0]?.label
: publishRefused
? blockingRequirements?.[0]?.label
: undefined;
if (isLoading) {
return (
<div className="flex h-64 items-center justify-center">
<div className="h-8 w-8 animate-spin rounded-full border-b-2 border-primary-600" />
</div>
);
}
const tabContent = (
<Tabs value={activeTab} onValueChange={setActiveTab}>
<TabsList className={`hidden sm:flex ${TAB_RAIL_LIST}`}>
{PROJECT_TABS.map((tab) => (
<TabsTrigger
key={tab.value}
value={tab.value}
className={TAB_RAIL_TRIGGER}
>
{tab.label}
{tab.value === "photos" && photoCount > 0 && (
<span className="ml-1.5 text-xs tabular-nums text-foreground-subtle">
{photoCount}
</span>
)}
</TabsTrigger>
))}
</TabsList>
<TabsContent value="details">
<div className="grid items-start gap-5 lg:grid-cols-[minmax(0,1fr)_minmax(0,19rem)]">
<DetailsTab
project={project}
onSave={handleSave}
openSection={editSection}
onSectionHandled={() => setEditSection(null)}
/>
<aside className="space-y-4">
<VisibilityPanel
status={project.status}
photoCount={photoCount}
photoMinimum={photoMinimum}
blockingRequirements={blockingRequirements}
publishRefused={publishRefused}
isBusy={isSaving}
onAction={onAction}
/>
<RankBetterPanel
project={project}
photoCount={photoCount}
onEditSection={(section) => {
if (section === "location" || section === "budget") {
setActiveTab("specifics");
return;
}
setEditSection(section);
}}
/>
</aside>
</div>
</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">
<div className="flex h-14 shrink-0 items-center gap-3 border-b border-border-default bg-background-elevated px-4">
<button
type="button"
onClick={() => navigate({ to: backLink })}
className="-ml-2 rounded-md p-2 text-foreground-muted hover:text-foreground-default"
aria-label="Go back"
>
<ArrowLeft className="h-5 w-5" />
</button>
<h2 className="truncate font-heading text-lg font-bold text-foreground-default">
{project.title}
</h2>
<div className="ml-auto flex items-center gap-2">
<ProjectHeader
project={project}
pro={pro}
context={context}
backLink={backLink}
isSaving={isSaving}
photoCount={photoCount}
publishBlockedBy={publishBlockedBy}
canMoveToDraft={canMoveToDraft}
canDelete={canDelete}
onAction={onAction}
mobileActionsOnly
/>
</div>
</div>
<div className="shrink-0 bg-background-base px-4 pt-3 pb-2">
<Select
aria-label="Project section"
value={activeTab}
onChange={(e) => setActiveTab(e.target.value)}
options={PROJECT_TABS.map((tab) => ({
value: tab.value,
label: tab.label,
}))}
/>
</div>
<div className="flex-1 overflow-y-auto p-4">{tabContent}</div>
</div>
);
}
// ─── Desktop ────────────────────────────────────────────────────────
return (
<div>
<ProjectHeader
project={project}
pro={pro}
context={context}
backLink={backLink}
isSaving={isSaving}
photoCount={photoCount}
publishBlockedBy={publishBlockedBy}
canMoveToDraft={canMoveToDraft}
canDelete={canDelete}
onAction={onAction}
/>
{/* The page rule: once per page, carrying this screen's one
3px index-red inset bar. */}
<Separator strong marked className="my-4" />
{tabContent}
</div>
);
}
|