fix: load published projects client side

This commit is contained in:
Erik
2025-11-27 16:49:41 -03:00
parent f69e0a10c4
commit 191127b3b3
2 changed files with 24 additions and 4 deletions

View File

@@ -14,6 +14,7 @@ interface Project {
status: string;
client: string | null;
completionDate: string | null;
createdAt?: string;
}
const FALLBACK_IMAGE = "https://images.unsplash.com/photo-1616401784845-180882ba9ba8?q=80&w=2070&auto=format&fit=crop";
@@ -31,7 +32,7 @@ export default function ProjetosPage() {
const fetchProjects = async () => {
try {
const response = await fetch('/api/projects?status=published', {
const response = await fetch('/api/projects', {
method: 'GET',
cache: 'no-store',
credentials: 'same-origin',
@@ -45,7 +46,15 @@ export default function ProjetosPage() {
const data = await response.json();
if (isMounted && Array.isArray(data)) {
setProjects(data);
const publishedProjects = (data as Project[])
.filter((project) => project.status !== 'Rascunho')
.sort((a, b) => {
const dateA = a.createdAt ? new Date(a.createdAt).getTime() : 0;
const dateB = b.createdAt ? new Date(b.createdAt).getTime() : 0;
return dateB - dateA;
});
setProjects(publishedProjects);
}
} catch (err) {
if ((err as Error).name !== 'AbortError') {