Skip to content

Commit

Permalink
LB-1647: use anchor links in MissingData pagination
Browse files Browse the repository at this point in the history
Instead of using links as buttons and navigating programmatically, preventing opening in new tab for example
  • Loading branch information
MonkeyDo committed Oct 19, 2024
1 parent 7d4f7f5 commit 1cd6f70
Showing 1 changed file with 11 additions and 39 deletions.
50 changes: 11 additions & 39 deletions frontend/js/src/settings/missing-data/MissingMBData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import * as React from "react";

import { faLink, faTrashAlt } from "@fortawesome/free-solid-svg-icons";
import { useLocation, useSearchParams } from "react-router-dom";
import { Link, useLocation, useSearchParams } from "react-router-dom";
import { toast } from "react-toastify";
import { Helmet } from "react-helmet";

Expand Down Expand Up @@ -172,24 +172,6 @@ export default function MissingMBDataPage() {
}
};

const handleClickPrevious = () => {
if (currPage && currPage > 1) {
setLoading(true);
const updatedPage = currPage - 1;
setSearchParams({ page: updatedPage.toString() });
afterDisplay();
}
};

const handleClickNext = () => {
if (currPage && currPage < totalPages) {
setLoading(true);
const updatedPage = currPage + 1;
setSearchParams({ page: updatedPage.toString() });
afterDisplay();
}
};

// Effects
React.useEffect(() => {
// Set the ?page search param in URL on startup if not set, as well as
Expand Down Expand Up @@ -403,36 +385,26 @@ export default function MissingMBDataPage() {
})}
</div>
<ul className="pager" style={{ display: "flex" }}>
<li
className={`previous ${currPage && currPage <= 1 ? "hidden" : ""}`}
>
<a
<li className={`previous ${currPage <= 1 ? "disabled" : ""}`}>
<Link
to={`?page=${Math.max(currPage - 1, 1)}`}
role="button"
onClick={handleClickPrevious}
onKeyDown={(e) => {
if (e.key === "Enter") handleClickPrevious();
}}
tabIndex={0}
aria-disabled={currPage >= totalPages}
>
&larr; Previous
</a>
</Link>
</li>
<li
className={`next ${
currPage && currPage >= totalPages ? "hidden" : ""
}`}
className={`next ${currPage >= totalPages ? "disabled" : ""}`}
style={{ marginLeft: "auto" }}
>
<a
<Link
to={`?page=${Math.min(currPage + 1, totalPages)}`}
role="button"
onClick={handleClickNext}
onKeyDown={(e) => {
if (e.key === "Enter") handleClickNext();
}}
tabIndex={0}
aria-disabled={currPage >= totalPages}
>
Next &rarr;
</a>
</Link>
</li>
</ul>
</div>
Expand Down

0 comments on commit 1cd6f70

Please sign in to comment.