Skip to content

Commit

Permalink
feat :: 필터가 적용 됐을 때만 querystring 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
KANGYONGSU23 committed Nov 26, 2023
1 parent 0ef4f02 commit 4f2db7b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 30 deletions.
8 changes: 5 additions & 3 deletions src/apis/recruitments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ export const GetRecruitmentsList = (queryString: string) => {
const { append } = useToastStore();
return useQuery(
["getRecruitmentsList", queryString],
async () =>
await instance.get<RecruitmentsListResponseType>(
async () => {
const { data } = await instance.get<RecruitmentsListResponseType>(
`${router}/student?${queryString}`
),
);
return data;
},
{
onError: () => {
append({
Expand Down
4 changes: 2 additions & 2 deletions src/components/common/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Header() {
className={`text-[#333333] text-b2 ${
pathname.indexOf("/companies") !== -1 && "font-b"
}`}
href={"/companies?page=1&name="}
href={"/companies?page=1"}
prefetch
>
기업체
Expand All @@ -37,7 +37,7 @@ function Header() {
className={`text-[#333333] text-b2 ${
pathname.indexOf("/recruitments") !== -1 && "font-b"
}`}
href={"/recruitments?page=1&job_code=&tech_code=&name="}
href={"/recruitments?page=1"}
>
모집의뢰서
</Link>
Expand Down
35 changes: 24 additions & 11 deletions src/components/common/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,29 @@ import { useEffect, useState } from "react";
export default function Pagination() {
const pathname = usePathname();

const { setQueryString, getQueryString, getQueryStringEntry } = useQueryString({
page: "1",
job_code: "",
tech_code: "",
name: "",
});
const { setQueryString, getQueryString, getQueryStringEntry } =
useQueryString({
page: "1",
job_code: "",
tech_code: "",
name: "",
});
const currentPageNumber = getQueryString("page");

const recruitmentQuery = [
getQueryStringEntry("job_code"),
getQueryStringEntry("tech_code"),
getQueryString("name"),
]
.filter((item) => item)
.join("&");

const numberOfPages =
pathname === "/recruitments/"
? GetNumberOfRecruitmentRequestListPages(
`${getQueryStringEntry("job_code")}&${getQueryStringEntry("tech_code")}&${getQueryStringEntry("name")}`
)?.data
: GetNumberOfCompaniesListPages(`${getQueryStringEntry("name")}`)?.data;
? GetNumberOfRecruitmentRequestListPages(recruitmentQuery)?.data
: GetNumberOfCompaniesListPages(
`${getQueryStringEntry("name") ? getQueryStringEntry("name") : ""}`
)?.data;
const [pagesArray, setPagesArray] = useState<number[]>([]);

useEffect(() => {
Expand Down Expand Up @@ -73,7 +82,11 @@ export default function Pagination() {
icon="Chevron"
direction="right"
size={16}
color={getQueryString("page") === String(pagesArray.length) ? "gray50" : "gray90"}
color={
getQueryString("page") === String(pagesArray.length)
? "gray50"
: "gray90"
}
/>
</div>
</div>
Expand Down
16 changes: 4 additions & 12 deletions src/components/recruitments/RecruitmentsCard.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
"use client";

import { Icon } from "@team-return/design-system";
import { SetBookmarks } from "@/apis/bookmarks";
import { GetRecruitmentsList } from "@/apis/recruitments";
import { Icon } from "@team-return/design-system";
import Image from "next/image";
import React, { useEffect, useState } from "react";
import { useSearchParams } from "next/navigation";
import { RecruitmentsListType } from "@/apis/recruitments/type";
import { GetRecruitmentsList } from "@/apis/recruitments";
import React from "react";
import HoverPrefetchLink from "../common/HoverPrefetchLink";
import RecruitmentSkelton from "../common/Skelton/SkeltonElement";

export default function RecruitmentsCard() {
const getParams = useSearchParams();
const [list, setList] = useState<RecruitmentsListType[]>([]);

const { data: recruitmentsList, isLoading } = GetRecruitmentsList(getParams.toString());
useEffect(() => {
setList((prev) => recruitmentsList?.data.recruitments || prev);
}, [recruitmentsList]);

const { mutate: SetBookmarksMutate } = SetBookmarks();

const tagStyle =
"text-caption leading-caption text-lightBlue font-r border rounded-full border-[#135C9D] py-1 px-2";

return (
<div className="w-full mt-5 grid grid-cols-3 md:grid-cols-4 gap-[1.5vw]">
{isLoading && <RecruitmentSkelton />}
{list.map(
{recruitmentsList?.recruitments.map(
(
{
company_profile_url,
Expand Down
5 changes: 3 additions & 2 deletions src/hook/useQueryString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const useQueryString = (initialState: QueryStringType) => {

const refresh = () => {
const queryString = Object.entries(value)
.map(([key, val]) => `${key}=${val}`)
.map(([key, val]) => val && `${key}=${val}`)
.filter((item) => item)
.join("&");
router.push(`${pathname}?${queryString}`);
};
Expand All @@ -47,7 +48,7 @@ export const useQueryString = (initialState: QueryStringType) => {
return value[key];
};
const getQueryStringEntry = (key: keyof setQueryStringType) => {
return `${Object.keys(value).find((objectKey) => objectKey === key)}=${
return value[key] && `${Object.keys(value).find((objectKey) => objectKey === key)}=${
value[key]
}`;
};
Expand Down

0 comments on commit 4f2db7b

Please sign in to comment.