|
| 1 | +import React, { useState } from 'react'; |
| 2 | +import { |
| 3 | + Box, |
| 4 | + Container, |
| 5 | + Typography, |
| 6 | + Alert, |
| 7 | + CircularProgress, |
| 8 | + Fade, |
| 9 | +} from '@mui/material'; |
| 10 | +import { |
| 11 | + AutoAwesome as MagicIcon, |
| 12 | + Error as ErrorIcon, |
| 13 | +} from '@mui/icons-material'; |
| 14 | +import type { ProjectRequirements, AIStackSuggestion } from '../types/stackFinder'; |
| 15 | +import { DEFAULT_PROJECT_REQUIREMENTS } from '../types/stackFinder'; |
| 16 | +import { generateStackRecommendations } from '../utils/stackRecommendation'; |
| 17 | +import { StackFinderForm } from './StackFinderForm'; |
| 18 | +import { StackRecommendations } from './StackRecommendations'; |
| 19 | + |
| 20 | +export const AIStackFinder: React.FC = () => { |
| 21 | + const [requirements, setRequirements] = useState<ProjectRequirements>(DEFAULT_PROJECT_REQUIREMENTS); |
| 22 | + const [suggestions, setSuggestions] = useState<AIStackSuggestion | null>(null); |
| 23 | + const [isGenerating, setIsGenerating] = useState(false); |
| 24 | + const [error, setError] = useState<string | null>(null); |
| 25 | + |
| 26 | + const handleRequirementsChange = (newRequirements: ProjectRequirements) => { |
| 27 | + setRequirements(newRequirements); |
| 28 | + // Clear previous results when requirements change significantly |
| 29 | + if (suggestions) { |
| 30 | + setSuggestions(null); |
| 31 | + } |
| 32 | + setError(null); |
| 33 | + }; |
| 34 | + |
| 35 | + const handleGenerateRecommendations = async () => { |
| 36 | + setIsGenerating(true); |
| 37 | + setError(null); |
| 38 | + |
| 39 | + try { |
| 40 | + // Simulate API call delay for better UX |
| 41 | + await new Promise(resolve => setTimeout(resolve, 1500)); |
| 42 | + |
| 43 | + const newSuggestions = generateStackRecommendations(requirements); |
| 44 | + setSuggestions(newSuggestions); |
| 45 | + } catch (err) { |
| 46 | + const errorMessage = err instanceof Error ? err.message : 'Failed to generate recommendations'; |
| 47 | + console.error('Error generating recommendations:', errorMessage); |
| 48 | + setError(errorMessage); |
| 49 | + } finally { |
| 50 | + setIsGenerating(false); |
| 51 | + } |
| 52 | + }; |
| 53 | + |
| 54 | + return ( |
| 55 | + <Container maxWidth="xl"> |
| 56 | + <Box sx={{ py: 2 }}> |
| 57 | + {/* Header */} |
| 58 | + <Box sx={{ textAlign: 'center', py: 2, mb: 3 }}> |
| 59 | + <Typography |
| 60 | + variant="h4" |
| 61 | + component="h1" |
| 62 | + sx={{ fontWeight: 'bold', mb: 2 }} |
| 63 | + > |
| 64 | + AI Stack Finder |
| 65 | + </Typography> |
| 66 | + <Typography |
| 67 | + variant="body1" |
| 68 | + color="text.secondary" |
| 69 | + sx={{ maxWidth: '800px', mx: 'auto' }} |
| 70 | + > |
| 71 | + Get personalized AI technology stack recommendations based on your project requirements. |
| 72 | + Our intelligent system analyzes your needs and suggests the best tools, frameworks, and services |
| 73 | + to build your AI solution efficiently and effectively. |
| 74 | + </Typography> |
| 75 | + </Box> |
| 76 | + |
| 77 | + {/* Error Display */} |
| 78 | + {error && ( |
| 79 | + <Alert |
| 80 | + severity="error" |
| 81 | + icon={<ErrorIcon />} |
| 82 | + sx={{ mb: 3 }} |
| 83 | + onClose={() => setError(null)} |
| 84 | + > |
| 85 | + <Typography variant="h6" sx={{ mb: 1 }}> |
| 86 | + Recommendation Generation Failed |
| 87 | + </Typography> |
| 88 | + <Typography variant="body2"> |
| 89 | + {error} |
| 90 | + </Typography> |
| 91 | + <Typography variant="body2" sx={{ mt: 1, fontWeight: 'bold' }}> |
| 92 | + 💡 Please try again or adjust your requirements. |
| 93 | + </Typography> |
| 94 | + </Alert> |
| 95 | + )} |
| 96 | + |
| 97 | + {/* Loading State */} |
| 98 | + {isGenerating && ( |
| 99 | + <Box sx={{ |
| 100 | + display: 'flex', |
| 101 | + flexDirection: 'column', |
| 102 | + alignItems: 'center', |
| 103 | + gap: 2, |
| 104 | + py: 4, |
| 105 | + mb: 3 |
| 106 | + }}> |
| 107 | + <CircularProgress size={60} /> |
| 108 | + <Box sx={{ textAlign: 'center' }}> |
| 109 | + <Typography variant="h6" sx={{ mb: 1 }}> |
| 110 | + Generating AI Stack Recommendations |
| 111 | + </Typography> |
| 112 | + <Typography variant="body2" color="text.secondary"> |
| 113 | + Analyzing your requirements and matching with optimal technologies... |
| 114 | + </Typography> |
| 115 | + </Box> |
| 116 | + </Box> |
| 117 | + )} |
| 118 | + |
| 119 | + {/* Main Content */} |
| 120 | + <Box sx={{ |
| 121 | + display: 'flex', |
| 122 | + flexDirection: { xs: 'column', xl: 'row' }, |
| 123 | + gap: 3, |
| 124 | + minHeight: '60vh' |
| 125 | + }}> |
| 126 | + {/* Form Section */} |
| 127 | + <Box sx={{ |
| 128 | + flex: suggestions ? { xs: 1, xl: '0 0 400px' } : 1, |
| 129 | + minWidth: 0 |
| 130 | + }}> |
| 131 | + <StackFinderForm |
| 132 | + onRequirementsChange={handleRequirementsChange} |
| 133 | + onGenerateRecommendations={handleGenerateRecommendations} |
| 134 | + isGenerating={isGenerating} |
| 135 | + /> |
| 136 | + </Box> |
| 137 | + |
| 138 | + {/* Results Section */} |
| 139 | + {suggestions && !isGenerating && ( |
| 140 | + <Fade in={true} timeout={500}> |
| 141 | + <Box sx={{ flex: 1, minWidth: 0 }}> |
| 142 | + <StackRecommendations suggestions={suggestions} /> |
| 143 | + </Box> |
| 144 | + </Fade> |
| 145 | + )} |
| 146 | + |
| 147 | + {/* Empty State */} |
| 148 | + {!suggestions && !isGenerating && !error && ( |
| 149 | + <Box sx={{ |
| 150 | + flex: 1, |
| 151 | + display: 'flex', |
| 152 | + flexDirection: 'column', |
| 153 | + alignItems: 'center', |
| 154 | + justifyContent: 'center', |
| 155 | + textAlign: 'center', |
| 156 | + py: 8, |
| 157 | + color: 'text.secondary' |
| 158 | + }}> |
| 159 | + <MagicIcon sx={{ fontSize: 80, mb: 2, opacity: 0.3 }} /> |
| 160 | + <Typography variant="h6" sx={{ mb: 1, opacity: 0.7 }}> |
| 161 | + Ready to Find Your Perfect AI Stack? |
| 162 | + </Typography> |
| 163 | + <Typography variant="body2" sx={{ maxWidth: 400, opacity: 0.6 }}> |
| 164 | + Complete the form on the left with your project requirements, |
| 165 | + and we'll generate personalized technology recommendations for your AI project. |
| 166 | + </Typography> |
| 167 | + </Box> |
| 168 | + )} |
| 169 | + </Box> |
| 170 | + |
| 171 | + {/* Footer Information */} |
| 172 | + <Box sx={{ textAlign: 'center', py: 3, mt: 4, maxWidth: 800, mx: 'auto' }}> |
| 173 | + <Typography variant="caption" color="text.secondary" sx={{ display: 'block', mb: 1 }}> |
| 174 | + <strong>AI Stack Finder</strong> uses intelligent matching algorithms to recommend |
| 175 | + technologies based on your specific requirements, constraints, and preferences. |
| 176 | + </Typography> |
| 177 | + <Typography variant="caption" color="text.secondary"> |
| 178 | + Recommendations are based on current industry best practices, community feedback, |
| 179 | + and compatibility analysis. Always validate recommendations against your specific use case. |
| 180 | + </Typography> |
| 181 | + </Box> |
| 182 | + </Box> |
| 183 | + </Container> |
| 184 | + ); |
| 185 | +}; |
| 186 | + |
0 commit comments