feat: complete dynamic JSON-driven photo tools frontend connected to FastAPI backend
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
import React from 'react';
|
||||
import { SectionConfig, ToolItem, AppItem, CategoryItem, VariantSpec } from '@/types';
|
||||
import { resolveBindings, isSectionVisible } from '@/lib/config/bindings';
|
||||
|
||||
import { HeroSection } from './HeroSection';
|
||||
import { ToolGridSection } from './ToolGridSection';
|
||||
import { TryItWidget } from './TryItWidget';
|
||||
import { BeforeAfterSection } from './BeforeAfterSection';
|
||||
import { AppCardsSection } from './AppCardsSection';
|
||||
import { AppHandoffSection } from './AppHandoffSection';
|
||||
import { AvailabilitySection } from './AvailabilitySection';
|
||||
import { AppPickerSection } from './AppPickerSection';
|
||||
import { StepsSection } from './StepsSection';
|
||||
import { FeatureListSection } from './FeatureListSection';
|
||||
import { FaqSection } from './FaqSection';
|
||||
import { StatsSection } from './StatsSection';
|
||||
import { PricingExplainerSection } from './PricingExplainerSection';
|
||||
import { RelatedToolsSection } from './RelatedToolsSection';
|
||||
import { RichTextSection } from './RichTextSection';
|
||||
import { CtaBannerSection } from './CtaBannerSection';
|
||||
import { NoticeSection } from './NoticeSection';
|
||||
|
||||
interface SectionRendererProps {
|
||||
section: SectionConfig;
|
||||
context: {
|
||||
site?: any;
|
||||
page?: any;
|
||||
tool?: ToolItem | null;
|
||||
app?: AppItem | null;
|
||||
homeApp?: AppItem | null;
|
||||
tools?: ToolItem[];
|
||||
apps?: AppItem[];
|
||||
categories?: CategoryItem[];
|
||||
variants?: VariantSpec[];
|
||||
relatedTools?: ToolItem[];
|
||||
locale?: string;
|
||||
device?: 'mobile' | 'desktop';
|
||||
};
|
||||
}
|
||||
|
||||
export function SectionRenderer({ section, context }: SectionRendererProps) {
|
||||
const locale = context.locale || 'en';
|
||||
|
||||
// Visibility Check (PRD §5.2, §5.3 CFG-09)
|
||||
if (!isSectionVisible(section, { device: context.device, locale })) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Resolve bindings on section props (PRD §5.2)
|
||||
const resolvedProps = resolveBindings(section.props || {}, context, locale);
|
||||
|
||||
switch (section.type) {
|
||||
case 'hero':
|
||||
return (
|
||||
<HeroSection
|
||||
{...resolvedProps}
|
||||
variant={section.variant}
|
||||
tool={context.tool}
|
||||
homeApp={context.homeApp}
|
||||
variants={context.variants}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
case 'toolGrid':
|
||||
return (
|
||||
<ToolGridSection
|
||||
{...resolvedProps}
|
||||
tools={context.tools}
|
||||
categories={context.categories}
|
||||
apps={context.apps}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
case 'tryItWidget':
|
||||
if (!context.tool) return null;
|
||||
return (
|
||||
<div className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||
<TryItWidget
|
||||
tool={context.tool}
|
||||
homeApp={context.homeApp}
|
||||
variants={context.variants}
|
||||
locale={locale}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
case 'beforeAfter':
|
||||
return <BeforeAfterSection {...resolvedProps} locale={locale} />;
|
||||
|
||||
case 'appCards':
|
||||
return (
|
||||
<AppCardsSection
|
||||
{...resolvedProps}
|
||||
apps={context.apps}
|
||||
layout={section.variant as any}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
case 'appHandoff':
|
||||
if (!context.app && !context.homeApp) return null;
|
||||
return (
|
||||
<AppHandoffSection
|
||||
{...resolvedProps}
|
||||
app={(context.app || context.homeApp)!}
|
||||
tool={context.tool}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
case 'availability':
|
||||
if (!context.tool) return null;
|
||||
return (
|
||||
<AvailabilitySection
|
||||
tool={context.tool}
|
||||
homeApp={context.homeApp}
|
||||
locale={locale}
|
||||
/>
|
||||
);
|
||||
|
||||
case 'appPicker':
|
||||
return <AppPickerSection {...resolvedProps} apps={context.apps} locale={locale} />;
|
||||
|
||||
case 'steps':
|
||||
return <StepsSection {...resolvedProps} locale={locale} />;
|
||||
|
||||
case 'featureList':
|
||||
return <FeatureListSection {...resolvedProps} locale={locale} />;
|
||||
|
||||
case 'faq':
|
||||
return <FaqSection {...resolvedProps} locale={locale} />;
|
||||
|
||||
case 'stats':
|
||||
return <StatsSection {...resolvedProps} />;
|
||||
|
||||
case 'pricingExplainer':
|
||||
return <PricingExplainerSection {...resolvedProps} locale={locale} />;
|
||||
|
||||
case 'relatedTools':
|
||||
return <RelatedToolsSection tools={context.relatedTools} locale={locale} />;
|
||||
|
||||
case 'richText':
|
||||
return <RichTextSection {...resolvedProps} />;
|
||||
|
||||
case 'ctaBanner':
|
||||
return <CtaBannerSection {...resolvedProps} locale={locale} />;
|
||||
|
||||
case 'notice':
|
||||
return <NoticeSection {...resolvedProps} locale={locale} />;
|
||||
|
||||
default:
|
||||
console.warn(`[SectionRenderer] Unknown section type: ${section.type}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user