/** * Presentation Container * * Main container for smart presentation rendering. * * Features: * - Auto-detects presentation type from data structure * - Supports manual type switching * - Manages presentation state * - Provides export functionality */ import React, { useState, useMemo, useCallback } from 'react'; import { invoke } from '@tauri-apps/api/core'; import type { PresentationType, PresentationAnalysis } from './types'; import { TypeSwitcher } from './TypeSwitcher'; import { QuizRenderer } from './renderers/QuizRenderer'; const SlideshowRenderer = React.lazy(() => import('./renderers/SlideshowRenderer').then(m => ({ default: m.SlideshowRenderer }))); const DocumentRenderer = React.lazy(() => import('./renderers/DocumentRenderer').then(m => ({ default: m.DocumentRenderer }))); const ChartRenderer = React.lazy(() => import('./renderers/ChartRenderer').then(m => ({ default: m.ChartRenderer }))); interface PresentationContainerProps { /** Pipeline output data */ data: unknown; /** Pipeline ID (reserved for future use) */ pipelineId?: string; /** Supported presentation types (from pipeline config) */ supportedTypes?: PresentationType[]; /** Default presentation type */ defaultType?: PresentationType; /** Allow user to switch types */ allowSwitch?: boolean; /** Called when export is triggered (reserved for future use) */ onExport?: (format: string) => void; /** Custom className */ className?: string; } export function PresentationContainer({ data, supportedTypes, defaultType, allowSwitch = true, className = '', }: PresentationContainerProps) { const [analysis, setAnalysis] = useState(null); const [currentType, setCurrentType] = useState(null); const [isAnalyzing, setIsAnalyzing] = useState(true); useMemo(() => { const runAnalysis = async () => { setIsAnalyzing(true); try { const result = await invoke('analyze_presentation', { data }); setAnalysis(result); if (defaultType) { setCurrentType(defaultType); } else if (result) { setCurrentType(result.recommendedType); } } catch (error) { console.error('Failed to analyze presentation:', error); setCurrentType('document'); } finally { setIsAnalyzing(false); } }; runAnalysis(); }, [data, defaultType]); const handleTypeChange = useCallback((type: PresentationType) => { setCurrentType(type); }, []); const availableTypes = useMemo(() => { if (supportedTypes && supportedTypes.length > 0) { return supportedTypes.filter((t): t is PresentationType => t !== 'auto'); } return (['quiz', 'slideshow', 'document', 'chart', 'whiteboard'] as PresentationType[]); }, [supportedTypes]); const renderContent = () => { if (isAnalyzing) { return (

分析数据中...

); } switch (currentType) { case 'quiz': return [0]['data']} />; case 'slideshow': return ( }> [0]['data']} /> ); case 'document': return ( }> [0]['data']} /> ); case 'whiteboard': return (
即将推出

白板渲染器开发中

); case 'chart': return ( }> [0]['data']} /> ); default: return (

选择展示类型

); } }; return (
{allowSwitch && (
)}
{renderContent()}
); } export default PresentationContainer;