Prechádzať zdrojové kódy

♻️ refactor(profile): 优化用户资料页面数据获取逻辑

- 移除本地状态管理,直接从useAuth获取用户资料和加载状态
- 简化用户头像URL获取方式,使用userProfile.avatarFile.fullUrl替代原逻辑
- 删除冗余的useEffect生命周期钩子
- 统一loading状态命名为isLoading并从useAuth获取
yourname 4 mesiacov pred
rodič
commit
5697391689
1 zmenil súbory, kde vykonal 12 pridanie a 13 odobranie
  1. 12 13
      mini/src/pages/profile/index.tsx

+ 12 - 13
mini/src/pages/profile/index.tsx

@@ -10,19 +10,18 @@ import { Navbar } from '@/components/ui/navbar'
 import './index.css'
 
 const ProfilePage: React.FC = () => {
-  const [userProfile, setUserProfile] = useState<UserProfile | null>(null)
-  const [loading, setLoading] = useState(true)
-  const { user, logout } = useAuth()
+  // const [userProfile, setUserProfile] = useState<UserProfile | null>(null)
+  const { user: userProfile, logout, isLoading: loading } = useAuth()
 
-  useEffect(() => {
-    if (user) {
-      setUserProfile({
-        ...user,
-        avatar: user.avatar || 'https://images.unsplash.com/photo-1494790108755-2616b612b786?w=160&h=160&fit=crop&crop=face',
-      })
-    }
-    setLoading(false)
-  }, [user])
+  // useEffect(() => {
+  //   if (user) {
+  //     setUserProfile({
+  //       ...user,
+  //       avatar: user.avatar || 'https://images.unsplash.com/photo-1494790108755-2616b612b786?w=160&h=160&fit=crop&crop=face',
+  //     })
+  //   }
+  //   setLoading(false)
+  // }, [user])
 
   const handleLogout = async () => {
     try {
@@ -144,7 +143,7 @@ const ProfilePage: React.FC = () => {
             <View className="relative">
               <Image
                className="w-24 h-24 border-4 border-white shadow-lg"
-               src={userProfile.avatar || 'https://images.unsplash.com/photo-1494790108755-2616b612b786?w=160&h=160&fit=crop&crop=face'}
+               src={userProfile.avatarFile?.fullUrl || 'https://images.unsplash.com/photo-1494790108755-2616b612b786?w=160&h=160&fit=crop&crop=face'}
                mode="aspectFill"
                rounded="full"
              />