diff --git a/frontend/src/app/(public)/projetos/page.tsx b/frontend/src/app/(public)/projetos/page.tsx index daeb914..78d91df 100644 --- a/frontend/src/app/(public)/projetos/page.tsx +++ b/frontend/src/app/(public)/projetos/page.tsx @@ -2,59 +2,67 @@ import Link from "next/link"; import { T } from "@/components/TranslatedText"; +import { useState, useEffect, useMemo } from "react"; + +interface Project { + id: string; + title: string; + category: string; + location: string | null; + description: string | null; + coverImage: string | null; + status: string; +} export default function ProjetosPage() { - // Placeholder data - will be replaced by database content - const projects = [ - { - id: 1, - title: "Adequação de Frota de Caminhões", - category: "Engenharia Veicular", - location: "Vitória, ES", - image: "https://images.unsplash.com/photo-1616401784845-180882ba9ba8?q=80&w=2070&auto=format&fit=crop", - description: "Projeto de adequação técnica de 50 caminhões para instalação de carrocerias especiais e sistemas de segurança." - }, - { - id: 2, - title: "Laudo Técnico de Guindaste Industrial", - category: "Laudos e Perícias", - location: "Serra, ES", - image: "https://images.unsplash.com/photo-1535082623926-b3a33d531740?q=80&w=2052&auto=format&fit=crop", - description: "Inspeção completa e emissão de laudo técnico para guindaste de 45 toneladas, com testes de carga e verificação estrutural." - }, - { - id: 3, - title: "Projeto de Equipamento Portuário", - category: "Projetos Mecânicos", - location: "Aracruz, ES", - image: "https://images.unsplash.com/photo-1504917595217-d4dc5ebe6122?q=80&w=2070&auto=format&fit=crop", - description: "Desenvolvimento e cálculo estrutural de Spreader para movimentação de contêineres em área portuária." - }, - { - id: 4, - title: "Adequação NR-12 de Linha de Produção", - category: "Segurança do Trabalho", - location: "Linhares, ES", - image: "https://images.unsplash.com/photo-1581092921461-eab62e97a782?q=80&w=2070&auto=format&fit=crop", - description: "Inventário e adequação de segurança de 120 máquinas operatrizes conforme norma regulamentadora NR-12." - }, - { - id: 5, - title: "Homologação de Veículos Especiais", - category: "Engenharia Veicular", - location: "Viana, ES", - image: "https://images.unsplash.com/photo-1591768793355-74d04bb6608f?q=80&w=2070&auto=format&fit=crop", - description: "Processo completo de homologação e certificação de plataformas elevatórias para distribuição urbana." - }, - { - id: 6, - title: "Sistema de Proteção Contra Quedas", - category: "Segurança do Trabalho", - location: "Cariacica, ES", - image: "https://images.unsplash.com/photo-1504328345606-18bbc8c9d7d1?q=80&w=2070&auto=format&fit=crop", - description: "Projeto e instalação de sistema de linha de vida para proteção contra quedas em operações de carga e descarga." + const [projects, setProjects] = useState([]); + const [loading, setLoading] = useState(true); + const [searchTerm, setSearchTerm] = useState(""); + const [selectedCategory, setSelectedCategory] = useState(null); + + useEffect(() => { + async function fetchProjects() { + try { + const res = await fetch("/api/projects", { cache: "no-store" }); + if (res.ok) { + const data = await res.json(); + // Filtrar apenas projetos publicados + const published = data.filter((p: Project) => p.status === "published"); + setProjects(published); + } + } catch (error) { + console.error("Erro ao carregar projetos:", error); + } finally { + setLoading(false); + } } - ]; + fetchProjects(); + }, []); + + // Extrair categorias únicas dos projetos + const categories = useMemo(() => { + const cats = new Set(); + projects.forEach((p) => { + if (p.category) cats.add(p.category); + }); + return Array.from(cats); + }, [projects]); + + // Filtrar projetos por categoria e pesquisa + const filteredProjects = useMemo(() => { + return projects.filter((project) => { + const matchesCategory = !selectedCategory || project.category === selectedCategory; + const matchesSearch = + !searchTerm || + project.title.toLowerCase().includes(searchTerm.toLowerCase()) || + project.description?.toLowerCase().includes(searchTerm.toLowerCase()) || + project.category?.toLowerCase().includes(searchTerm.toLowerCase()) || + project.location?.toLowerCase().includes(searchTerm.toLowerCase()); + return matchesCategory && matchesSearch; + }); + }, [projects, selectedCategory, searchTerm]); + + const defaultImage = "https://images.unsplash.com/photo-1504307651254-35680f356dfd?q=80&w=2070&auto=format&fit=crop"; return (
@@ -73,40 +81,137 @@ export default function ProjetosPage() { {/* Projects Grid */}
- {/* Filters (Placeholder) */} -
- - - - + {/* Search Bar */} +
+
+ setSearchTerm(e.target.value)} + className="w-full px-5 py-3 pl-12 rounded-full border border-gray-200 dark:border-white/20 bg-white dark:bg-white/5 text-secondary dark:text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent transition-all" + /> + + {searchTerm && ( + + )} +
-
- {projects.map((project) => ( -
-
-
-
-
- {project.category} -
-
-
-

{project.title}

-
- - {project.location} -
-

- {project.description} -

- - Ver Detalhes - -
-
+ {/* Category Filters */} +
+ + {categories.map((category) => ( + ))}
+ + {/* Loading State */} + {loading && ( +
+
+
+ )} + + {/* Empty State */} + {!loading && filteredProjects.length === 0 && ( +
+ +

+ Nenhum projeto encontrado +

+

+ {searchTerm || selectedCategory ? ( + Tente ajustar os filtros de busca + ) : ( + Em breve adicionaremos novos projetos + )} +

+ {(searchTerm || selectedCategory) && ( + + )} +
+ )} + + {/* Projects Grid */} + {!loading && filteredProjects.length > 0 && ( +
+ {filteredProjects.map((project) => ( +
+
+
+
+ {project.category && ( +
+ {project.category} +
+ )} +
+
+

+ {project.title} +

+ {project.location && ( +
+ + {project.location} +
+ )} + {project.description && ( +

+ {project.description} +

+ )} + + Ver Detalhes + +
+
+ ))} +
+ )} + + {/* Results Count */} + {!loading && filteredProjects.length > 0 && ( +
+ Exibindo {filteredProjects.length} de {projects.length} projetos +
+ )}