Skip to content

Commit 1242bc6

Browse files
Merge pull request #17 from maxlshk/default
Search With Skills
2 parents 9aa1a3a + 256f287 commit 1242bc6

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

src/components/contents/ProfileGrid.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { db } from "@/database";
33
import { users } from "@/schemas";
44
import ProfileCard from "./ProfileCard";
55
import Paginations from "../pagination/Paginations";
6-
import { ilike, or, sql } from "drizzle-orm";
6+
import { ilike, or, sql, arrayContains } from "drizzle-orm";
77
import Notfound from "../shared/Notfound";
88
import Search from "../shared/search/Search";
99

@@ -16,27 +16,29 @@ const ProfileGrid = async ({ page, searchParams }: Props) => {
1616
const currentPage = parseInt(page); // like 1
1717
const itemPerPage = 5; // we want to show 5 item in per pages
1818
const offset = (currentPage - 1) * itemPerPage; // (1 - 1) * 3 = 0
19+
const searchSkills = searchParams ? searchParams.split(',') : []; // Assuming skills are searched by a comma-separated string in searchParams
1920

2021
const [lengths, profiles] = await Promise.all([
2122
db.select({ count: sql<number>`count(*)` }).from(users),
2223
searchParams
2324
? db
24-
.select()
25-
.from(users)
26-
.where(
27-
or(
28-
ilike(users.name, `%${searchParams}%`),
29-
ilike(users.location, `%${searchParams}%`),
30-
),
31-
)
32-
.limit(itemPerPage)
33-
.offset(offset)
25+
.select()
26+
.from(users)
27+
.where(
28+
or(
29+
ilike(users.name, `%${searchParams}%`),
30+
ilike(users.location, `%${searchParams}%`),
31+
...(searchSkills.length > 0 ? [arrayContains(users.skills, searchSkills)] : [])
32+
),
33+
)
34+
.limit(itemPerPage)
35+
.offset(offset)
3436
: db
35-
.select()
36-
.from(users)
37-
.orderBy(sql.raw("RANDOM()"))
38-
.limit(itemPerPage)
39-
.offset(offset),
37+
.select()
38+
.from(users)
39+
.orderBy(sql.raw("RANDOM()"))
40+
.limit(itemPerPage)
41+
.offset(offset),
4042
]);
4143
const count = lengths[0].count;
4244
return (

src/components/forms/SearchProfiles.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const SearchProfiles = () => {
2929
type="text"
3030
value={queryString}
3131
className="text-lg p-6 text-gray-800 dark:text-white rounded-br-xl backdrop-blur-3xl bg-white/95 dark:bg-zinc-700 shadow-sm"
32-
placeholder="Search developer by name, and locations"
32+
placeholder="Search developer by name, skills or locations"
3333
/>
3434
<SearchIcon
3535
size={30}

0 commit comments

Comments
 (0)