Skip to content

Commit eb23a6d

Browse files
committed
corrigindo searchbar
1 parent 9d687f9 commit eb23a6d

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

frontend/src/API/Community.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function NewCommunity(data: CommunityProps) {
3535
}
3636
}
3737

38-
export async function GetAllCommunities(): Promise<CommunityProps[]> {
38+
export async function GetUserCommunities(): Promise<CommunityProps[]> {
3939
try{
4040
const response = await api.get<CommunityProps[]>('/api/user/communities', getAuthHeader());
4141
return response.data
@@ -110,4 +110,14 @@ export async function LeaveCommunity(communityId: string) {
110110
}
111111
throw new Error("Erro ao sair da comunidade.");
112112
}
113+
}
114+
115+
export async function GetAllCommunities(): Promise<CommunityProps[]> {
116+
try{
117+
const response = await api.get<CommunityProps[]>('/api/communities', getAuthHeader());
118+
return response.data
119+
}catch(error){
120+
console.error("Erro ao obter todas as comunidades:", error);
121+
throw new Error('Erro ao obter todas as comunidades');
122+
}
113123
}

frontend/src/components/domain/Searchbar/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export default function Searchbar() {
2525
const [filteredCommunities, setFilteredCommunities] = useState<CommunityProps[]>([]);
2626
const [filteredProjects, setFilteredProjects] = useState<ProjectProps[]>([]);
2727

28-
// Carrega dados APENAS na primeira vez que o usuário foca na busca (para economizar recursos)
2928
const handleFocus = async () => {
3029
setIsFocused(true);
3130
if (allCommunities.length === 0 && allProjects.length === 0) {

frontend/src/components/layout/Sidebar/Sidebar.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('Componente Sidebar', () => {
5353
expect(screen.getByText('COMUNIDADES')).toBeInTheDocument();
5454

5555
// Aguarda o useEffect terminar para limpar warnings
56-
await waitFor(() => expect(CommunityAPI.GetAllCommunities).toHaveBeenCalled());
56+
await waitFor(() => expect(CommunityAPI.GetUserCommunities).toHaveBeenCalled());
5757
});
5858

5959
it('deve buscar e listar as comunidades do usuário', async () => {
@@ -101,6 +101,6 @@ describe('Componente Sidebar', () => {
101101
fireEvent.click(screen.getByTestId('communities-header'));
102102
expect(screen.getByTestId('communities-list')).toBeInTheDocument();
103103

104-
await waitFor(() => expect(CommunityAPI.GetAllCommunities).toHaveBeenCalled());
104+
await waitFor(() => expect(CommunityAPI.GetUserCommunities).toHaveBeenCalled());
105105
});
106106
});

frontend/src/components/layout/Sidebar/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState } from 'react';
22
import { FiHome, FiChevronDown } from 'react-icons/fi';
3-
import { GetAllCommunities } from '../../../API/Community';
3+
import { GetUserCommunities } from '../../../API/Community';
44
import * as S from './styles';
55
import type { CommunityProps } from '../../../API/Community';
66
import { useAuth } from '../../../API/AuthContext';
@@ -21,7 +21,7 @@ export default function Sidebar() {
2121
const fetchCommunities = async () => {
2222
try {;
2323

24-
const apiUserCommunities = await GetAllCommunities();
24+
const apiUserCommunities = await GetUserCommunities();
2525
console.log("Comunidades do usuário:", apiUserCommunities);
2626
setUserCommunities(apiUserCommunities);
2727

0 commit comments

Comments
 (0)