-
Notifications
You must be signed in to change notification settings - Fork 2
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
[민우] - 작성 가능 리마인드 아이템 컴포넌트 구현 #54
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2c964dd
✨ : #47 - checkBox 아이콘 Icon 컴포넌트에 추가
MinwooP 81a567e
✨ : #47 - WritableRemindItem 컴포넌트 기본 prop, state, 로직 구현
MinwooP 67d6853
💄 : #47 - WritableRemindItem 컴포넌트 css 구현
MinwooP 43bb7bf
💩 : #47 - border-weight => border-width로 변수명 변경
MinwooP ae6e6a2
✨ : #47 - 동일한 리마인드 메세지 Modal 로직 추가
MinwooP 3a99f28
💄 : #47 - background-color, color 스타일 className을 통해 적용하는 방법으로 수정
MinwooP b0973ad
♻️ : #47 - useMemo를 사용을 통한 컴포넌트 내 변수 렌더링 최적화
MinwooP aefc72b
💩 : #47 - 주석 제거
MinwooP bdd8d56
♻️ : #47 - PR 반영 : ! 연산자 사용
MinwooP 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 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 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
157 changes: 157 additions & 0 deletions
157
src/components/WritableRemindItem/WritableRemindItem.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
'use client'; | ||
|
||
import { Icon, Modal, ModalBasic, RemindInput } from '@/components'; | ||
import classNames from 'classnames'; | ||
import React, { useEffect, useMemo, useState } from 'react'; | ||
import './index.scss'; | ||
|
||
interface WritableRemindItemProps { | ||
remindMonth: number; | ||
remindDay: number; | ||
remindMessage: string; | ||
handleChangeRemindMessage: (text: string) => void; | ||
makeAllRemindMessageSame?: () => void; | ||
} | ||
|
||
const MAX_REMIND_MESSAGE_LENGTH = 255; | ||
|
||
export default function WritableRemindItem({ | ||
remindMonth, | ||
remindDay, | ||
remindMessage, | ||
handleChangeRemindMessage, | ||
makeAllRemindMessageSame, | ||
}: WritableRemindItemProps) { | ||
const isRemindMessageEmpty = useMemo(() => { | ||
return remindMessage.length === 0; | ||
}, [remindMessage]); | ||
|
||
const isFirstRemindItem = useMemo(() => { | ||
return makeAllRemindMessageSame !== undefined; | ||
}, [makeAllRemindMessageSame]); | ||
Comment on lines
+25
to
+31
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. useMemo 사용하셨군요 👍 |
||
|
||
const [isItemOpened, setIsItemOpened] = useState( | ||
makeAllRemindMessageSame ? true : false, | ||
); | ||
|
||
const handleClickToggleIsItemOpened = () => { | ||
setIsItemOpened(!isItemOpened); | ||
}; | ||
|
||
const [isSameMessageChecked, setIsSameMessageChecked] = useState(false); | ||
const [isSameMessageModalOpen, setIsSameMessageModalOpen] = useState(false); | ||
|
||
const handleClickSameMessageCheck = () => { | ||
if (isSameMessageChecked) { | ||
setIsSameMessageChecked(false); | ||
} else { | ||
setIsSameMessageModalOpen(!isSameMessageModalOpen); | ||
} | ||
}; | ||
|
||
const handleModalClickYes = () => { | ||
setIsSameMessageChecked(true); | ||
setIsSameMessageModalOpen(false); | ||
}; | ||
|
||
const handleModalClickNo = () => { | ||
setIsSameMessageChecked(false); | ||
setIsSameMessageModalOpen(false); | ||
}; | ||
|
||
useEffect(() => { | ||
if (isFirstRemindItem && isSameMessageChecked) { | ||
makeAllRemindMessageSame!(); | ||
} | ||
}, [isFirstRemindItem, isSameMessageChecked, makeAllRemindMessageSame]); | ||
|
||
return ( | ||
<> | ||
<div className="remind-item"> | ||
<div | ||
className="remind-item__header" | ||
onClick={handleClickToggleIsItemOpened}> | ||
<p className="remind-item__header__title"> | ||
{remindMonth}월 {remindDay}일에 받을 리마인드 메세지 | ||
</p> | ||
|
||
<div className="remind-item__header__meta"> | ||
{isRemindMessageEmpty && ( | ||
<div | ||
className={classNames( | ||
'remind-item__header__warning', | ||
'background-origin-primary', | ||
)}> | ||
<Icon name="WARNING" size="xs" color="white-100" /> | ||
<span | ||
className={classNames( | ||
'remind-item__header__warning__text', | ||
'color-origin-white-100', | ||
)}> | ||
리마인드 메세지가 아직 작성되지 않았습니다 | ||
</span> | ||
</div> | ||
)} | ||
<span className="remind-item__header__button-text"> | ||
{isRemindMessageEmpty ? '작성하기' : '수정하기'} | ||
</span> | ||
<Icon | ||
name={isItemOpened ? 'ITEM_CLOSE' : 'ITEM_OPEN'} | ||
size="xl" | ||
color="gray-300" | ||
classNameList={['remind-item__header__icon']} | ||
/> | ||
</div> | ||
</div> | ||
{isItemOpened && ( | ||
<div | ||
className={classNames( | ||
'remind-item__message', | ||
'background-origin-white-300', | ||
{ | ||
'remind-item__message--open': isItemOpened, | ||
}, | ||
)}> | ||
<RemindInput | ||
textInput={remindMessage} | ||
onChangeInput={handleChangeRemindMessage} | ||
placeholder="미래의 내가 받게 될 리마인드 메세지를 작성해보세요 !" | ||
maxLength={MAX_REMIND_MESSAGE_LENGTH} | ||
editable={true} | ||
/> | ||
|
||
{isFirstRemindItem && ( | ||
<span | ||
className="remind-item__message__check" | ||
onClick={handleClickSameMessageCheck}> | ||
<Icon | ||
name={isSameMessageChecked ? 'CHECKED' : 'UN_CHECKED'} | ||
size="2xl" | ||
color="primary" | ||
isFilled={isSameMessageChecked ? true : false} | ||
/> | ||
<p | ||
className={classNames( | ||
'remind-item__message__check__text', | ||
'color-origin-primary', | ||
)}> | ||
항상 같은 리마인드 메세지 받기 | ||
</p> | ||
</span> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
{isSameMessageModalOpen && !isSameMessageChecked && ( | ||
<Modal> | ||
<ModalBasic | ||
onClickYes={handleModalClickYes} | ||
onClickNo={handleModalClickNo}> | ||
다른 모든 리마인드 메세지가 해당 메세지와 동일한 내용으로 | ||
변경됩니다. 정말 적용하시겠습니까? | ||
</ModalBasic> | ||
</Modal> | ||
)} | ||
</> | ||
); | ||
} |
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,104 @@ | ||
.remind-item { | ||
display: flex; | ||
flex-direction: column; | ||
width: 100%; | ||
border-radius: var(--border-radius); | ||
border: var(--border-width) solid var(--origin-orange-200); | ||
|
||
&__header { | ||
display: flex; | ||
position: relative; | ||
padding: 1rem 2rem; | ||
justify-content: center; | ||
align-items: center; | ||
cursor: pointer; | ||
|
||
&__title { | ||
font-size: 1.25rem; | ||
line-height: 1.25rem; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
} | ||
|
||
&__meta { | ||
position: absolute; | ||
display: inline-flex; | ||
align-items: center; | ||
right: 0rem; | ||
} | ||
|
||
&__warning { | ||
transition: all 1s ease; | ||
display: flex; | ||
margin-right: 0.75rem; | ||
padding: 0.25rem 0.5rem; | ||
border-radius: var(--border-radius); | ||
|
||
&__text { | ||
margin-left: 0.25rem; | ||
font-size: 0.6rem; | ||
line-height: 0.7rem; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
} | ||
} | ||
|
||
&__button-text { | ||
font-size: 1rem; | ||
line-height: 1rem; | ||
margin-right: 1.25rem; | ||
} | ||
|
||
&__icon { | ||
margin-right: 2rem; | ||
} | ||
} | ||
|
||
&__message { | ||
display: none; | ||
flex-direction: column; | ||
align-items: center; | ||
border-top: var(--border-width) solid var(--origin-orange-200); | ||
border-radius: 0 0 12px 12px; | ||
padding: 1rem; | ||
|
||
&--open { | ||
display: flex; | ||
} | ||
|
||
&__check { | ||
display: flex; | ||
margin-top: 1.2rem; | ||
cursor: pointer; | ||
|
||
&__text { | ||
margin-left: 0.25rem; | ||
font-size: 1.25rem; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
} | ||
} | ||
} | ||
} | ||
|
||
@media (max-width: 1200px) { | ||
.remind-item { | ||
&__header { | ||
&__warning { | ||
display: none; | ||
} | ||
} | ||
} | ||
} | ||
|
||
@media (max-width: 750px) { | ||
.remind-item { | ||
&__header { | ||
&__button-text { | ||
display: none; | ||
} | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -15,4 +15,6 @@ export type IconName = | |
| 'HELP' | ||
| 'DROP_DOWN' | ||
| 'DROP_UP' | ||
| 'CLOSE'; | ||
| 'CLOSE' | ||
| 'CHECKED' | ||
| 'UN_CHECKED'; |
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.
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.
계산이 복잡하지 않으니 useMemo를 안써도 isRemindMessageEmpty 를 사용하는 곳에
remidMessage.length === 0
통해서 처리해도 괜찮을것 같습니다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.
앗 컴포넌트 return 부분이 좀 복잡해서 최대한 줄여서 가독성을 높이려는 의도로 만들긴 했는데 한번 고려해보겠슴다 ^^