Skip to content

Commit f59030e

Browse files
committed
Refactored Filters component. Modified styles of Switch shadcn/ui component. Added target and rel attrs for imporved ux. Added filtering based on salary and skills to jobs
1 parent 8edee93 commit f59030e

File tree

7 files changed

+48
-28
lines changed

7 files changed

+48
-28
lines changed

app/(root)/jobs/page.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import LocalSearchbar from "@/components/shared/search/LocalSearchbar";
44
import JobFilters from "@/components/shared/Filters";
55
import NoResult from "@/components/shared/NoResult";
66
import Pagination from "@/components/shared/Pagination";
7-
import Switcher from "@/components/shared/Switcher";
87
import JobCard from "@/components/cards/JobCard";
98

109
import { getCountryFilters, getJobs } from "@/lib/actions/job.action";
@@ -22,14 +21,13 @@ const Page = async ({ searchParams }: SearchParamsProps) => {
2221
location: searchParams.location,
2322
remote: searchParams.remote,
2423
page: searchParams.page ? +searchParams.page : 1,
24+
wage: searchParams.wage,
25+
skills: searchParams.skills,
2526
});
2627

2728
return (
2829
<>
29-
<div className="flex flex-row items-center">
30-
<h1 className="h1-bold text-dark100_light900">Jobs</h1>
31-
<Switcher />
32-
</div>
30+
<h1 className="h1-bold text-dark100_light900">Jobs</h1>
3331

3432
<div className="mt-11 flex justify-between gap-5 max-sm:flex-col sm:items-center">
3533
<LocalSearchbar
@@ -48,7 +46,7 @@ const Page = async ({ searchParams }: SearchParamsProps) => {
4846
)}
4947
</div>
5048

51-
<JobFilters filters={JobPageFilters} />
49+
<JobFilters filters={JobPageFilters} jobFilter />
5250

5351
<div className="mt-10 flex w-full flex-col gap-6">
5452
{result.data.length > 0 ? (
@@ -78,12 +76,10 @@ const Page = async ({ searchParams }: SearchParamsProps) => {
7876
))
7977
) : (
8078
<NoResult
81-
title="No Questions Found"
82-
description="Be the first to break the silence! 🚀 Ask a Question and kickstart the
83-
discussion. our query could be the next big thing others learn from. Get
84-
involved! 💡"
85-
link="/ask-question"
86-
linkTitle="Ask a Question"
79+
title="No Jobs Found"
80+
description="We couldn't find any jobs matching your search 🤔"
81+
link="/jobs"
82+
linkTitle="Explore Jobs"
8783
/>
8884
)}
8985
</div>

components/cards/JobCard.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const JobCard = ({
8484
<h4 className="paragraph-medium text-dark400_light700">
8585
{employerName}
8686
</h4>
87-
<p className="body-regular text-light-500">
87+
<p className="body-regular mt-0.5 capitalize text-light-500">
8888
posted {getTimestamp(new Date(postedAt))}
8989
</p>
9090
</div>
@@ -134,7 +134,12 @@ const JobCard = ({
134134
textStyles="small-medium text-light-500"
135135
/>
136136
</div>
137-
<Link href={applyLink || "/"} className="flex items-center gap-2">
137+
<Link
138+
href={applyLink || "/"}
139+
className="flex items-center gap-2"
140+
target="_blank"
141+
rel="noopener noreferrer"
142+
>
138143
<p className="body-semibold primary-text-gradient">View job</p>
139144
<Image
140145
alt="arrow up right"

components/shared/Filters.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ import { useState } from "react";
44
import { useRouter, useSearchParams } from "next/navigation";
55

66
import { Button } from "@/components/ui/button";
7+
import Switcher from "@/components/shared/Switcher";
78

89
import { formUrlQuery } from "@/lib/utils";
910

1011
import type { FilterProps } from "@/types";
1112

12-
const Filters = ({ filters }: { filters: FilterProps[] }) => {
13+
const Filters = ({
14+
filters,
15+
jobFilter = false,
16+
}: {
17+
filters: FilterProps[];
18+
jobFilter: boolean;
19+
}) => {
1320
const searchParams = useSearchParams();
1421
const router = useRouter();
1522

@@ -54,6 +61,14 @@ const Filters = ({ filters }: { filters: FilterProps[] }) => {
5461
{filter.name}
5562
</Button>
5663
))}
64+
65+
{jobFilter && (
66+
<div className="background-light800_dark300 mt-2 flex items-center rounded-lg px-3 py-2 shadow-none md:mt-0">
67+
<Switcher query="remote" label="Remote Only" />
68+
<Switcher query="wage" label="TBA" />
69+
<Switcher query="skills" label="Skills" />
70+
</div>
71+
)}
5772
</div>
5873
);
5974
};

components/shared/Switcher.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,28 @@ import { Switch } from "@/components/ui/switch";
88
import { formUrlQuery, removeKeysFromQuery } from "@/lib/utils";
99

1010
interface Props {
11-
searchParamKey?: string;
12-
label?: string;
11+
query: string;
12+
label: string;
1313
}
1414

15-
const Switcher = ({
16-
searchParamKey = "remote",
17-
label = "Remote jobs only",
18-
}: Props) => {
15+
const Switcher = ({ query, label }: Props) => {
1916
const searchParams = useSearchParams();
2017
const router = useRouter();
2118

22-
const paramFilter = searchParams.get(searchParamKey);
19+
const paramFilter = searchParams.get(query);
2320

2421
const handleUpdateParams = (value: string) => {
2522
let newUrl;
2623

2724
if (!value) {
2825
newUrl = removeKeysFromQuery({
2926
params: searchParams.toString(),
30-
keysToRemove: [searchParamKey],
27+
keysToRemove: [query],
3128
});
3229
} else {
3330
newUrl = formUrlQuery({
3431
params: searchParams.toString(),
35-
key: searchParamKey,
32+
key: query,
3633
value,
3734
});
3835
}
@@ -43,13 +40,13 @@ const Switcher = ({
4340
return (
4441
<>
4542
<Switch
46-
id="remote-only"
43+
id={`${query}-switcher`}
4744
className="ml-4 mr-2"
4845
checked={paramFilter === "true"}
4946
// @ts-expect-error
5047
onCheckedChange={handleUpdateParams}
5148
/>
52-
<Label htmlFor="remote-only" className="text-light-500">
49+
<Label htmlFor={`${query}-switcher`} className="text-light-500">
5350
{label}
5451
</Label>
5552
</>

components/ui/switch.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Switch = React.forwardRef<
1111
>(({ className, ...props }, ref) => (
1212
<SwitchPrimitives.Root
1313
className={cn(
14-
"peer inline-flex h-[24px] w-[44px] shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-light-700 dark:data-[state=checked]:bg-dark-200 data-[state=unchecked]:bg-light-800 dark:data-[state=unchecked]:bg-dark-300",
14+
"peer inline-flex h-[24px] w-[44px] shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-light-700 dark:data-[state=checked]:bg-dark-200 data-[state=unchecked]:bg-light-900 dark:data-[state=unchecked]:bg-dark-400",
1515
className
1616
)}
1717
{...props}

lib/actions/job.action.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export async function getJobs(params: GetJobsParams) {
1111
filter,
1212
location,
1313
remote,
14+
wage,
15+
skills,
1416
searchQuery,
1517
} = params;
1618

@@ -35,7 +37,10 @@ export async function getJobs(params: GetJobsParams) {
3537
job &&
3638
searchQueryRegExp.test(job.job_title) &&
3739
locationRegExp.test(job.job_country) &&
38-
(remote ? job.job_is_remote === true : true)
40+
(!remote || job.job_is_remote === true) &&
41+
(!wage ||
42+
(job.job_min_salary !== null && job.job_max_salary !== null)) &&
43+
(!skills || job.job_required_skills)
3944
);
4045
});
4146

lib/actions/shared.types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export interface GetAllUsersParams extends Searchable {}
7373
export interface GetJobsParams extends Searchable {
7474
location?: string;
7575
remote?: boolean | string;
76+
wage?: boolean | string;
77+
skills?: boolean | string;
7678
}
7779

7880
export interface UpdateUserParams extends ClerkId, Path {

0 commit comments

Comments
 (0)