diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index 8181c03..e0b128b 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -52,7 +52,7 @@ const Layout: React.FC = ({ children }) => {
神机阁 diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index 5bf6958..a0cd149 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -86,6 +86,7 @@ export function AuthProvider({ children }: AuthProviderProps) { ); } +// eslint-disable-next-line react-refresh/only-export-components export function useAuth() { const context = useContext(AuthContext); if (context === undefined) { diff --git a/src/pages/AnalysisPage.tsx b/src/pages/AnalysisPage.tsx index 4224aa0..3df65f9 100644 --- a/src/pages/AnalysisPage.tsx +++ b/src/pages/AnalysisPage.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useMemo, useRef } from 'react'; +import React, { useState, useEffect, useMemo, useRef, useCallback } from 'react'; import { useAuth } from '../contexts/AuthContext'; import { localApi } from '../lib/localApi'; import { ChineseButton } from '../components/ui/ChineseButton'; @@ -42,16 +42,7 @@ const AnalysisPage: React.FC = () => { return undefined; }, [analysisType, formData.birth_date, formData.birth_time, formData.name, formData.gender]); - useEffect(() => { - loadProfile(); - }, [user]); - - // 切换分析类型时清空分析结果 - useEffect(() => { - setAnalysisResult(null); - }, [analysisType]); - - const loadProfile = async () => { + const loadProfile = useCallback(async () => { if (!user) return; try { @@ -71,7 +62,16 @@ const AnalysisPage: React.FC = () => { } catch (error) { console.error('加载档案失败:', error); } - }; + }, [user]); + + useEffect(() => { + loadProfile(); + }, [user, loadProfile]); + + // 切换分析类型时清空分析结果 + useEffect(() => { + setAnalysisResult(null); + }, [analysisType]); const handleAnalysis = async () => { if (!user) return; @@ -111,7 +111,7 @@ const AnalysisPage: React.FC = () => { case 'ziwei': response = await localApi.analysis.ziwei(birthData); break; - case 'yijing': + case 'yijing': { const yijingData = { question: formData.question, user_id: user.id, @@ -121,6 +121,7 @@ const AnalysisPage: React.FC = () => { }; response = await localApi.analysis.yijing(yijingData); break; + } default: throw new Error(`不支持的分析类型: ${analysisType}`); } diff --git a/src/pages/HistoryPage.tsx b/src/pages/HistoryPage.tsx index 35ec8e8..a664271 100644 --- a/src/pages/HistoryPage.tsx +++ b/src/pages/HistoryPage.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useCallback } from 'react'; import { useAuth } from '../contexts/AuthContext'; import { localApi } from '../lib/localApi'; import { ChineseButton } from '../components/ui/ChineseButton'; @@ -41,11 +41,7 @@ const HistoryPage: React.FC = () => { } }; - useEffect(() => { - loadHistory(); - }, [user]); - - const loadHistory = async () => { + const loadHistory = useCallback(async () => { if (!user) return; try { @@ -93,7 +89,11 @@ const HistoryPage: React.FC = () => { } finally { setLoading(false); } - }; + }, [user]); + + useEffect(() => { + loadHistory(); + }, [user, loadHistory]); const handleDeleteReading = async (readingId: string) => { if (!confirm('确定要删除这条分析记录吗?')) { @@ -122,6 +122,8 @@ const HistoryPage: React.FC = () => { const handleViewReading = (reading: NumerologyReading) => { setSelectedReading(reading); setViewingResult(true); + // 滚动到页面顶部 + window.scrollTo({ top: 0, behavior: 'smooth' }); }; const getAnalysisTypeIcon = (type: string) => { diff --git a/src/pages/HomePage.tsx b/src/pages/HomePage.tsx index b50a77f..0c18149 100644 --- a/src/pages/HomePage.tsx +++ b/src/pages/HomePage.tsx @@ -71,8 +71,8 @@ const HomePage: React.FC = () => { {/* 太极符号装饰 */}
太极八卦
diff --git a/src/pages/ProfilePage.tsx b/src/pages/ProfilePage.tsx index 37b9a41..d1f8be3 100644 --- a/src/pages/ProfilePage.tsx +++ b/src/pages/ProfilePage.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useCallback } from 'react'; import { useNavigate } from 'react-router-dom'; import { useAuth } from '../contexts/AuthContext'; import { localApi } from '../lib/localApi'; @@ -24,11 +24,7 @@ const ProfilePage: React.FC = () => { username: '' }); - useEffect(() => { - loadProfile(); - }, [user]); - - const loadProfile = async () => { + const loadProfile = useCallback(async () => { if (!user) return; try { @@ -54,7 +50,11 @@ const ProfilePage: React.FC = () => { console.error('加载档案失败:', error); toast.error('加载档案失败'); } - }; + }, [user]); + + useEffect(() => { + loadProfile(); + }, [user, loadProfile]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault();