Skip to content

Commit 72c1689

Browse files
[issue 🤞] filtering
1 parent 1242bc6 commit 72c1689

2 files changed

Lines changed: 27 additions & 20 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "finddevs",
33
"description": "Discover All Developers From The Programming World",
4-
"version": "0.1.6",
5-
"private": true,
4+
"version": "0.1.7",
5+
"private": false,
66
"scripts": {
77
"dev": "next dev",
88
"build": "next build",

src/components/contents/ProfileGrid.tsx

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ 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, arrayContains } from "drizzle-orm";
6+
import {
7+
ilike,
8+
or,
9+
sql,
10+
arrayContained,
11+
arrayContains,
12+
arrayOverlaps,
13+
} from "drizzle-orm";
714
import Notfound from "../shared/Notfound";
815
import Search from "../shared/search/Search";
916

@@ -16,30 +23,30 @@ const ProfileGrid = async ({ page, searchParams }: Props) => {
1623
const currentPage = parseInt(page); // like 1
1724
const itemPerPage = 5; // we want to show 5 item in per pages
1825
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
2026

2127
const [lengths, profiles] = await Promise.all([
2228
db.select({ count: sql<number>`count(*)` }).from(users),
2329
searchParams
2430
? db
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)
31+
.select()
32+
.from(users)
33+
.where(
34+
or(
35+
ilike(users.name, `%${searchParams}%`),
36+
ilike(users.location, `%${searchParams}%`),
37+
ilike(users.description, `%${searchParams}%`)
38+
)
39+
)
40+
.limit(itemPerPage)
41+
.offset(offset)
3642
: db
37-
.select()
38-
.from(users)
39-
.orderBy(sql.raw("RANDOM()"))
40-
.limit(itemPerPage)
41-
.offset(offset),
43+
.select()
44+
.from(users)
45+
.orderBy(sql.raw("RANDOM()"))
46+
.limit(itemPerPage)
47+
.offset(offset),
4248
]);
49+
4350
const count = lengths[0].count;
4451
return (
4552
<div className="lg:mt-32 mt-[10rem] mb-8 border-t-orange-500 lg:ml-[20rem] px-4 lg:px-6 overflow-y-scroll relative">

0 commit comments

Comments
 (0)