Skip to content

Commit 9dae6fe

Browse files
Merge pull request #20 from devlopersabbir/revert-17-default
Revert 17 default
2 parents 6d50f13 + bbd3af1 commit 9dae6fe

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

File renamed without changes.

src/components/contents/ProfileGrid.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ const ProfileGrid = async ({ page, searchParams }: Props) => {
1515
const currentPage = parseInt(page); // like 1
1616
const itemPerPage = 5; // we want to show 5 item in per pages
1717
const offset = (currentPage - 1) * itemPerPage; // (1 - 1) * 3 = 0
18+
const searchSkills = searchParams ? searchParams.toLowerCase().split(/[\s,]+/) : []; // regular expression to accept inputs separated by comma, space or both
19+
20+
// In order to get rid of the "error: operator does not exist: json @> json" I mannually cast the skills column to JSONB
21+
const skillsCondition = searchSkills.length > 0
22+
? sql.raw(`lower("skills"::text)::JSONB @> '${JSON.stringify(searchSkills.map(skill => skill.toLowerCase()))}'::JSONB`)
23+
: undefined;
1824

1925
const [lengths, profiles] = await Promise.all([
2026
db.select({ count: sql<number>`count(*)` }).from(users),
@@ -26,8 +32,9 @@ const ProfileGrid = async ({ page, searchParams }: Props) => {
2632
or(
2733
ilike(users.name, `%${searchParams}%`),
2834
ilike(users.location, `%${searchParams}%`),
29-
ilike(users.description, `%${searchParams}%`)
30-
)
35+
ilike(users.description, `%${searchParams}%`),
36+
skillsCondition
37+
),
3138
)
3239
.limit(itemPerPage)
3340
.offset(offset)

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)