From b7c695bb4e59f2db2c8c73c12713e941ceb89a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=84=AD=E6=B2=9B=E8=BB=92?= Date: Wed, 8 Oct 2025 00:18:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=84=AA=E5=8C=96=E7=94=A8=E6=88=B6?= =?UTF-8?q?=E9=AB=94=E9=A9=97=E8=88=87=E7=95=8C=E9=9D=A2=E8=A8=AD=E8=A8=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修復用戶名稱更新後導航欄不即時更新的問題 - 新增 AuthContext.updateUser 方法同步全域用戶狀態 - 隱藏導航欄通知鈴鐺按鈕 - 隱藏儀表板導航項目 - 隱藏個人資料頁面的學習設定分頁 - 調整登出按鈕顏色為較溫和的灰色 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- frontend/app/profile/page.tsx | 33 ++++++----------------- frontend/components/shared/Navigation.tsx | 8 +++--- frontend/contexts/AuthContext.tsx | 16 +++++++++++ 3 files changed, 28 insertions(+), 29 deletions(-) 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 (