|
1 | | -import TabButton from "@/app/(main)/_components/tab-button"; |
2 | | -import UpdownIcon from "@/shared/assets/icon/updown.svg"; |
| 1 | +import Down from "@/shared/assets/icon/down.svg"; |
3 | 2 | import { |
4 | 3 | MY_CAPSULE_FILTER, |
5 | 4 | type MyCapsuleFilterType, |
6 | 5 | } from "@/shared/types/api/capsule"; |
7 | 6 | import { CAPSULE_SORT, type CapsuleSortType } from "@/shared/types/api/capsule"; |
8 | 7 | import Dropdown from "@/shared/ui/dropdown"; |
9 | 8 | import * as styles from "./select-tab-section.css"; |
| 9 | + |
10 | 10 | interface Props { |
11 | | - onSelect: (value: MyCapsuleFilterType) => void; |
12 | | - selectedTab: MyCapsuleFilterType; |
| 11 | + handleFilter: (value: MyCapsuleFilterType) => void; |
| 12 | + selectedFilter: MyCapsuleFilterType; |
13 | 13 | handleSort: (value: CapsuleSortType) => void; |
| 14 | + selectedSort: CapsuleSortType; |
14 | 15 | } |
15 | 16 |
|
16 | | -const SelectTabSection = ({ onSelect, selectedTab, handleSort }: Props) => { |
17 | | - const tabOptions = [ |
| 17 | +const SelectTabSection = ({ |
| 18 | + handleFilter, |
| 19 | + selectedFilter, |
| 20 | + handleSort, |
| 21 | + selectedSort = CAPSULE_SORT.LATEST, |
| 22 | +}: Props) => { |
| 23 | + const filterOptions = [ |
18 | 24 | { label: "전체", value: MY_CAPSULE_FILTER.ALL }, |
19 | 25 | { label: "좋아요", value: MY_CAPSULE_FILTER.LIKED }, |
20 | 26 | { label: "내가 만든 캡슐", value: MY_CAPSULE_FILTER.CREATED }, |
21 | 27 | { label: "참여 중인 캡슐", value: MY_CAPSULE_FILTER.PARTICIPATING }, |
22 | 28 | ]; |
23 | 29 |
|
| 30 | + const sortOptions = [ |
| 31 | + { label: "최신 순", value: CAPSULE_SORT.LATEST }, |
| 32 | + { label: "오픈 임박 순", value: CAPSULE_SORT.OPEN_IMMINENT }, |
| 33 | + { label: "편지 마감 순", value: CAPSULE_SORT.WRITE_DEADLINE }, |
| 34 | + ]; |
| 35 | + |
| 36 | + const selectedFilterLabel = filterOptions.find( |
| 37 | + (option) => option.value === selectedFilter, |
| 38 | + )?.label; |
| 39 | + |
| 40 | + const selectedSortLabel = sortOptions.find( |
| 41 | + (option) => option.value === selectedSort, |
| 42 | + )?.label; |
| 43 | + |
24 | 44 | return ( |
25 | 45 | <div className={styles.chipContainer}> |
26 | | - <div className={styles.chipWrapper}> |
27 | | - {tabOptions.map((option) => ( |
28 | | - <TabButton |
29 | | - key={option.value} |
30 | | - text={option.label} |
31 | | - selected={selectedTab === option.value} |
32 | | - onClick={() => onSelect(option.value)} |
33 | | - /> |
34 | | - ))} |
| 46 | + <div className={styles.leftContainer}> |
| 47 | + <Dropdown className={styles.dropdown}> |
| 48 | + <Dropdown.Trigger className={styles.dropdownTrigger}> |
| 49 | + <span>{selectedSortLabel}</span> |
| 50 | + <Down /> |
| 51 | + </Dropdown.Trigger> |
| 52 | + <Dropdown.Content className={styles.dropdownContent} align="left"> |
| 53 | + {sortOptions.map((option) => ( |
| 54 | + <Dropdown.Item |
| 55 | + key={option.value} |
| 56 | + label={option.label} |
| 57 | + onClick={() => handleSort(option.value)} |
| 58 | + isSelected={selectedSort === option.value} |
| 59 | + /> |
| 60 | + ))} |
| 61 | + </Dropdown.Content> |
| 62 | + </Dropdown> |
| 63 | + </div> |
| 64 | + |
| 65 | + <div className={styles.rightContainer}> |
| 66 | + <Dropdown className={styles.dropdown}> |
| 67 | + <Dropdown.Trigger className={styles.dropdownTrigger}> |
| 68 | + <span>{selectedFilterLabel}</span> |
| 69 | + <Down /> |
| 70 | + </Dropdown.Trigger> |
| 71 | + <Dropdown.Content className={styles.dropdownContent} align="left"> |
| 72 | + {filterOptions.map((option) => ( |
| 73 | + <Dropdown.Item |
| 74 | + key={option.value} |
| 75 | + label={option.label} |
| 76 | + onClick={() => handleFilter(option.value)} |
| 77 | + isSelected={selectedFilter === option.value} |
| 78 | + /> |
| 79 | + ))} |
| 80 | + </Dropdown.Content> |
| 81 | + </Dropdown> |
35 | 82 | </div> |
36 | | - <Dropdown className={styles.dropdown}> |
37 | | - <Dropdown.Trigger> |
38 | | - <UpdownIcon /> |
39 | | - </Dropdown.Trigger> |
40 | | - <Dropdown.Content> |
41 | | - <Dropdown.Item |
42 | | - label="최신 순" |
43 | | - onClick={() => handleSort(CAPSULE_SORT.LATEST)} |
44 | | - /> |
45 | | - <Dropdown.Item |
46 | | - label="오픈 임박 순" |
47 | | - onClick={() => handleSort(CAPSULE_SORT.OPEN_IMMINENT)} |
48 | | - /> |
49 | | - <Dropdown.Item |
50 | | - label="편지 마감 순" |
51 | | - onClick={() => handleSort(CAPSULE_SORT.WRITE_DEADLINE)} |
52 | | - /> |
53 | | - </Dropdown.Content> |
54 | | - </Dropdown> |
55 | 83 | </div> |
56 | 84 | ); |
57 | 85 | }; |
|
0 commit comments