Skip to content

Commit

Permalink
fix: pagination bug
Browse files Browse the repository at this point in the history
  • Loading branch information
inaseem committed Feb 2, 2024
1 parent cf57319 commit c0e2d1e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/components/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ export const Pagination = ({
pagination.machine({
id,
count: totalItems,
page,
pageSize,
onPageChange,
})
}),
{
context: {
count: totalItems,
page,
pageSize,
onPageChange,
},
}
);

const api = pagination.connect(state, send, normalizeProps);
Expand Down
14 changes: 12 additions & 2 deletions src/components/TopNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ import BackButton from './BackButton';

const TopNav = () => {
const { pathname } = useLocation();
const [searchParams] = useSearchParams();
const [searchParams, setSearchParams] = useSearchParams();
const navigate = useNavigate();

const handleBackClick = () => {
navigate(-1);
};

const handleTitleClick = () => {
searchParams.delete(queryParamsMapping.query);
searchParams.delete(queryParamsMapping.tags);
searchParams.delete(queryParamsMapping.page);
setSearchParams(searchParams);
};

const initialSearchValue = searchParams.get(queryParamsMapping.query) || '';

const isHome = pathname === paths.root;
Expand All @@ -22,7 +29,10 @@ const TopNav = () => {
<div className="flex items-center justify-between gap-8">
<div className="flex gap-6 items-center">
{!isHome && <BackButton onClick={handleBackClick} />}
<h1 className="font-bold uppercase tracking-widest text-lg sm:text-xl">
<h1
className="font-bold uppercase tracking-widest text-lg sm:text-xl cursor-pointer"
onClick={handleTitleClick}
>
HEWS
</h1>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useHNSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const useHNSearch = () => {

const queryString = getQueryString();

const searchBy = searchQuery ? 'search_by_date' : 'search';
const searchBy = searchQuery || tags ? 'search_by_date' : 'search';

const query = useQuery({
queryKey: ['HN', queryString],
Expand Down

0 comments on commit c0e2d1e

Please sign in to comment.