This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: `categories`, 'writings' ๋ถ๋ฆฌ * refactor: `categories` ๋ฐ์ดํฐ๊ฐ ์์ ๋ ์นดํ ๊ณ ๋ฆฌ ํค๋๋ ๋ณด์ด๊ฒ ์์ * refactor: `useCategoryWritings` -> `useWritings` * feat: `CategoryItem` ๊ตฌํ * refactor: CategorySection ๊ด์ฌ์ฌ ๋ถ๋ฆฌ * chore: isValidCategoryName ํ์ผ ๊ฒฝ๋ก ์์ * chore: merge
- Loading branch information
1 parent
e1fd86b
commit fc53c73
Showing
14 changed files
with
214 additions
and
246 deletions.
There are no files selected for viewing
136 changes: 0 additions & 136 deletions
136
frontend/src/components/Category/CategorySection/CategorySection.tsx
This file was deleted.
Oops, something went wrong.
62 changes: 0 additions & 62 deletions
62
frontend/src/components/Category/CategorySection/useCategoryDetails.ts
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
frontend/src/components/Category/CategorySection/useCategoryWritings.ts
This file was deleted.
Oops, something went wrong.
This file contains 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,89 @@ | ||
import { KeyboardEventHandler } from 'react'; | ||
import { styled } from 'styled-components'; | ||
import useCategoryInput from '../useCategoryInput'; | ||
import { useCategoryMutation } from '../useCategoryMutation'; | ||
import { isValidCategoryName } from '../isValidCategoryName'; | ||
import Input from 'components/@common/Input/Input'; | ||
import { PlusCircleIcon } from 'assets/icons'; | ||
|
||
const Header = () => { | ||
const { | ||
inputRef, | ||
escapeInput: escapeAddCategory, | ||
isInputOpen, | ||
openInput, | ||
resetInput, | ||
isError, | ||
setIsError, | ||
} = useCategoryInput(''); | ||
const { addCategory } = useCategoryMutation(); | ||
|
||
const requestAddCategory: KeyboardEventHandler<HTMLInputElement> = async (e) => { | ||
if (e.key !== 'Enter') return; | ||
|
||
const categoryName = e.currentTarget.value.trim(); | ||
|
||
if (!isValidCategoryName(categoryName)) { | ||
setIsError(true); | ||
return; | ||
} | ||
|
||
resetInput(); | ||
addCategory({ categoryName: categoryName }); | ||
}; | ||
|
||
return ( | ||
<S.Header> | ||
<S.Title>์นดํ ๊ณ ๋ฆฌ</S.Title> | ||
{isInputOpen ? ( | ||
<Input | ||
type='text' | ||
variant='underlined' | ||
size='small' | ||
placeholder='Add category ...' | ||
ref={inputRef} | ||
isError={isError} | ||
onBlur={resetInput} | ||
onKeyDown={escapeAddCategory} | ||
onKeyUp={requestAddCategory} | ||
/> | ||
) : ( | ||
<S.Button onClick={openInput} aria-label='์นดํ ๊ณ ๋ฆฌ ์ถ๊ฐ ์ ๋ ฅ ์ฐฝ ์ด๊ธฐ'> | ||
<PlusCircleIcon width={12} height={12} /> | ||
</S.Button> | ||
)} | ||
</S.Header> | ||
); | ||
}; | ||
|
||
export default Header; | ||
|
||
const S = { | ||
Header: styled.header` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
height: 2.8rem; | ||
font-size: 1.2rem; | ||
font-weight: 400; | ||
padding-right: 0.8rem; | ||
`, | ||
|
||
Title: styled.h1` | ||
color: ${({ theme }) => theme.color.gray8}; | ||
cursor: default; | ||
`, | ||
|
||
Button: styled.button` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
width: 2rem; | ||
height: 2.4rem; | ||
border-radius: 8px; | ||
&:hover { | ||
background-color: ${({ theme }) => theme.color.gray5}; | ||
} | ||
`, | ||
}; |
This file contains 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,34 @@ | ||
import Accordion from 'components/@common/Accordion/Accordion'; | ||
import { useState } from 'react'; | ||
import Category from '../Category/Category'; | ||
import WritingList from '../WritingList/WritingList'; | ||
|
||
type Props = { | ||
categoryId: number; | ||
categoryName: string; | ||
isDefaultCategory: boolean; | ||
}; | ||
|
||
const Item = ({ categoryId, categoryName, isDefaultCategory }: Props) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
return ( | ||
<Accordion.Item key={categoryId}> | ||
<Accordion.Title | ||
onIconClick={() => setIsOpen((prev) => !prev)} | ||
aria-label={`${categoryName} ์นดํ ๊ณ ๋ฆฌ ์ผ์ชฝ ์ฌ์ด๋๋ฐ์์ ์ด๊ธฐ`} | ||
> | ||
<Category | ||
categoryId={categoryId} | ||
categoryName={categoryName} | ||
isDefaultCategory={isDefaultCategory} | ||
/> | ||
</Accordion.Title> | ||
<Accordion.Panel> | ||
<WritingList categoryId={categoryId} isOpen={isOpen} /> | ||
</Accordion.Panel> | ||
</Accordion.Item> | ||
); | ||
}; | ||
|
||
export default Item; |
This file contains 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,28 @@ | ||
import Accordion from 'components/@common/Accordion/Accordion'; | ||
import { useCategories } from './useCategories'; | ||
import Item from '../Item/Item'; | ||
|
||
const List = () => { | ||
const { categories } = useCategories(); | ||
|
||
return ( | ||
<> | ||
{categories ? ( | ||
<Accordion> | ||
{categories.map((category, index) => { | ||
return ( | ||
<Item | ||
key={category.id} | ||
categoryId={category.id} | ||
categoryName={category.categoryName} | ||
isDefaultCategory={Boolean(index === 0)} | ||
/> | ||
); | ||
})} | ||
</Accordion> | ||
) : null} | ||
</> | ||
); | ||
}; | ||
|
||
export default List; |
This file contains 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,8 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { getCategories } from 'apis/category'; | ||
|
||
export const useCategories = () => { | ||
const { data } = useQuery(['categories'], getCategories); | ||
|
||
return { categories: data ? data.categories : null }; | ||
}; |
8 changes: 4 additions & 4 deletions
8
...tegorySection/CategorySection.stories.tsx โ ...ents/Category/Section/Section.stories.tsx
This file contains 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
Oops, something went wrong.