Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: SkYNewZ/gh-stars-search-engine
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9a86576311a447ac90c606dbcc0ab8f1eacbba7b
Choose a base ref
..
head repository: SkYNewZ/gh-stars-search-engine
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 398a85f1c2cc3fe173b23419097f642b03a5c77c
Choose a head ref
Showing with 5 additions and 7 deletions.
  1. +5 −7 ui/src/pages/Results.tsx
12 changes: 5 additions & 7 deletions ui/src/pages/Results.tsx
Original file line number Diff line number Diff line change
@@ -12,17 +12,17 @@ const Results = () => {
const [result, setResult] = useState<Result>();
const query = searchParams.get("q");
const page = searchParams.get("p");
const from = (Number(page) - 1) * SIZE;

useEffect(() => {
if (query && page) {
const from = (Number(page) - 1) * SIZE;
fetch(`http://localhost:8080/search?q=${query}&from=${from}&size=${SIZE}`)
.then((response) => response.json())
.then((result) => setResult(result));
} else {
navigate("/");
}
}, [navigate, query, page]);
}, [navigate, from, query, page]);

const handlePagination = (type: "previous" | "next"): void => {
const newPage = type === "previous" ? Number(page) - 1 : Number(page) + 1;
@@ -81,11 +81,9 @@ const Results = () => {
<div className="hidden sm:block">
<p className="text-sm text-gray-700">
Showing <span className="font-medium">{page}</span> to{" "}
<span className="font-medium">
{Math.ceil(result.total_hits / SIZE)}
</span>{" "}
of <span className="font-medium">{result.total_hits}</span>{" "}
results (
<span className="font-medium">{from}</span> of{" "}
<span className="font-medium">{result.total_hits}</span> results
(
<span className="font-medium">
{(result.took / 1000).toFixed(1)}
</span>{" "}