@@ -5,12 +5,8 @@ import * as S from './styles';
55import * as D from '../../components/common/Dropdown/styles' ;
66import type { ProjectProps } from '../../API/Project' ;
77import type { CommentProps } from '../../API/Comment' ;
8-
9- // 3. Tipagem do Usuário
10- type UserProps = {
11- username : string ;
12- avatarUrl : string ;
13- } ;
8+ import { GetUserProjects } from '../../API/Project' ;
9+ import { useAuth } from '../../API/AuthContext' ;
1410
1511// --- ÍCONES ---
1612const PostsIcon = ( ) => (
@@ -34,43 +30,23 @@ const SettingsIcon = () => (
3430type ViewState = 'posts' | 'comments' ;
3531
3632export default function Profile ( ) {
33+ const { currentUser, logout } = useAuth ( ) ;
3734 const [ view , setView ] = useState < ViewState > ( 'posts' ) ;
3835 const [ isMenuOpen , setIsMenuOpen ] = useState ( false ) ;
3936 const menuRef = useRef < HTMLDivElement > ( null ) ;
4037
4138 // Estados para os dados da API
42- const [ user , setUser ] = useState < UserProps | null > ( null ) ;
4339 const [ userPosts , setUserPosts ] = useState < ProjectProps [ ] > ( [ ] ) ;
4440 const [ userComments , setUserComments ] = useState < CommentProps [ ] > ( [ ] ) ;
4541
46- // Simulação de chamada de API (useEffect)
4742 useEffect ( ( ) => {
4843 // Função assíncrona para buscar todos os dados
44+ console . log ( "Efeito de busca de dados do perfil disparado." ) ;
4945 const fetchProfileData = async ( ) => {
5046 try { ;
51-
52- // Dados que viriam da sua API
53- const apiUserData : UserProps = {
54- username : 'ceci' ,
55- avatarUrl : '' // URL da imagem do avatar
56- } ;
5747
58- const apiUserPosts : ProjectProps [ ] = [
59- {
60- name : 'Projeto CTable (React)' ,
61- description : 'Este é o projeto que estamos construindo agora!' ,
62- technologies : [ 'React' , 'TypeScript' , 'Node.js' ] ,
63- status : 'em-andamento' ,
64- date : '10/11/2025'
65- } ,
66- {
67- name : 'API de Análise de Dados' ,
68- description : 'Um backend em Python para análise.' ,
69- technologies : [ 'Python' , 'Django' ] ,
70- status : 'finalizado' ,
71- date : '01/08/2025'
72- }
73- ] ;
48+ console . log ( "Usuário atual no Profile:" , currentUser ) ;
49+ const apiUserPosts = await GetUserProjects ( ) ;
7450
7551 const apiUserComments : CommentProps [ ] = [
7652 {
@@ -80,18 +56,17 @@ export default function Profile() {
8056 }
8157 ] ;
8258
83- // Atualiza os estados
84- setUser ( apiUserData ) ;
8559 setUserPosts ( apiUserPosts ) ;
8660 setUserComments ( apiUserComments ) ;
8761
8862 } catch ( error ) {
8963 console . error ( "Falha ao buscar dados do perfil:" , error ) ;
9064 }
65+
9166 } ;
92-
93- fetchProfileData ( ) ;
94- } , [ ] ) ; // O array vazio [] garante que isso rode apenas uma vez
67+ if ( currentUser )
68+ fetchProfileData ( ) ;
69+ } , [ currentUser ] ) ;
9570
9671 // Lógica para fechar o menu ao clicar fora
9772 useEffect ( ( ) => {
@@ -110,11 +85,13 @@ export default function Profile() {
11085
11186 // Função para renderizar o feed (posts ou comentários)
11287 const renderFeed = ( ) => {
113-
11488 if ( view === 'posts' ) {
115- // Mapeia 'userPosts' e passa o 'post' (ProjectProps)
116- return userPosts . map ( post => (
117- < S . PostContainer >
89+ if ( userPosts . length === 0 ) {
90+ return < p style = { { color : '#fff' , padding : '20px' } } > Nenhum projeto encontrado.</ p > ;
91+ }
92+
93+ return userPosts . map ( ( post , index ) => (
94+ < S . PostContainer key = { index } >
11895 < Postcard post = { post } showMenu = { true } />
11996 </ S . PostContainer >
12097 ) ) ;
@@ -179,10 +156,10 @@ export default function Profile() {
179156 < S . ProfileInfo >
180157 < S . ProfileAvatar
181158 style = { {
182- backgroundImage : user ?. avatarUrl ? `url( ${ user . avatarUrl } )` : undefined
159+ backgroundImage : undefined
183160 } }
184161 />
185- < S . Username > { user ? user . username : ' ...'} </ S . Username >
162+ < S . Username > { currentUser ?. nomeCompleto || currentUser ? .username || 'Carregando ...'} </ S . Username >
186163 </ S . ProfileInfo >
187164
188165 < S . PostList >
0 commit comments