fix: resolve TypeScript build errors in admin learning pages
All checks were successful
Deploy Admin Frontend / build-and-deploy (push) Successful in 9s

- Remove 5 unused antd imports (Card, Descriptions, message, Spin, Alert)
- Add PaginatedResponse<T> interface for typed API responses
- Add explicit return types to all learningAdminAPI functions
- Remove unused isLoading from UserDiagnosePage / MaterialDiagnosePage

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
wangdl 2026-06-10 22:42:59 +08:00
parent 5bfac05bec
commit ea73400857
2 changed files with 28 additions and 18 deletions

View File

@ -1,5 +1,5 @@
import { useState } from 'react';
import { Table, Card, Input, Select, Space, Tag, Descriptions, Button, message, Spin, Alert, Tabs } from 'antd';
import { Table, Input, Select, Space, Tag, Button, Tabs } from 'antd';
import { useQuery } from '@tanstack/react-query';
import { learningAdminAPI } from '../../services/learningAdmin';
@ -171,7 +171,7 @@ export function AnomalyPage() {
export function UserDiagnosePage() {
const [userId, setUserId] = useState('');
const { data, isLoading, refetch } = useQuery({
const { data, refetch } = useQuery({
queryKey: ['admin-user-diag', userId],
queryFn: () => learningAdminAPI.getUserDiagnose(userId),
enabled: false,
@ -183,7 +183,7 @@ export function UserDiagnosePage() {
<Input placeholder="User ID" value={userId} onChange={e => setUserId(e.target.value)} style={{ width: 300 }} />
<Button type="primary" onClick={() => refetch()}></Button>
</Space>
{data && <pre style={{ background: '#f5f5f5', padding: 16, borderRadius: 8, overflow: 'auto', maxHeight: 600 }}>{JSON.stringify(data, null, 2)}</pre>}
{data ? <pre style={{ background: '#f5f5f5', padding: 16, borderRadius: 8, overflow: 'auto', maxHeight: 600 }}>{JSON.stringify(data, null, 2)}</pre> : null}
</PageWrapper>
);
}
@ -192,7 +192,7 @@ export function UserDiagnosePage() {
export function MaterialDiagnosePage() {
const [materialId, setMaterialId] = useState('');
const { data, isLoading, refetch } = useQuery({
const { data, refetch } = useQuery({
queryKey: ['admin-mat-diag', materialId],
queryFn: () => learningAdminAPI.getMaterialDiagnose(materialId),
enabled: false,
@ -204,7 +204,7 @@ export function MaterialDiagnosePage() {
<Input placeholder="Material ID" value={materialId} onChange={e => setMaterialId(e.target.value)} style={{ width: 300 }} />
<Button type="primary" onClick={() => refetch()}></Button>
</Space>
{data && <pre style={{ background: '#f5f5f5', padding: 16, borderRadius: 8, overflow: 'auto', maxHeight: 600 }}>{JSON.stringify(data, null, 2)}</pre>}
{data ? <pre style={{ background: '#f5f5f5', padding: 16, borderRadius: 8, overflow: 'auto', maxHeight: 600 }}>{JSON.stringify(data, null, 2)}</pre> : null}
</PageWrapper>
);
}

View File

@ -1,5 +1,15 @@
const BASE = '/api/admin/learning';
export interface PaginatedResponse<T> {
items: T[];
total: number;
}
interface AnomalyData {
deltaOutliers: unknown[];
futureEvents: unknown[];
}
async function getApi<T>(path: string, params?: Record<string, any>): Promise<T> {
let url = `${BASE}${path}`;
if (params) {
@ -35,17 +45,17 @@ export interface DashboardData {
export const learningAdminAPI = {
getDashboard: () => getApi<DashboardData>('/dashboard'),
getReadingEvents: (params?: Record<string, any>) => getApi('/reading-events', params),
getFailedEvents: (params?: Record<string, any>) => getApi('/reading-events/failed', params),
getSessions: (params?: Record<string, any>) => getApi('/sessions', params),
getProgress: (params?: Record<string, any>) => getApi('/progress', params),
getDailyActivities: (params?: Record<string, any>) => getApi('/daily-activities', params),
getRecords: (params?: Record<string, any>) => getApi('/records', params),
getUserTimeline: (userId: string) => getApi('/user-timeline', { userId }),
getUserDiagnose: (userId: string) => getApi('/user-diagnose', { userId }),
getMaterialDiagnose: (materialId: string) => getApi('/material-diagnose', { materialId }),
getAnomalies: () => getApi('/anomalies'),
getTemporaryMaterials: (params?: Record<string, any>) => getApi('/temporary-materials', params),
recalculate: () => postApi('/recalculate'),
exportData: (type: string) => getApi('/export', { type }),
getReadingEvents: (params?: Record<string, any>) => getApi<PaginatedResponse<unknown>>('/reading-events', params),
getFailedEvents: (params?: Record<string, any>) => getApi<PaginatedResponse<unknown>>('/reading-events/failed', params),
getSessions: (params?: Record<string, any>) => getApi<PaginatedResponse<unknown>>('/sessions', params),
getProgress: (params?: Record<string, any>) => getApi<PaginatedResponse<unknown>>('/progress', params),
getDailyActivities: (params?: Record<string, any>) => getApi<PaginatedResponse<unknown>>('/daily-activities', params),
getRecords: (params?: Record<string, any>) => getApi<PaginatedResponse<unknown>>('/records', params),
getUserTimeline: (userId: string) => getApi<unknown>('/user-timeline', { userId }),
getUserDiagnose: (userId: string) => getApi<unknown>('/user-diagnose', { userId }),
getMaterialDiagnose: (materialId: string) => getApi<unknown>('/material-diagnose', { materialId }),
getAnomalies: () => getApi<AnomalyData>('/anomalies'),
getTemporaryMaterials: (params?: Record<string, any>) => getApi<PaginatedResponse<unknown>>('/temporary-materials', params),
recalculate: () => postApi<unknown>('/recalculate'),
exportData: (type: string) => getApi<unknown>('/export', { type }),
};