Skip to content

Commit

Permalink
Merge pull request #20 from devlopersabbir/revert-17-default
Browse files Browse the repository at this point in the history
Revert 17 default
  • Loading branch information
devlopersabbir authored Mar 30, 2024
2 parents 6d50f13 + bbd3af1 commit 9dae6fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
File renamed without changes.
11 changes: 9 additions & 2 deletions src/components/contents/ProfileGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const ProfileGrid = async ({ page, searchParams }: Props) => {
const currentPage = parseInt(page); // like 1
const itemPerPage = 5; // we want to show 5 item in per pages
const offset = (currentPage - 1) * itemPerPage; // (1 - 1) * 3 = 0
const searchSkills = searchParams ? searchParams.toLowerCase().split(/[\s,]+/) : []; // regular expression to accept inputs separated by comma, space or both

// In order to get rid of the "error: operator does not exist: json @> json" I mannually cast the skills column to JSONB
const skillsCondition = searchSkills.length > 0
? sql.raw(`lower("skills"::text)::JSONB @> '${JSON.stringify(searchSkills.map(skill => skill.toLowerCase()))}'::JSONB`)
: undefined;

const [lengths, profiles] = await Promise.all([
db.select({ count: sql<number>`count(*)` }).from(users),
Expand All @@ -26,8 +32,9 @@ const ProfileGrid = async ({ page, searchParams }: Props) => {
or(
ilike(users.name, `%${searchParams}%`),
ilike(users.location, `%${searchParams}%`),
ilike(users.description, `%${searchParams}%`)
)
ilike(users.description, `%${searchParams}%`),
skillsCondition
),
)
.limit(itemPerPage)
.offset(offset)
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/SearchProfiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const SearchProfiles = () => {
type="text"
value={queryString}
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"
placeholder="Search developer by name, and locations"
placeholder="Search developer by name, skills or locations"
/>
<SearchIcon
size={30}
Expand Down

0 comments on commit 9dae6fe

Please sign in to comment.