Skip to content

Commit 09e7be2

Browse files
authored
Merge branch 'main' into replace-clearbit-logos
2 parents dd4616f + edc017a commit 09e7be2

File tree

4 files changed

+54
-12
lines changed

4 files changed

+54
-12
lines changed

apps/web/src/app/(pages)/(dashboard)/(roles)/page.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import { useState } from "react";
4+
import { useSearchParams } from "next/navigation";
45
import { ChevronDown } from "lucide-react";
56

67
import type { RoleType } from "@cooper/db/schema";
@@ -20,10 +21,17 @@ import { RoleInfo } from "~/app/_components/reviews/role-info";
2021
import { api } from "~/trpc/react";
2122

2223
export default function Roles() {
24+
const searchParams = useSearchParams();
25+
const searchValue = searchParams.get("search") ?? ""; // Get search query from URL
26+
2327
const [selectedFilter, setSelectedFilter] = useState<
2428
"default" | "rating" | "newest" | "oldest" | undefined
2529
>("default");
26-
const roles = api.role.list.useQuery({ sortBy: selectedFilter });
30+
const roles = api.role.list.useQuery({
31+
sortBy: selectedFilter,
32+
search: searchValue,
33+
});
34+
2735
const buttonStyle =
2836
"bg-white hover:bg-cooper-gray-200 border-white text-black p-2";
2937

apps/web/src/app/(pages)/(dashboard)/companies/page.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22

33
import { useRouter } from "next/navigation";
44

5+
import { useSearchParams } from "next/navigation";
56
import { CompanyCardPreview } from "~/app/_components/companies/company-card-preview";
67
import LoadingResults from "~/app/_components/loading-results";
78
import NoResults from "~/app/_components/no-results";
89
import { api } from "~/trpc/react";
910

1011
export default function Companies() {
11-
const companies = api.company.list.useQuery({});
12+
const searchParams = useSearchParams();
13+
const searchValue = searchParams.get("search") ?? ""; // Get search query from URL
14+
15+
const companies = api.company.list.useQuery({
16+
search: searchValue,
17+
});
1218

1319
const router = useRouter();
1420

apps/web/src/app/_components/reviews/role-info.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useState } from "react";
44
import Image from "next/image";
5+
import Link from "next/link";
56

67
import type { ReviewType, RoleType } from "@cooper/db/schema";
78
import { cn } from "@cooper/ui";
@@ -279,8 +280,14 @@ export function RoleInfo({ className, roleObj }: RoleCardProps) {
279280
<div className="col-span-2" id="reviews">
280281
<CollapsableInfoCard title="Reviews">
281282
{reviews.isSuccess && reviews.data.length === 0 && (
282-
<div className="flex h-full w-full items-center justify-center text-[#5a5a5a]">
283-
No reviews yet!
283+
<div className="flex h-full w-full flex-col items-center justify-center text-[#5a5a5a]">
284+
<p>No reviews yet</p>
285+
<Link
286+
href={`/review?id=${roleObj.id}`}
287+
className="ml-2 underline"
288+
>
289+
Add one!
290+
</Link>
284291
</div>
285292
)}
286293
{reviews.isSuccess && reviews.data.length > 0 && (

packages/api/src/router/role.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const roleRouter = {
2626
}),
2727
)
2828
.query(async ({ ctx, input }) => {
29+
let roles: RoleType[] = [];
2930
if (ctx.sortBy === "rating") {
3031
const rolesWithRatings = await ctx.db.execute(sql`
3132
SELECT
@@ -37,20 +38,40 @@ export const roleRouter = {
3738
ORDER BY avg_rating DESC
3839
`);
3940

40-
const roles = rolesWithRatings.rows.map((role) => ({
41+
roles = rolesWithRatings.rows.map((role) => ({
4142
...(role as RoleType),
4243
}));
43-
44-
const fuseOptions = ["title", "description"];
45-
return performFuseSearch<RoleType>(roles, fuseOptions, input.search);
44+
} else {
45+
roles = await ctx.db.query.Role.findMany({
46+
orderBy: ordering[ctx.sortBy],
47+
});
4648
}
4749

48-
const roles = await ctx.db.query.Role.findMany({
49-
orderBy: ordering[ctx.sortBy],
50+
// Extract unique company IDs
51+
const companyIds = [...new Set(roles.map((role) => role.companyId))];
52+
53+
// Fetch companies that match the extracted company IDs
54+
const companies = await ctx.db.query.Company.findMany({
55+
where: (company, { inArray }) => inArray(company.id, companyIds),
56+
});
57+
58+
const rolesWithCompanies = roles.map((role) => {
59+
const company = companies.find((c) => c.id === role.companyId);
60+
return {
61+
...role,
62+
companyName: company?.name ?? "",
63+
};
5064
});
5165

52-
const fuseOptions = ["title", "description"];
53-
return performFuseSearch<RoleType>(roles, fuseOptions, input.search);
66+
const fuseOptions = ["title", "description", "companyName"];
67+
68+
const searchedRoles = performFuseSearch<
69+
RoleType & { companyName: string }
70+
>(rolesWithCompanies, fuseOptions, input.search);
71+
72+
return searchedRoles.map((role) => ({
73+
...(role as RoleType),
74+
}));
5475
}),
5576

5677
getByTitle: sortableProcedure

0 commit comments

Comments
 (0)