diff --git a/src/components/SummaryPage/SummaryDetailBox/CategorySelectBox/CategoryDropdown/CategoryDropdown.tsx b/src/components/SummaryPage/SummaryDetailBox/CategorySelectBox/CategoryDropdown/CategoryDropdown.tsx index 3a17e69..45e6070 100644 --- a/src/components/SummaryPage/SummaryDetailBox/CategorySelectBox/CategoryDropdown/CategoryDropdown.tsx +++ b/src/components/SummaryPage/SummaryDetailBox/CategorySelectBox/CategoryDropdown/CategoryDropdown.tsx @@ -1,24 +1,33 @@ import { Dropdown } from '@/styles/SummaryPage'; import DropdownItem from './DropdownItem'; +import { useRecoilValue } from 'recoil'; +import { categoryState } from '@/stores/category'; +import React from 'react'; +import { ISelectedCategoryProps } from 'types/category'; -// 임시 타입 -interface Item { - id: number; - text: string; - items?: Item[]; +interface ICategoryDropdownProp { + setSelectedCategory: React.Dispatch< + React.SetStateAction + >; + setIsOpen: React.Dispatch>; } -type Props = { - categoryList: Item[]; -}; - -const CategoryDropdown = ({ categoryList }: Props) => { +const CategoryDropdown = ({ + setSelectedCategory, + setIsOpen, +}: ICategoryDropdownProp) => { + const categories = useRecoilValue(categoryState); return ( e.stopPropagation()}>
    - {categoryList.map((category) => ( - + {categories.map((category) => ( + ))}
diff --git a/src/components/SummaryPage/SummaryDetailBox/CategorySelectBox/CategoryDropdown/DropdownItem.tsx b/src/components/SummaryPage/SummaryDetailBox/CategorySelectBox/CategoryDropdown/DropdownItem.tsx index f796fb5..9bd120b 100644 --- a/src/components/SummaryPage/SummaryDetailBox/CategorySelectBox/CategoryDropdown/DropdownItem.tsx +++ b/src/components/SummaryPage/SummaryDetailBox/CategorySelectBox/CategoryDropdown/DropdownItem.tsx @@ -1,19 +1,27 @@ import { useState } from 'react'; import DownIcon from '@/assets/icons/down.svg?react'; +import { IFolderProps, ISelectedCategoryProps } from 'types/category'; +import { DropdownTopCategoryName } from '@/styles/SummaryPage'; -// 임시 타입 -interface Item { - id: number; - text: string; - items?: Item[]; +interface ICategoryDropdownProp { + category: IFolderProps; + setSelectedCategory: React.Dispatch< + React.SetStateAction + >; + setIsOpen: React.Dispatch>; } -type Props = { - category: Item; -}; +interface IItemClickProps { + name: string; + categoryId: number; +} -const DropdownItem = ({ category }: Props) => { +const DropdownItem = ({ + category, + setSelectedCategory, + setIsOpen, +}: ICategoryDropdownProp) => { const [isShow, setIsShow] = useState(false); const dynamicStyles = { @@ -21,30 +29,53 @@ const DropdownItem = ({ category }: Props) => { transform: isShow ? 'rotateZ(180deg)' : 'rotateZ(0deg)', }, subCategory: { - height: isShow ? (category.items?.length || 0) * 46 : 0, + height: isShow ? (category.subFolders.length || 0) * 46 : 0, }, }; - const handleItemClick = async (id: number) => { + const handleItemClick = async ({ name, categoryId }: IItemClickProps) => { + setSelectedCategory({ + name, + categoryId, + }); // API 요청 - console.log(id); + console.log('API 요청'); + setIsOpen(false); }; return ( <> -
  • setIsShow(!isShow)}> - - - {category.text} +
  • + setIsShow(!isShow)} + /> + + handleItemClick({ + name: category.name, + categoryId: category.categoryId, + }) + } + > + {category.name} +
    • - {category.items?.map((subCategory) => ( + {category.subFolders.map((subFolder) => (
    • handleItemClick(subCategory.id)} + key={subFolder.categoryId} + onClick={() => + handleItemClick({ + name: subFolder.name, + categoryId: subFolder.categoryId, + }) + } > - {subCategory.text} + {subFolder.name}
    • ))}
    diff --git a/src/components/SummaryPage/SummaryDetailBox/CategorySelectBox/CategorySelectBox.tsx b/src/components/SummaryPage/SummaryDetailBox/CategorySelectBox/CategorySelectBox.tsx index 5b8dc28..459575e 100644 --- a/src/components/SummaryPage/SummaryDetailBox/CategorySelectBox/CategorySelectBox.tsx +++ b/src/components/SummaryPage/SummaryDetailBox/CategorySelectBox/CategorySelectBox.tsx @@ -6,33 +6,13 @@ import OpenFileIcon from '@/assets/icons/open-file.svg?react'; import useOutsideClick from '@/hooks/useOutsideClick'; import { CategoryDropdown } from './CategoryDropdown'; +import { ISelectedCategoryProps } from 'types/category'; const CategorySelectBox = () => { - const categoryList = [ - { - id: 1, - text: '기획', - items: [ - { id: 2, text: '마케팅' }, - { id: 3, text: '트렌드' }, - { id: 4, text: '기업' }, - { id: 5, text: '용어' }, - ], - }, - { - id: 6, - text: '디자인', - items: [ - { id: 7, text: 'AAA' }, - { id: 8, text: 'BBB' }, - { id: 9, text: 'CCC' }, - { id: 10, text: 'DDD' }, - ], - }, - ]; - const [isLogin] = useState(true); const [isOpen, setIsOpen] = useState(false); + const [selectedCategory, setSelectedCategory] = + useState({ name: '', categoryId: 0 }); // 다른 영역 클릭 시 dropdown 안보여지게 하기 const [ref] = useOutsideClick(() => { @@ -44,24 +24,34 @@ const CategorySelectBox = () => { setIsOpen(!isOpen); }; - return (
    {isLogin - ? '어떤 카테고리에 넣을까요?' + ? selectedCategory.name + ? selectedCategory.name + : '어떤 카테고리에 넣을까요?' : '로그인하고 요약한 영상을 아카이빙해요!'}
    - {isOpen && } + {isOpen && ( + + )}
    - +
    diff --git a/src/styles/SummaryPage.ts b/src/styles/SummaryPage.ts index 1677291..86bc0a8 100644 --- a/src/styles/SummaryPage.ts +++ b/src/styles/SummaryPage.ts @@ -50,9 +50,16 @@ export const DetailBox = styled.div` width: 40px; height: 40px; border-radius: 8px; - background-color: ${(props) => props.theme.color.gray200}; cursor: pointer; + &.selected { + background-color: ${(props) => props.theme.color.green400}; + } + + &.not-selected { + background-color: ${(props) => props.theme.color.gray200}; + } + &.disabled svg { & path:nth-of-type(1) { fill: ${(props) => props.theme.color.gray300}; @@ -489,3 +496,11 @@ export const ModalContainer = styled(BlurBackground)` } } `; + +export const DropdownTopCategoryName = styled.span` + width: 100%; + height: 100%; + display: flex; + flex-direction: column; + justify-content: center; +`; diff --git a/types/category.ts b/types/category.ts index a2c43ff..760296a 100644 --- a/types/category.ts +++ b/types/category.ts @@ -10,3 +10,8 @@ export interface IFolderProps { topCategoryId: null; subFolders: ISubFolderProps[]; } + +export interface ISelectedCategoryProps { + name: string; + categoryId: number; +}