Skip to content
Snippets Groups Projects
Commit c2788b2c authored by Štěpán Šonovský's avatar Štěpán Šonovský
Browse files

fix: total pages deleted and added disability

parent fb575dcc
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ import CsvButtons from "@/app/csvDownload/CsvButtons";
const CommitList = ({ projectId, token, host, onCommitClick }) => {
const [page, setPage] = useState(1);
const { commits, loading, error, totalPages } = useCommitsPagination(projectId, token, host, page);
const { commits, loading, error, nextPage } = useCommitsPagination(projectId, token, host, page);
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>;
......@@ -32,9 +32,9 @@ const CommitList = ({ projectId, token, host, onCommitClick }) => {
>
Previous
</button>
<span>Page {page} of {totalPages}</span>
<span>Page {page}</span>
<button
disabled={page >= totalPages}
disabled={nextPage === ""}
onClick={() => setPage(page + 1)}
className="px-4 py-2 bg-blue-500 text-white rounded"
>
......
......@@ -36,7 +36,7 @@ export const useCommitsPagination = (projectId, token, host, page = 1, perPage =
const [commits, setCommits] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const [totalPages, setTotalPages] = useState(1);
const [nextPage, setNextPage] = useState(1);
useEffect(() => {
const fetchCommits = async () => {
......@@ -47,7 +47,8 @@ export const useCommitsPagination = (projectId, token, host, page = 1, perPage =
params: { page, per_page: perPage }
});
setCommits(response.data);
setTotalPages(parseInt(response.headers['x-total-pages'], 10));
console.log(JSON.stringify(response.headers))
setNextPage(response.headers['x-next-page']);
} catch (err) {
setError(err);
} finally {
......@@ -58,6 +59,6 @@ export const useCommitsPagination = (projectId, token, host, page = 1, perPage =
fetchCommits();
}, [host, projectId, token, page, perPage]);
return { commits, loading, error, totalPages };
return { commits, loading, error, nextPage };
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment