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

@@ -11,6 +11,8 @@ type PortfolioProject = {
category: string;
coverImage: string | null;
galleryImages: string[];
status: string;
createdAt?: string;
};
type FallbackProject = {
@@ -112,7 +114,7 @@ export default function Home() {
const fetchProjects = async () => {
try {
const response = await fetch('/api/projects?status=published&take=3', {
const response = await fetch('/api/projects', {
method: 'GET',
cache: 'no-store',
credentials: 'same-origin',
@@ -126,7 +128,16 @@ export default function Home() {
const data = await response.json();
if (isMounted && Array.isArray(data)) {
setLatestProjects(data);
const publishedProjects = data
.filter((project: PortfolioProject) => 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;
})
.slice(0, 3);
setLatestProjects(publishedProjects);
}
} catch (err) {
if ((err as Error).name !== 'AbortError') {