Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ilmerry
Copy link
Member

@ilmerry ilmerry commented Jul 23, 2023

📌 내용

CardCollection - CardMenu, MenuModal을 구현합니다.

  • 이 과정에서 기존에 만들어져 있던 Modal 컴포넌트를 사용했어요

Common - useToast 훅을 구현합니다.

  • 토스트메시지는 공통적으로 사용되는 부분이 많기 때문에, 커스텀훅을 선언해주었어요. activeToast 라는 recoil state에 활성화될 메시지 message와 지속될 시간 duration을 초단위로 입력한뒤(2.5초 이면 2.5 입력) setActiveToast를 해주면 자동으로 활성화됩니다.
 setActiveToast({ message: "🥰 소중한 의견 주셔서 감사해요", duration: 2.5 });

📌 질문할 부분

  • Modal들을 어디서 어떻게 훅을 사용할지 설계에 대해 고민했는데(특히 MenuModal 부분은 Card 내부에서만 사용하기 때문), 한 곳으로 통일 되어있지 않다면 혼란을 줄 것 같아서 Toast랑 Modal 전부 CardCollection 컴포넌트에서 선언하여 개발했습니다. 혹시 더 좋은 의견이 있다면 주셔도 좋아요!

📸 스크린샷

image

@ilmerry ilmerry requested review from NYeonK and joohaem July 23, 2023 11:52
@ilmerry ilmerry self-assigned this Jul 23, 2023
Comment on lines 34 to 37
<IcMenuBtn isLighted={false} />
</St.ButtonWrapper>
<St.ButtonWrapper>
<IcShareBtn isLighted={false} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 static하게 쓸거면 아이콘에 변수를 인터페이스로 빼낼 이유가 있나요???

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

230618카드뷰-처음의 처음

이 부분은 추후에 개발될 업데이트 알림을 위해 선언해둔 변수인데, isLighted ?: boolean 으로 변경하는게 좋겠네요!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 ~~~ 그러면 괜찮을 것 같습니다~!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

믓찌다 은형이👏👏

import St from "./style";

interface LoginCheckProps {
export interface LoginCheckProps {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

props를 재사용하는게 맞다고 생각들지 않아요.
당장에 UI가 바뀐다면? 특정 프로퍼티가 안들어온다면? 그 때 다시 의존성을 풀고 수정하나요??
"가짜 중복"의 형태를 띄고 있지는 않은가 고민이 필요해보여요

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오.. 좋은 의견이에요 props 내용이 같다고 중복이 아님을 명심해야겠군요 감사합니다


import { activeStateToast } from "../../../core/atom/menuBar";

export default function useToast() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋습니다 !!!!~!

Comment on lines 20 to 21
const { closeHandler, fireToast } = props;
const setActiveToast = useSetRecoilState(activeStateToast);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fireToast는 언제 쓰나요..?
fireToast랑 setActiveToast랑 따로 선언해서 쓰는 게 정녕 최선의 인터페이스인가요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 로직을 변경하면서 미처 fireToast를 지우지 못했어요. setActiveToast로 메시지를 설정하고, fireToast로 토스트메시지 트리거를 하려고 했었는데, 비동기때문에 메시지가 set되지 않았음에도 toast되는 오류가 있었습니다.

그래서 로직을 다음과 같이 변경했습니다. setActiveToast로 메시지를 설정함과 동시에 훅 내부의 useEffect가 동작하게 만들어, 결론적으로 fireToast는 토스트가 꺼지고 일정시간 뒤에 닫히게 만드는 역할만 수행하게 됩니다. 다시한번 말씀드리자면, Toast 메시지는 setActiveToast를 호출함과 동시에 시작되어요!

더 나은 로직에 대해 의견 주시면 감사드리겠습니다.

Comment on lines 7 to 8
const [activeToast, setActiveStateToast] = useRecoilState(activeStateToast);
const [isToastOpen, setIsToastOpen] = useState(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state 분리할 필요성이 있나요??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activeToast는 단순히 message, duration만 담고 있는 state라서 isToastOpen이 있어야 컴포넌트를 숨기고 보이게 할 수 있어요!

}, [activeToast]);

useEffect(() => {
setActiveStateToast(activeToast);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 무슨 동작인가요???

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위 comment 참고 부탁드립니다!

Comment on lines 17 to 20
useEffect(() => {
setActiveStateToast(activeToast);
fireToast();
}, [activeToast, setActiveStateToast, fireToast]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 읽기가 힘들어요.. 무슨 동작을 하는 코드인거죠?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위 comment 참고 부탁드립니다!

@joohaem
Copy link
Member

joohaem commented Jul 24, 2023

모듈은 인터페이스로써 사용자(개발자)에게 "선언적인" 사용을 보장해야 해요.
사용하는 것이 명쾌하지 않고, 어떻게 동작하는 건지 알아야 된다면 잘못된 모듈화가 된 것입니다.

useToast를 사용하는 사람은 isToastOpen으로써 조작도 해야하고, fire도 시켜야 하는데, 이게 최선의 인터페이스인지는 의문입니다.

'나는 토스트를 발생시키는 게 주인데, 열려있는지 아닌지도 확인해야돼.' 라는 생각이 들고 코드를 보며 아 이래이래서 이렇게 뱉어줬구나
그래 개발 하기 어려우니 사용하는 내가 거기에 맞춰 사용해야지
맞는 생각인지 잘 모르겠습니다.

앗 로직을 변경하면서 미처 fireToast를 지우지 못했어요. setActiveToast로 메시지를 설정하고, fireToast로 토스트메시지 트리거를 하려고 했었는데, 비동기때문에 메시지가 set되지 않았음에도 toast되는 오류가 있었습니다.
라고 하셨는데, 그럼 로직을 다시 설계해야하지 않을까요??
"사용자는 속성값을 통해 fire만 할 수 있게 만들 수는 없나요?" 라는 의문이 들고,
그것이 불가능하다면 hook으로 빼낼 의미도 없습니다. 재사용 불가능하니까요

@joohaem
Copy link
Member

joohaem commented Jul 24, 2023

같은 의미로 구현부에서의 어떤 동작을 의미하는가를 "자연어"로 한 번 스스로 설명해보는 것도 좋은 방법이에요
코드가 읽기 힘듦은 곧 선언적인 코드 작성이 안 되었다는 것을 의미해요.


정답 없습니다! 저도 얕게 생각한 것들이고, 같이 더 생각해보면 도움 될 것 같아서 리뷰 남겼던 것이에요!!!!!~
이런 식으로 "선언적"인 모듈화에 대해 파볼 수 있을 것 같아요 -> https://github.com/sopt-makers/sopt-playground-frontend/tree/main/components/common/Toast

@ilmerry ilmerry requested a review from joohaem July 24, 2023 12:20
Copy link
Member

@joohaem joohaem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋네요 !!

Comment on lines +20 to +23
<ToastProvider>
<Router />
{isActiveModal && <ModalStyle />}
</ToastProvider>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

App.tsx 말고 index.tsx는 어떤가요???

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

St.MobileContainer의 영향범위 밖인데 그래도 괜찮을까요??

Copy link
Contributor

@NYeonK NYeonK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

너무너무 수고하셨습니다~!! 커밋도 잘 나눠줘서 코드 변해가는 과정 잘 봤습니다👏👏

@ilmerry ilmerry merged commit 0171398 into release/2.1.0 Aug 2, 2023
@ilmerry ilmerry deleted the feat/#312-card_menu branch August 2, 2023 05:36
@NYeonK NYeonK linked an issue Aug 5, 2023 that may be closed by this pull request
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ CardCollection - Menu ] 더보기 메뉴 기능 일부 구현

4 participants