fix: load published projects client side
This commit is contained in:
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user