-
Notifications
You must be signed in to change notification settings - Fork 4
[Refactor] pagination 상태 유지 개선(searchParams) #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
35d3c30
8c43f12
bb02dae
f513221
8a8d1cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { useState } from "react"; | ||
| import { useNavigate } from "react-router-dom"; | ||
| import { useSearchParams, useNavigate } from "react-router-dom"; | ||
|
|
||
| import { ROUTES } from "@/app/routes/paths"; | ||
| import { useGetExperienceList } from "@/features/experience/api/use-experience-list.query"; | ||
|
|
@@ -9,24 +9,33 @@ import { ExperienceFilter } from "@/widgets"; | |
| import * as styles from "./experience-page.css"; | ||
| import { ExperienceListContainer } from "./ui/experience-list-container"; | ||
|
|
||
| import type { ExperienceTypeCode } from "@/shared/config/experience"; | ||
|
|
||
| const ExperiencePage = () => { | ||
| const [filter, setFilter] = useState<ExperienceTypeCode | null>(null); | ||
| const navigate = useNavigate(); | ||
| const [searchParams, setSearchParams] = useSearchParams(); | ||
|
|
||
| const currentPage = Number(searchParams.get("page")) || 1; | ||
| const type = searchParams.get("type") || ""; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🔧 수정 제안- const type = searchParams.get("type") || "";
+ const type = searchParams.get("type");
const { data } = useGetExperienceList({
type,
page: currentPage,
});
const handleFilterChange = (value: string) => {
setIsExpTouched(true);
- setSearchParams({
- type: value,
- page: "1",
- });
+ setSearchParams((prev) => {
+ const next = new URLSearchParams(prev);
+ if (value) next.set("type", value);
+ else next.delete("type");
+ next.set("page", "1");
+ return next;
+ });
};
const handlePageChange = (page: number) => {
- setSearchParams({
- type,
- page: String(page),
- });
+ setSearchParams((prev) => {
+ const next = new URLSearchParams(prev);
+ if (type) next.set("type", type);
+ else next.delete("type");
+ next.set("page", String(page));
+ return next;
+ });
};Also applies to: 22-23, 28-31, 35-37 🤖 Prompt for AI Agents |
||
|
|
||
| const [isExpTouched, setIsExpTouched] = useState(false); | ||
| const [currentPage, setCurrentPage] = useState(1); | ||
| const navigate = useNavigate(); | ||
|
|
||
| const { data } = useGetExperienceList({ | ||
| type: filter, | ||
| type, | ||
| page: currentPage, | ||
| }); | ||
|
|
||
| const handleFilterChange = (value: ExperienceTypeCode | null) => { | ||
| const handleFilterChange = (value: string) => { | ||
| setIsExpTouched(true); | ||
| setFilter(value); | ||
| setCurrentPage(1); | ||
| setSearchParams({ | ||
| type: value, | ||
| page: "1", | ||
| }); | ||
| }; | ||
|
|
||
| const handlePageChange = (page: number) => { | ||
| setSearchParams({ | ||
| type, | ||
| page: String(page), | ||
| }); | ||
| }; | ||
hummingbbird marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
|
|
@@ -53,15 +62,15 @@ const ExperiencePage = () => { | |
| </button> | ||
|
|
||
| <ExperienceFilter | ||
| value={filter} | ||
| value={type} | ||
| onChange={handleFilterChange} | ||
| isTouched={isExpTouched} | ||
| hasTotal={true} | ||
| /> | ||
| </div> | ||
| </section> | ||
|
|
||
| <ExperienceListContainer data={data} onPageChange={setCurrentPage} /> | ||
| <ExperienceListContainer data={data} onPageChange={handlePageChange} /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -143,7 +143,7 @@ export interface ExperienceRequestDto { | |
| */ | ||
| title: string; | ||
| /** @example "INTERNSHIP" */ | ||
| type: "INTERNSHIP" | "PROJECT" | "EDUCATION" | "ETC"; | ||
| type: string; | ||
| /** | ||
|
Comment on lines
+146
to
147
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다들 http-client.ts 업데이트하게 되면, string 바꿔주기 잊지 말기.....(( API 호출부.. 수정하고 말겁니다... |
||
| * @format date | ||
| * @example "2025-12-23" | ||
|
|
@@ -812,7 +812,7 @@ export class Api< | |
| */ | ||
| getSummaryExperienceList: ( | ||
| query?: { | ||
| type?: "INTERNSHIP" | "PROJECT" | "EDUCATION" | "ETC"; | ||
| type?: string; | ||
| /** | ||
| * @format int32 | ||
| * @default 1 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
page쿼리 파라미터 정규화가 없어 잘못된 페이지 요청이 가능합니다.현재 계산식은
-1,1.5같은 값도 그대로 통과합니다. 페이지는 1 이상의 정수로 제한해 방어적으로 처리하는 게 안전합니다.🔧 수정 제안
📝 Committable suggestion
🤖 Prompt for AI Agents