2025-06-18 20:02:27 +03:30
|
|
|
'use client';
|
|
|
|
|
|
2025-06-10 17:30:21 +03:30
|
|
|
import { getProjects } from '@/services/projects';
|
2025-06-18 20:02:27 +03:30
|
|
|
import { IProjectGridViewProps } from './project';
|
2025-06-10 17:30:21 +03:30
|
|
|
import ProjectsGrid from './ProjectGrid';
|
2025-06-18 20:02:27 +03:30
|
|
|
import Pagination from '@/components/layout/pagination';
|
|
|
|
|
import { useState } from 'react';
|
|
|
|
|
|
|
|
|
|
export default function ProjectsGridView({
|
|
|
|
|
initialProjects,
|
|
|
|
|
initialPagination,
|
|
|
|
|
}: IProjectGridViewProps) {
|
|
|
|
|
const [projects, setProjects] = useState(initialProjects);
|
|
|
|
|
const [pagination, setPagination] = useState(initialPagination);
|
|
|
|
|
|
|
|
|
|
const fetchPage = (page: number) => {
|
|
|
|
|
getProjects(page)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
setProjects(res.data);
|
|
|
|
|
setPagination(res.pagination);
|
2025-06-10 17:30:21 +03:30
|
|
|
|
2025-06-18 20:02:27 +03:30
|
|
|
document
|
|
|
|
|
.getElementById('projectList')
|
|
|
|
|
?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error('Failed to fetch Projects:', error);
|
|
|
|
|
});
|
|
|
|
|
};
|
2025-06-10 17:30:21 +03:30
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2025-06-18 20:02:27 +03:30
|
|
|
{projects?.length ? <ProjectsGrid projects={projects} /> : <></>}
|
|
|
|
|
<Pagination {...pagination} onPageChange={fetchPage} />
|
2025-06-10 17:30:21 +03:30
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|