-
Notifications
You must be signed in to change notification settings - Fork 1
일반 게시글 목록 필터 UI 추가 #279
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
Merged
Merged
일반 게시글 목록 필터 UI 추가 #279
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
09400c0
feat(list): 목록 필터 UI 구현
wlrnjs 638628f
Merge branch 'develop' of https://github.com/find-my-item/FMI-FE into…
wlrnjs 22c9393
fix(list): 필요없는 훅 제거
wlrnjs bd7cb13
refactor(list): 타입 분리 및 타입 안정성 추가
wlrnjs ea7b9b0
refactor(list): 중복 타입 개선
wlrnjs 6285de5
refactor(list): 찾는중 타입 안정성 추가
wlrnjs 2b1c123
refactor(list): 필터 섹션 상수 분리 및 유틸 함수 분리
wlrnjs 1043d5e
refactor(list): 중복 제거 및 누락된 함수 추가
wlrnjs 571baa1
refactor(list): 임시 타입 추가
wlrnjs 9f26a02
refactor(list): 목록 정렬 옵션 개선
wlrnjs 90071db
rename(list): Filter Type 폴더 위치 개선
wlrnjs ef27dcc
refactor(list): 상수 as const 변경
wlrnjs d560065
fix(list): 정렬 필터 수정
wlrnjs 4071f33
fix(list): 최신순 타입 제거
wlrnjs 7ba2e45
Merge branch 'develop' into feat/list-filter-ui
wlrnjs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/app/(route)/list/_components/_internal/FilterBottomSheet/CONSTANTS.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { FilterTab } from "./types"; | ||
| import { CategoryFilterValue, SortFilterValue, StatusFilterValue } from "./types"; | ||
|
|
||
| export const tabs: { label: string; value: FilterTab }[] = [ | ||
| { label: "지역", value: "region" }, | ||
| { label: "카테고리", value: "category" }, | ||
| { label: "정렬", value: "sort" }, | ||
| { label: "찾음여부", value: "status" }, | ||
| ]; | ||
|
|
||
| export const categories: { label: string; value: CategoryFilterValue }[] = [ | ||
| { label: "전체", value: "" }, | ||
| { label: "전자기기", value: "ELECTRONICS" }, | ||
| { label: "지갑", value: "WALLET" }, | ||
| { label: "신분증", value: "ID_CARD" }, | ||
| { label: "귀금속", value: "JEWELRY" }, | ||
| { label: "가방", value: "BAG" }, | ||
| { label: "카드", value: "CARD" }, | ||
| { label: "기타", value: "ETC" }, | ||
| ]; | ||
|
|
||
| export const sort: { label: string; value: SortFilterValue }[] = [ | ||
| { label: "최신순", value: "LATEST" }, | ||
| { label: "오래된 순", value: "OLDEST" }, | ||
| { label: "즐겨찾기 많은 순", value: "MOST_FAVORITE" }, | ||
| { label: "조회수 많은 순", value: "MOST_VIEWS" }, | ||
| ]; | ||
|
|
||
| export const status: { label: string; value: StatusFilterValue }[] = [ | ||
| { label: "전체", value: "" }, | ||
| { label: "찾는중", value: "SEARCHING" }, | ||
| { label: "찾았음", value: "FOUND" }, | ||
| ]; | ||
172 changes: 172 additions & 0 deletions
172
src/app/(route)/list/_components/_internal/FilterBottomSheet/FilterBottomSheet.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| import { Dispatch, SetStateAction } from "react"; | ||
| import { usePathname, useRouter, useSearchParams } from "next/navigation"; | ||
| import { cn } from "@/utils"; | ||
| import { Button, Icon, PopupLayout } from "@/components"; | ||
| import { FilterTab } from "./types"; | ||
| import { tabs, categories, sort, status } from "./CONSTANTS"; | ||
| import { applyFiltersToUrl } from "./applyFiltersToUrl"; | ||
| import { FiltersState } from "../FilterSection/filtersStateType"; | ||
|
|
||
| interface FilterBottomSheetProps { | ||
| isOpen: boolean; | ||
| setIsOpen: (value: boolean) => void; | ||
| selectedTab: FilterTab; | ||
| setSelectedTab: (tab: FilterTab) => void; | ||
| filters: FiltersState; | ||
| setFilters: Dispatch<SetStateAction<FiltersState>>; | ||
| } | ||
|
|
||
| const FilterBottomSheet = ({ | ||
| isOpen, | ||
| setIsOpen, | ||
| selectedTab, | ||
| setSelectedTab, | ||
| filters, | ||
| setFilters, | ||
| }: FilterBottomSheetProps) => { | ||
| const searchParams = useSearchParams(); | ||
| const router = useRouter(); | ||
| const pathname = usePathname(); | ||
|
|
||
| const handleApply = () => { | ||
| const qs = applyFiltersToUrl({ | ||
| filters, | ||
| searchParams: new URLSearchParams(searchParams.toString()), | ||
| }); | ||
|
|
||
| router.replace(qs ? `${pathname}?${qs}` : pathname); | ||
| setIsOpen(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <PopupLayout isOpen={isOpen} onClose={() => setIsOpen(false)} className="min-h-[530px] py-10"> | ||
| <div className="w-full gap-6 flex-col-center"> | ||
| <h2 className="text-h2-medium text-layout-header-default">필터</h2> | ||
|
|
||
| <section role="tablist" className="w-full flex-center"> | ||
| {tabs.map((tab) => { | ||
| const isSelected = selectedTab === tab.value; | ||
|
|
||
| return ( | ||
| <button | ||
| key={tab.value} | ||
| role="tab" | ||
| aria-selected={isSelected} | ||
| className={cn( | ||
| "min-h-[60px] flex-1 text-[20px] font-semibold", | ||
| // TODO(지권): 디자인 토큰 변경 | ||
| isSelected ? "border-b-2 border-[#1EB87B] text-[#1EB87B]" : "text-[#ADADAD]" | ||
| )} | ||
| onClick={() => setSelectedTab(tab.value)} | ||
| > | ||
| {tab.label} | ||
| </button> | ||
| ); | ||
| })} | ||
suhyeon0111 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </section> | ||
|
|
||
| {selectedTab === "region" && ( | ||
wlrnjs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <div className="relative w-full"> | ||
| <Icon | ||
| name="Search" | ||
| size={16} | ||
| className="absolute left-5 top-1/2 -translate-y-1/2 text-gray-400" | ||
| /> | ||
| <input | ||
| className="w-full rounded-full px-5 py-[10px] pl-10 bg-fill-neutral-subtle-default" | ||
| placeholder="검색어를 입력하세요" | ||
| value={filters.region} | ||
| onChange={(e) => setFilters((prev) => ({ ...prev, region: e.target.value }))} | ||
| /> | ||
| <button | ||
| type="button" | ||
| onClick={() => setFilters((prev) => ({ ...prev, region: "" }))} | ||
| className="absolute right-3 top-1/2 -translate-y-1/2" | ||
| aria-label="지역 검색어 지우기" | ||
| > | ||
| <Icon name="Delete" size={16} className="text-gray-400" /> | ||
| </button> | ||
| </div> | ||
| )} | ||
|
|
||
| {selectedTab === "category" && ( | ||
| <div className="flex w-full flex-wrap gap-2"> | ||
| {categories.map((category) => ( | ||
| <ChipButton | ||
| key={category.value || "all"} | ||
| label={category.label} | ||
| value={category.value} | ||
| selected={filters.category === category.value} | ||
| onSelect={() => setFilters((prev) => ({ ...prev, category: category.value }))} | ||
| /> | ||
| ))} | ||
| </div> | ||
| )} | ||
|
|
||
| {selectedTab === "sort" && ( | ||
| <div className="flex w-full flex-wrap gap-2"> | ||
| {sort.map((sortItem, index) => ( | ||
| <ChipButton | ||
| key={index} | ||
| label={sortItem.label} | ||
| value={sortItem.value} | ||
| selected={filters.sort === sortItem.value} | ||
| onSelect={() => setFilters((prev) => ({ ...prev, sort: sortItem.value }))} | ||
| /> | ||
| ))} | ||
| </div> | ||
| )} | ||
|
|
||
| {selectedTab === "status" && ( | ||
| <div className="flex w-full flex-wrap gap-2"> | ||
| {status.map((statusItem, index) => ( | ||
| <ChipButton | ||
| key={index} | ||
| label={statusItem.label} | ||
| value={statusItem.value} | ||
| selected={filters.status === statusItem.value} | ||
| onSelect={() => setFilters((prev) => ({ ...prev, status: statusItem.value }))} | ||
| /> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className="h-[230px] w-full" /> | ||
|
|
||
| <Button className="w-full" onClick={handleApply}> | ||
| 적용하기 | ||
| </Button> | ||
| </PopupLayout> | ||
| ); | ||
| }; | ||
|
|
||
| export default FilterBottomSheet; | ||
|
|
||
| const ChipButton = ({ | ||
| label, | ||
| value, | ||
| selected, | ||
| onSelect, | ||
| }: { | ||
| label: string; | ||
| value: string; | ||
| selected: boolean; | ||
| onSelect: (value: string) => void; | ||
| }) => { | ||
| return ( | ||
| <button | ||
| type="button" | ||
| onClick={() => onSelect(value)} | ||
| className={cn( | ||
| "rounded-full px-[18px] py-2 text-body1-semibold", | ||
| selected | ||
| ? "text-white bg-fill-neutralInversed-normal-enteredSelected" | ||
| : "text-neutralInversed-normal-default bg-fill-neutralInversed-normal-default" | ||
| )} | ||
| aria-pressed={selected} | ||
| > | ||
| {label} | ||
| </button> | ||
| ); | ||
| }; | ||
25 changes: 25 additions & 0 deletions
25
src/app/(route)/list/_components/_internal/FilterBottomSheet/LABELS.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { CategoryFilterValue, SortFilterValue, StatusFilterValue } from "./types"; | ||
|
|
||
| export const CATEGORY_LABEL_MAP: Partial<Record<CategoryFilterValue, string>> = { | ||
| "": "카테고리", | ||
| ELECTRONICS: "전자기기", | ||
| WALLET: "지갑", | ||
| ID_CARD: "신분증", | ||
| JEWELRY: "귀금속", | ||
| BAG: "가방", | ||
| CARD: "카드", | ||
| ETC: "기타", | ||
| }; | ||
|
|
||
| export const SORT_LABEL_MAP: Record<SortFilterValue, string> = { | ||
| LATEST: "최신순", | ||
| OLDEST: "오래된 순", | ||
| MOST_FAVORITE: "즐겨찾기 많은 순", | ||
| MOST_VIEWS: "조회수 많은 순", | ||
| }; | ||
|
|
||
| export const STATUS_LABEL_MAP: Record<StatusFilterValue, string> = { | ||
| "": "전체", | ||
| SEARCHING: "찾는중", | ||
| FOUND: "찾음", | ||
| }; |
65 changes: 65 additions & 0 deletions
65
src/app/(route)/list/_components/_internal/FilterBottomSheet/applyFiltersToUrl.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { FiltersState } from "../FilterSection/filtersStateType"; | ||
| import { CategoryFilterValue, SortFilterValue, StatusFilterValue } from "./types"; | ||
|
|
||
| const categoryToQueryValue = (category: CategoryFilterValue) => { | ||
| if (!category) return ""; | ||
|
|
||
| const map: Record<CategoryFilterValue, string> = { | ||
| "": "", | ||
| ELECTRONICS: "electronics", | ||
| WALLET: "wallet", | ||
| ID_CARD: "id-card", | ||
| JEWELRY: "jewelry", | ||
| BAG: "bag", | ||
| CARD: "card", | ||
| ETC: "etc", | ||
| }; | ||
|
|
||
| return map[category]; | ||
| }; | ||
|
|
||
| const sortToQueryValue = (sort: SortFilterValue) => { | ||
| if (!sort) return ""; | ||
|
|
||
| const map: Record<SortFilterValue, string> = { | ||
| LATEST: "latest", | ||
| OLDEST: "oldest", | ||
| MOST_FAVORITE: "mostFavorite", | ||
| MOST_VIEWS: "mostViews", | ||
| }; | ||
|
|
||
| return map[sort]; | ||
| }; | ||
|
|
||
| const statusToQueryValue = (status: StatusFilterValue) => { | ||
| if (!status) return ""; | ||
|
|
||
| const map: Record<StatusFilterValue, string> = { | ||
| "": "", | ||
| FOUND: "found", | ||
| SEARCHING: "searching", | ||
| }; | ||
|
|
||
| return map[status]; | ||
| }; | ||
|
|
||
| type ApplyFiltersToUrlProps = { | ||
| filters: FiltersState; | ||
| searchParams: URLSearchParams; | ||
| }; | ||
|
|
||
| export const applyFiltersToUrl = ({ filters, searchParams }: ApplyFiltersToUrlProps): string => { | ||
| const params = new URLSearchParams(searchParams.toString()); | ||
|
|
||
| const upsert = (key: string, value: string) => { | ||
| if (!value) params.delete(key); | ||
| else params.set(key, value); | ||
| }; | ||
|
|
||
| upsert("region", filters.region); | ||
| upsert("category", categoryToQueryValue(filters.category)); | ||
| upsert("sort", sortToQueryValue(filters.sort)); | ||
| upsert("status", statusToQueryValue(filters.status)); | ||
|
|
||
| return params.toString(); | ||
| }; |
10 changes: 10 additions & 0 deletions
10
src/app/(route)/list/_components/_internal/FilterBottomSheet/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { CategoryType, ItemStatus } from "@/types"; | ||
|
|
||
| // 필터 타입 | ||
| export type FilterTab = "region" | "category" | "sort" | "status"; | ||
|
|
||
| export type CategoryFilterValue = "" | CategoryType; | ||
|
|
||
| export type SortFilterValue = "LATEST" | "OLDEST" | "MOST_FAVORITE" | "MOST_VIEWS"; // 임시 type API 수정 후 변경 | ||
|
|
||
| export type StatusFilterValue = "" | ItemStatus; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.