'use client'; import { useState, useEffect } from 'react'; import { Container, Box, Typography, CircularProgress, Stack, useTheme } from '@mui/material'; import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline'; import Navbar from '@/components/Navbar/index'; import HeroSection from '@/components/home/HeroSection'; import ProjectList from '@/components/home/ProjectList'; import CreateProjectDialog from '@/components/home/CreateProjectDialog'; import MigrationDialog from '@/components/home/MigrationDialog'; import { motion } from 'framer-motion'; import { useTranslation } from 'react-i18next'; export default function Home() { const { t } = useTranslation(); const [projects, setProjects] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [createDialogOpen, setCreateDialogOpen] = useState(false); const [unmigratedProjects, setUnmigratedProjects] = useState([]); const [migrationDialogOpen, setMigrationDialogOpen] = useState(false); useEffect(() => { async function fetchProjects() { try { setLoading(true); // 获取用户创建的项目详情 const response = await fetch(`/api/projects`); if (!response.ok) { throw new Error(t('projects.fetchFailed')); } const data = await response.json(); setProjects(data); // 检查是否有未迁移的项目 await checkUnmigratedProjects(); } catch (error) { console.error(t('projects.fetchError'), String(error)); setError(String(error)); } finally { setLoading(false); } } // 检查未迁移的项目 async function checkUnmigratedProjects() { try { const response = await fetch('/api/projects/unmigrated'); if (!response.ok) { console.error('检查未迁移项目失败'); return; } const { success, data } = await response.json(); if (success && Array.isArray(data) && data.length > 0) { setUnmigratedProjects(data); setMigrationDialogOpen(true); } } catch (error) { console.error('检查未迁移项目出错', error); } } fetchProjects(); }, []); const theme = useTheme(); return (
setCreateDialogOpen(true)} /> {/* */} {loading && ( {t('projects.loading')} )} {error && !loading && ( {t('projects.fetchFailed')}: {error} )} {!loading && ( setCreateDialogOpen(true)} /> )} setCreateDialogOpen(false)} /> {/* 项目迁移对话框 */} setMigrationDialogOpen(false)} projectIds={unmigratedProjects} />
); }