Skip to content

Commit 186be78

Browse files
authored
Merge pull request #21 from alexmarqs/fix/fix-category-location-pagination
fix: make category and location pages work correclty
2 parents 4c5f874 + 7c914d2 commit 186be78

File tree

6 files changed

+37
-29
lines changed

6 files changed

+37
-29
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ yarn-debug.log*
4242
yarn-error.log*
4343
.pnpm-debug.log*
4444

45+
.cursor/mcp.json
46+

apps/web/src/app/category/[category]/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,14 @@ export default async function CategoryPage({
7575

7676
return (
7777
<section className="mx-auto flex w-full max-w-5xl p-3 relative flex-1">
78-
<div className="flex flex-col gap-5 w-full">
78+
<div className="flex flex-col w-full">
7979
<h1 className="text-2xl font-bold">Tech Companies | {category} </h1>
8080
<Suspense fallback={<CompaniesListSkeleton />}>
8181
<CompaniesList
8282
allCompanies={filteredCompanies}
8383
updatedAtISODate={updatedAtISODate}
84-
allowSearchParams={false}
84+
showHeader={true}
85+
hideUpdatedAt={true}
8586
/>
8687
</Suspense>
8788
</div>

apps/web/src/app/location/[location]/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ export default async function LocationPage({
7575

7676
return (
7777
<section className="mx-auto flex w-full max-w-5xl p-3 relative">
78-
<div className="flex flex-col gap-5 w-full">
78+
<div className="flex flex-col w-full">
7979
<h1 className="text-2xl font-bold">Tech Companies in {location}</h1>
8080

8181
<Suspense fallback={<CompaniesListSkeleton />}>
8282
<CompaniesList
8383
allCompanies={filteredCompanies}
8484
updatedAtISODate={updatedAtISODate}
85-
allowSearchParams={false}
85+
showHeader={true}
86+
hideUpdatedAt={true}
8687
/>
8788
</Suspense>
8889
</div>

apps/web/src/components/CompaniesList.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ const PAGE_SIZE = 15;
1616
type CompaniesListProps = {
1717
allCompanies: Company[];
1818
updatedAtISODate: string;
19-
allowSearchParams?: boolean;
19+
showHeader?: boolean;
20+
hideUpdatedAt?: boolean;
2021
};
2122

2223
export default function CompaniesList({
2324
allCompanies,
2425
updatedAtISODate,
25-
allowSearchParams = true,
26+
showHeader = false,
27+
hideUpdatedAt,
2628
}: CompaniesListProps) {
2729
const {
2830
searchParams: { query, category, location, page },
29-
} = useSearchQueryParams(allowSearchParams);
31+
} = useSearchQueryParams();
3032

3133
const start = (page - 1) * PAGE_SIZE;
3234
const end = start + PAGE_SIZE;
@@ -56,7 +58,7 @@ export default function CompaniesList({
5658
</motion.div>
5759
) : (
5860
<div className="flex-1 font-mono" aria-label="Companies list">
59-
{allowSearchParams && (
61+
{showHeader && (
6062
<motion.div
6163
className="mb-2 text-xs w-full flex flex-wrap items-center justify-between gap-2 text-muted-foreground"
6264
initial={{ opacity: 0, y: -10 }}
@@ -67,11 +69,12 @@ export default function CompaniesList({
6769
updatedAtISODate={updatedAtISODate}
6870
totalPages={totalPages}
6971
filteredCompanies={filteredCompanies}
72+
hideUpdatedAt={hideUpdatedAt}
7073
/>
7174
</motion.div>
7275
)}
7376
<div className="flex-1 space-y-4" data-testid="companies-list">
74-
{paginatedCompanies.map((company, index) => (
77+
{paginatedCompanies.map((company, _index) => (
7578
<motion.div
7679
key={company.slug}
7780
initial={{ opacity: 0, y: 20 }}

apps/web/src/components/CompaniesListHeader.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ type CompaniesListHeaderProps = {
1515
updatedAtISODate: string;
1616
totalPages: number;
1717
filteredCompanies: Company[];
18+
hideUpdatedAt?: boolean;
1819
};
1920

2021
export const CompaniesListHeader = ({
2122
updatedAtISODate,
2223
totalPages,
2324
filteredCompanies,
25+
hideUpdatedAt,
2426
}: CompaniesListHeaderProps) => {
2527
const {
2628
setSearchParams,
@@ -32,13 +34,17 @@ export const CompaniesListHeader = ({
3234

3335
return (
3436
<>
35-
<Badge
36-
variant="outline"
37-
className="rounded-none bg-white px-1 gap-1 h-8 whitespace-nowrap"
38-
>
39-
<Clock size={14} />
40-
{formatDistanceToNow(new Date(updatedAtISODate))} ago
41-
</Badge>
37+
{!hideUpdatedAt ? (
38+
<Badge
39+
variant="outline"
40+
className="rounded-none bg-white px-1 gap-1 h-8 whitespace-nowrap"
41+
>
42+
<Clock size={14} />
43+
{formatDistanceToNow(new Date(updatedAtISODate))} ago
44+
</Badge>
45+
) : (
46+
<div className="h-8" />
47+
)}
4248
<Badge
4349
variant="outline"
4450
className="rounded-none bg-white px-1 flex items-center justify-center h-8 whitespace-nowrap"
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import {
2-
defaultSearchParams,
3-
searchParamsQueryStateKeys,
4-
} from "@/lib/search-params";
1+
import { searchParamsQueryStateKeys } from "@/lib/search-params";
52
import { useQueryStates } from "nuqs";
63
import { useMemo } from "react";
74

8-
export const useSearchQueryParams = (enabled = true) => {
5+
export const useSearchQueryParams = () => {
96
const [searchParams, setSearchParams] = useQueryStates(
107
searchParamsQueryStateKeys,
118
{
@@ -15,17 +12,15 @@ export const useSearchQueryParams = (enabled = true) => {
1512

1613
const appliedFilters = useMemo(
1714
() =>
18-
enabled
19-
? Object.entries(searchParams).filter(
20-
([key, value]) => key != "page" && !!value,
21-
)
22-
: [],
23-
[searchParams, enabled],
15+
Object.entries(searchParams).filter(
16+
([key, value]) => key != "page" && !!value,
17+
),
18+
[searchParams],
2419
);
2520

2621
return {
27-
searchParams: enabled ? searchParams : defaultSearchParams,
28-
setSearchParams: enabled ? setSearchParams : () => {},
22+
searchParams,
23+
setSearchParams,
2924
appliedFilters,
3025
};
3126
};

0 commit comments

Comments
 (0)