fix: load published projects client side
This commit is contained in:
@@ -11,6 +11,8 @@ type PortfolioProject = {
|
|||||||
category: string;
|
category: string;
|
||||||
coverImage: string | null;
|
coverImage: string | null;
|
||||||
galleryImages: string[];
|
galleryImages: string[];
|
||||||
|
status: string;
|
||||||
|
createdAt?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type FallbackProject = {
|
type FallbackProject = {
|
||||||
@@ -112,7 +114,7 @@ export default function Home() {
|
|||||||
|
|
||||||
const fetchProjects = async () => {
|
const fetchProjects = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/projects?status=published&take=3', {
|
const response = await fetch('/api/projects', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
credentials: 'same-origin',
|
credentials: 'same-origin',
|
||||||
@@ -126,7 +128,16 @@ export default function Home() {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (isMounted && Array.isArray(data)) {
|
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) {
|
} catch (err) {
|
||||||
if ((err as Error).name !== 'AbortError') {
|
if ((err as Error).name !== 'AbortError') {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ interface Project {
|
|||||||
status: string;
|
status: string;
|
||||||
client: string | null;
|
client: string | null;
|
||||||
completionDate: 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";
|
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 () => {
|
const fetchProjects = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/projects?status=published', {
|
const response = await fetch('/api/projects', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
credentials: 'same-origin',
|
credentials: 'same-origin',
|
||||||
@@ -45,7 +46,15 @@ export default function ProjetosPage() {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (isMounted && Array.isArray(data)) {
|
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) {
|
} catch (err) {
|
||||||
if ((err as Error).name !== 'AbortError') {
|
if ((err as Error).name !== 'AbortError') {
|
||||||
|
|||||||
Reference in New Issue
Block a user