diff --git a/frontend/app/profile/page.tsx b/frontend/app/profile/page.tsx index af34c71..5c06c25 100644 --- a/frontend/app/profile/page.tsx +++ b/frontend/app/profile/page.tsx @@ -2,6 +2,7 @@ import { useState, useEffect } from 'react' import { Navigation } from '@/components/shared/Navigation' +import { useAuth } from '@/contexts/AuthContext' interface UserProfile { id: string @@ -31,6 +32,7 @@ interface LanguageLevel { type TabType = 'profile' | 'settings' | 'level' export default function ProfilePage() { + const { updateUser } = useAuth() const [activeTab, setActiveTab] = useState('profile') const [profile, setProfile] = useState(null) const [settings, setSettings] = useState(null) @@ -91,7 +93,7 @@ export default function ProfilePage() { const tabs = [ { id: 'profile' as TabType, label: '個人資料', icon: '👤' }, - { id: 'settings' as TabType, label: '學習設定', icon: '⚙️' }, + // { id: 'settings' as TabType, label: '學習設定', icon: '⚙️' }, { id: 'level' as TabType, label: '英語程度', icon: '🎯' } ] @@ -198,6 +200,10 @@ export default function ProfilePage() { if (response.ok) { await loadData() // 重新載入資料 + + // 同步更新全域 AuthContext 中的用戶資料 + updateUser({ displayName: editForm.displayName }) + console.log('✅ 個人資料更新成功') } else { setError('儲存失敗') @@ -442,7 +448,7 @@ export default function ProfilePage() {
@@ -670,29 +676,6 @@ export default function ProfilePage() {
)} - - {/* 快速操作區 */} -
-

快速操作

-
- {[ - { href: '/review', icon: '📚', label: '開始複習', desc: '複習詞卡' }, - { href: '/generate', icon: '➕', label: '新增詞卡', desc: '建立內容' }, - { href: '/flashcards', icon: '📋', label: '管理詞卡', desc: '編輯詞卡' }, - { href: '/stats', icon: '📊', label: '學習統計', desc: '查看進度' } - ].map(action => ( - - ))} -
-
diff --git a/frontend/components/shared/Navigation.tsx b/frontend/components/shared/Navigation.tsx index 6ac7696..2eb5b0c 100644 --- a/frontend/components/shared/Navigation.tsx +++ b/frontend/components/shared/Navigation.tsx @@ -16,10 +16,10 @@ export function Navigation({ showExitLearning = false, onExitLearning }: Navigat const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false) const navItems = [ - { href: '/dashboard', label: '儀表板' }, + // { href: '/dashboard', label: '儀表板' }, { href: '/flashcards', label: '詞卡' }, { href: '/review', label: '複習' }, - { href: '/generate', label: 'AI 生成' } + { href: '/generate', label: 'AI詞卡' } ] return ( @@ -74,11 +74,11 @@ export function Navigation({ showExitLearning = false, onExitLearning }: Navigat ) : ( <> {/* 通知按鈕 - 桌面和手機都顯示 */} - + */} {/* 用戶資訊 - 只在桌面版顯示 */}
diff --git a/frontend/contexts/AuthContext.tsx b/frontend/contexts/AuthContext.tsx index b09e5d7..406d54b 100644 --- a/frontend/contexts/AuthContext.tsx +++ b/frontend/contexts/AuthContext.tsx @@ -15,6 +15,7 @@ interface AuthContextType extends AuthState { register: (username: string, email: string, password: string) => Promise<{ success: boolean; error?: string }> logout: () => void checkAuth: () => Promise + updateUser: (updatedUser: Partial) => void } const AuthContext = createContext(undefined) @@ -139,12 +140,27 @@ export const AuthProvider: React.FC = ({ children }) => { return true } + const updateUser = (updatedUser: Partial) => { + if (!state.user) return + + const newUser = { ...state.user, ...updatedUser } + + setState(prev => ({ + ...prev, + user: newUser + })) + + // 同時更新 localStorage 中的用戶資料 + localStorage.setItem('user_data', JSON.stringify(newUser)) + } + const contextValue: AuthContextType = { ...state, login, register, logout, checkAuth, + updateUser, } return (