diff --git a/src/App.tsx b/src/App.tsx index 4190bee..5166f83 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -15,15 +15,13 @@ import { } from './refactor' import { PathPlanningPage } from './refactor/pages/PathPlanning' import { CourseContentPage } from './refactor/pages/CourseContent' -import { PathActivationDebugPage } from './refactor/pages/PathActivationDebug' // CodeRunner重构版本 (使用refactor目录下的) import { IntegratedCodeRunner } from './refactor/components/features/CodeRunner' type AppView = 'landing' | 'profile' | 'dashboard' | 'profile-settings' | 'refactor-assessment' | 'refactor-goal-management' | 'refactor-path-planning' | - 'refactor-course-content' | 'refactor-code-runner' | 'refactor-data-management' | - 'refactor-path-activation-debug' + 'refactor-course-content' | 'refactor-code-runner' | 'refactor-data-management' const App = () => { const [currentView, setCurrentView] = useState('landing') @@ -204,22 +202,9 @@ const App = () => { ) - case 'refactor-path-activation-debug': - return ( - - - - ) - default: - return void - onNavigate: (view: 'refactor-assessment' | 'refactor-goal-management' | 'refactor-path-planning' | 'refactor-course-content' | 'refactor-code-runner' | 'refactor-data-management' | 'refactor-path-activation-debug' | 'profile-settings') => void + onNavigate: (view: 'refactor-assessment' | 'refactor-goal-management' | 'refactor-path-planning' | 'refactor-course-content' | 'refactor-code-runner' | 'refactor-data-management' | 'profile-settings') => void onHome: () => void } @@ -209,20 +209,6 @@ const Dashboard: React.FC = ({ onLogout, onNavigate, onHome }) = status: '数据工具', available: true }, - { - id: 'path-activation-debug', - view: 'refactor-path-activation-debug' as const, - title: '🧪 路径激活调试', - description: '测试和验证路径激活、冻结功能是否正常工作', - icon: ( - - - - ), - color: 'from-yellow-500 to-orange-500', - status: '调试工具', - available: true - } ] return ( diff --git a/src/refactor/pages/DataManagement.tsx b/src/refactor/pages/DataManagement.tsx index d21567e..ad2a5e1 100644 --- a/src/refactor/pages/DataManagement.tsx +++ b/src/refactor/pages/DataManagement.tsx @@ -24,11 +24,10 @@ import { Alert, toast } from '../components/ui/Alert/Alert' import { ConfirmModal, Modal } from '../components/ui/Modal/Modal' import { Loading } from '../components/ui/Loading/Loading' import { ProgressBar } from '../components/ui/ProgressBar/ProgressBar' -import { learningApiV2 } from '../../api/learningApi_v2' +import { learningApi } from '../../api' // 使用any类型暂时解决类型问题 type LearningPath = any import { getCurrentProfile } from '../../utils/profile' -import { LearningAPI } from '../../api/learningApi' import { Button as UiButton, Alert as UiAlert, @@ -75,7 +74,7 @@ export const DataManagementPage: React.FC = ({ onNaviga setLoading(true) try { // 获取当前Profile - const profileResponse = learningApiV2.getCurrentProfile() + const profileResponse = learningApi.getCurrentProfile() if (!profileResponse.success || !profileResponse.data) { toast.error('无法获取当前Profile') return @@ -85,8 +84,8 @@ export const DataManagementPage: React.FC = ({ onNaviga setCurrentProfile(profile) // 获取学习数据 - 使用v2 API分别获取 - const goalsResponse = await learningApiV2.getAllGoals() - const pathsResponse = await learningApiV2.getAllPaths() + const goalsResponse = await learningApi.getAllGoals() + const pathsResponse = await learningApi.getAllPaths() const learningDataV2 = { goals: goalsResponse.data || [], @@ -160,8 +159,8 @@ export const DataManagementPage: React.FC = ({ onNaviga const handleExport = async () => { try { // v2版本暂时手动构建导出数据 - const goalsResponse = await learningApiV2.getAllGoals() - const pathsResponse = await learningApiV2.getAllPaths() + const goalsResponse = await learningApi.getAllGoals() + const pathsResponse = await learningApi.getAllPaths() const exportDataV2 = { goals: goalsResponse.data || [], @@ -193,10 +192,10 @@ export const DataManagementPage: React.FC = ({ onNaviga switch (deleteConfirm.type) { case 'goal': - result = await learningApiV2.deleteGoal(deleteConfirm.id) + result = await learningApi.deleteGoal(deleteConfirm.id) break case 'path': - result = await learningApiV2.deletePath(deleteConfirm.id) + result = await learningApi.deletePath(deleteConfirm.id) break case 'unit': // v2暂时不支持,返回失败 @@ -258,7 +257,7 @@ export const DataManagementPage: React.FC = ({ onNaviga for (const path of learningData.paths) { try { - const result = await learningApiV2.deletePath(path.id) + const result = await learningApi.deletePath(path.id) if (result.success) { successCount++ } else { @@ -286,8 +285,8 @@ export const DataManagementPage: React.FC = ({ onNaviga const handleActivatePath = async (path: LearningPath) => { console.log('🔥 [DataManagement] 激活路径操作开始:', path.id, path.title, path.status) try { - console.log('🔥 [DataManagement] 调用learningApiV2.updatePath') - const result = await learningApiV2.updatePath(path.id, { status: 'active' }) + console.log('🔥 [DataManagement] 调用learningApi.updatePath') + const result = await learningApi.updatePath(path.id, { status: 'active' }) console.log('🔥 [DataManagement] 激活路径API结果:', result) if (result.success) { @@ -308,8 +307,8 @@ export const DataManagementPage: React.FC = ({ onNaviga const handleFreezePath = async (path: LearningPath) => { console.log('❄️ [DataManagement] 冻结路径操作开始:', path.id, path.title, path.status) try { - console.log('❄️ [DataManagement] 调用learningApiV2.updatePath') - const result = await learningApiV2.updatePath(path.id, { status: 'frozen' }) + console.log('❄️ [DataManagement] 调用learningApi.updatePath') + const result = await learningApi.updatePath(path.id, { status: 'frozen' }) console.log('❄️ [DataManagement] 冻结路径API结果:', result) if (result.success) { @@ -330,8 +329,8 @@ export const DataManagementPage: React.FC = ({ onNaviga const handleArchivePath = async (path: LearningPath) => { console.log('📦 [DataManagement] 归档路径操作开始:', path.id, path.title, path.status) try { - console.log('📦 [DataManagement] 调用learningApiV2.updatePath') - const result = await learningApiV2.updatePath(path.id, { status: 'archived' }) + console.log('📦 [DataManagement] 调用learningApi.updatePath') + const result = await learningApi.updatePath(path.id, { status: 'archived' }) console.log('📦 [DataManagement] 归档路径API结果:', result) if (result.success) { @@ -972,7 +971,7 @@ export const DataManagementPage: React.FC = ({ onNaviga variant="secondary" size="sm" onClick={() => { - const allContent = LearningAPI.getInstance().getAllCourseContent() + const allContent = learningApi.getAllCourseContent() if (allContent.success) { copyToClipboard(allContent.data) } @@ -1016,7 +1015,7 @@ export const DataManagementPage: React.FC = ({ onNaviga {/* 课程内容列表 */}
{(() => { - const allContent = LearningAPI.getInstance().getAllCourseContent() + const allContent = learningApi.getAllCourseContent() if (!allContent.success || !allContent.data) return null return allContent.data.slice(0, 5).map((content: any) => ( @@ -1054,7 +1053,7 @@ export const DataManagementPage: React.FC = ({ onNaviga onClick={async () => { const confirmed = window.confirm(`确定要删除课程内容 "${content.title}" 吗?`) if (confirmed) { - const result = await LearningAPI.getInstance().deleteCourseContent(content.id) + const result = await learningApi.deleteCourseContent(content.id) if (result.success) { toast.success('课程内容已删除') await refreshData() @@ -1074,7 +1073,7 @@ export const DataManagementPage: React.FC = ({ onNaviga {/* 显示更多内容 */} {(() => { - const allContent = LearningAPI.getInstance().getAllCourseContent() + const allContent = learningApi.getAllCourseContent() if (!allContent.success || !allContent.data || allContent.data.length <= 5) return null return ( @@ -1097,7 +1096,7 @@ export const DataManagementPage: React.FC = ({ onNaviga
                     {(() => {
-                      const allContent = LearningAPI.getInstance().getAllCourseContent()
+                      const allContent = learningApi.getAllCourseContent()
                       return JSON.stringify(allContent.success ? allContent.data : [], null, 2)
                     })()}
                   
diff --git a/src/refactor/pages/PathActivationDebug.tsx b/src/refactor/pages/PathActivationDebug.tsx deleted file mode 100644 index 662b660..0000000 --- a/src/refactor/pages/PathActivationDebug.tsx +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Pointer.ai - AI驱动的个性化编程学习平台 - * Copyright (C) 2024 Pointer.ai - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import React, { useState, useEffect } from 'react' -import { Button } from '../components/ui/Button/Button' -import { Card, CardHeader, CardTitle, CardContent } from '../components/ui/Card/Card' -import { Badge } from '../components/ui/Badge/Badge' -import { toast } from '../components/ui/Alert/Alert' -import { learningApiV2 } from '../../api/learningApi_v2' - -interface PathActivationDebugProps { - onNavigate: (view: string) => void -} - -/** - * 路径激活功能调试页面 - * 用于测试和验证激活/冻结功能是否正常工作 - */ -export const PathActivationDebugPage: React.FC = ({ onNavigate }) => { - const [paths, setPaths] = useState([]) - const [loading, setLoading] = useState(false) - const [apiStatus, setApiStatus] = useState('未测试') - - // 刷新路径数据 - const refreshPaths = async () => { - console.log('🔄 刷新路径数据...') - try { - const response = await learningApiV2.getAllPaths() - console.log('📊 获取路径数据结果:', response) - - if (response.success) { - setPaths(response.data || []) - setApiStatus('API正常') - console.log('✅ 路径数据刷新成功,共', response.data?.length || 0, '条路径') - } else { - setApiStatus('API错误: ' + response.error) - console.error('❌ 获取路径失败:', response.error) - } - } catch (error) { - setApiStatus('API异常: ' + (error as Error).message) - console.error('❌ 刷新路径异常:', error) - } - } - - // 测试激活路径 - const testActivatePath = async (path: any) => { - console.log('🧪 测试激活路径:', path.id, path.title) - setLoading(true) - - try { - console.log('📡 调用 API.updatePath (status: active)...') - const result = await learningApiV2.updatePath(path.id, { status: 'active' }) - console.log('📡 API响应:', result) - - if (result.success) { - toast.success(`✅ 测试成功!路径"${path.title}"已激活`) - console.log('✅ 激活成功,刷新数据...') - await refreshPaths() - } else { - toast.error(`❌ 激活失败: ${result.error}`) - console.error('❌ 激活失败:', result.error) - } - } catch (error) { - toast.error(`❌ 激活异常: ${(error as Error).message}`) - console.error('❌ 激活异常:', error) - } finally { - setLoading(false) - } - } - - // 测试冻结路径 - const testFreezePath = async (path: any) => { - console.log('🧪 测试冻结路径:', path.id, path.title) - setLoading(true) - - try { - console.log('📡 调用 API.updatePath (status: frozen)...') - const result = await learningApiV2.updatePath(path.id, { status: 'frozen' }) - console.log('📡 API响应:', result) - - if (result.success) { - toast.success(`✅ 测试成功!路径"${path.title}"已冻结`) - console.log('✅ 冻结成功,刷新数据...') - await refreshPaths() - } else { - toast.error(`❌ 冻结失败: ${result.error}`) - console.error('❌ 冻结失败:', result.error) - } - } catch (error) { - toast.error(`❌ 冻结异常: ${(error as Error).message}`) - console.error('❌ 冻结异常:', error) - } finally { - setLoading(false) - } - } - - // 创建测试路径 - const createTestPath = async () => { - console.log('🧪 创建测试路径...') - setLoading(true) - - try { - // 首先获取一个目标 - const goalsResponse = await learningApiV2.getAllGoals() - if (!goalsResponse.success || !goalsResponse.data?.length) { - toast.error('没有可用的目标,请先创建一个目标') - return - } - - const testGoal = goalsResponse.data[0] - console.log('🎯 使用目标:', testGoal.title) - - // 使用generatePathForGoal方法创建路径,然后冻结它 - const result = await learningApiV2.generatePathForGoal(testGoal.id, { - learningStyle: 'visual', - timePreference: 'moderate', - difficultyProgression: 'gradual', - includeProjects: true, - includeExercises: true - }) - - if (result.success && result.data) { - // 生成后立即冻结,以便测试激活功能 - const freezeResult = await learningApiV2.updatePath(result.data.id, { status: 'frozen' }) - if (freezeResult.success) { - toast.success('✅ 测试路径创建并冻结成功') - } else { - toast.success('✅ 测试路径创建成功(但冻结失败)') - } - await refreshPaths() - } else { - toast.error(`❌ 创建测试路径失败: ${result.error}`) - } - } catch (error) { - toast.error(`❌ 创建测试路径异常: ${(error as Error).message}`) - console.error('❌ 创建测试路径异常:', error) - } finally { - setLoading(false) - } - } - - // 初始化 - useEffect(() => { - refreshPaths() - }, []) - - return ( -
- {/* 页面头部 */} -
-
-
-
-

🧪 路径激活功能调试

-

测试和验证路径激活/冻结功能

-
-
- - {apiStatus} - - - -
-
-
-
- -
- {/* 调试信息 */} - - - 🔍 调试信息 - - -
-
- 总路径数: - {paths.length} -
-
- 活跃路径: - {paths.filter(p => p.status === 'active').length} -
-
- 冻结路径: - {paths.filter(p => p.status === 'frozen').length} -
-
-
-

- 使用说明: -
• 点击"激活"测试冻结路径的激活功能 -
• 点击"冻结"测试活跃路径的冻结功能 -
• 查看浏览器控制台获取详细调试信息 -
• 如果没有路径,点击"创建测试路径" -

-
-
-
- - {/* 路径列表 */} - {paths.length === 0 ? ( - - -
🛤️
-

暂无路径数据

-

请先创建一个测试路径进行功能验证

- -
-
- ) : ( -
- {paths.map((path) => ( - - -
-
-

{path.title}

-
- 状态: {path.status} - 节点: {path.nodes?.length || 0}个 - ID: {path.id} -
-
- -
- - {path.status} - - - {path.status === 'frozen' && ( - - )} - - {path.status === 'active' && ( - - )} -
-
-
-
- ))} -
- )} - - {/* 底部说明 */} -
-

🔧 调试提示

-
    -
  • • 打开浏览器开发者工具的Console标签查看详细日志
  • -
  • • 所有API调用和响应都会在控制台显示
  • -
  • • 如果功能不工作,检查控制台是否有错误信息
  • -
  • • 测试完成后可以返回正常的路径管理页面
  • -
- -
-
-
- ) -} - -export default PathActivationDebugPage \ No newline at end of file