-
Notifications
You must be signed in to change notification settings - Fork 0
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
[FE] feat: 토스트 구현 #608
[FE] feat: 토스트 구현 #608
Conversation
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.
해온의 장인정신 토스트.. 정말 매우 고생했습니다!
알림 메시지가 한결 더 깔끔하게 보이겠네요 👍
코멘트 확인해주세요~
type ToastStyleProps = Pick<ToastProps, 'isError'>; | ||
|
||
const ToastContainer = styled.div<ToastStyleProps & { isAnimating?: boolean }>` |
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.
type ToastStyleProps = Pick<ToastProps, 'isError'>; | |
const ToastContainer = styled.div<ToastStyleProps & { isAnimating?: boolean }>` | |
type ToastStyleProps = Pick<ToastProps, 'isError'> & { isAnimating?: boolean }; | |
const ToastContainer = styled.div<ToastStyleProps>` |
스타일 프롭스에 isAnimating 타입을 추가하는건 어떤가요?
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.
죠습니다
message: string; | ||
} | ||
|
||
const Toast = ({ isError, message }: ToastProps) => { |
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.
isError에 디폴트 값을 넣어주면 더 좋겠네요!
useEffect(() => { | ||
setTimeout(() => setIsAnimating(false), 2000); | ||
if (!isAnimating) { | ||
setTimeout(() => clearTimeout(toastTimer.current), 500); | ||
} | ||
}, [isAnimating]); |
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.
클린업 함수도 추가해보죠!
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.
추가 완
@@ -8,7 +8,7 @@ import { RouterProvider } from 'react-router-dom'; | |||
|
|||
import { SvgSprite } from './components/Common'; | |||
import router from './router'; | |||
import GlobalStyle from './styles'; | |||
import GlobalStyle from './styles/globalStyle'; |
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.
파일 이름을 globalStyle로 바꾼 이유가 있을까요?
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.
animation이라는 파일을 추가했는데 index.ts가 있더라구요. 당연히 다른 파일처럼 경로 모아두는 파일이라고 생각했는데 아니여서 헷갈렸습니다. 지금은 global이랑 animation밖에 없는데 하나 더 추가되면 index.ts에 경로를 모아두어야 할 거 같아서 수정했습니다.
|
||
export const slideIn = keyframes` | ||
0% { | ||
transform: translateY(-100px); |
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.
transform 👍
const useToast = () => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const [isAnimating, setIsAnimating] = useState(true); | ||
const toastTimer = useRef<NodeJS.Timeout>(); |
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.
const toastTimer = useRef<NodeJS.Timeout>(); | |
const toastTimer = useRef<number | null>(null); |
브라우저 환경에서 동작하니 number로 가고
undefined보다 null로 없다는걸 명시적으로 하는 건 어떤가요??
아래 setTimeout -> window.setTimeout이 되겠네요
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.
얍 수정하였습니다
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.
해온~~ 토스트 컴포넌트 만드느라 정말 수고 많았습니다.
이 컴포넌트에 제가 제안하고 싶은 방법이 있는데요! 저도 장바구니 미션을 할 때 받았던 피드백입니다.
현재 토스트 컴포넌트는 조건부 렌더링을 하고 있는데요, 이 부분을 호출하는 방법으로 써보면 어떨까 싶습니다
if (success) toast.success("토스트 메시지")
이런식으로 쓸 수 있게요!
저희 서비스에서 토스트 메시지는 리뷰 작성 완료했을 때의 성공/실패 여부에 대해 보여지게 될 것 같은데 위와 같이 호출 방법으로 작성하면 query의 onSuccess에서 간단하게 작성이 가능할 것 같습니다!
onSuccess: () => toast.success("리뷰 작성 완료");
이런식으로요! 나머지는 다 굿굿입니다~~👍
<> | ||
<div style={{ width: '375px' }}> | ||
<button onClick={handleClick}>토스트 테스트</button> | ||
{isOpen && <Toast message="토스트 메세지" />} | ||
</div> | ||
</> |
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.
<> | |
<div style={{ width: '375px' }}> | |
<button onClick={handleClick}>토스트 테스트</button> | |
{isOpen && <Toast message="토스트 메세지" />} | |
</div> | |
</> | |
<div style={{ width: '375px' }}> | |
<button onClick={handleClick}>토스트 테스트</button> | |
{isOpen && <Toast message="토스트 메세지" />} | |
</div> |
<> | ||
<div style={{ width: '375px' }}> | ||
<button onClick={handleClick}>토스트 테스트</button> | ||
{isOpen && <Toast isError message="토스트 메세지" />} | ||
</div> | ||
</> |
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.
<> | |
<div style={{ width: '375px' }}> | |
<button onClick={handleClick}>토스트 테스트</button> | |
{isOpen && <Toast isError message="토스트 메세지" />} | |
</div> | |
</> | |
<div style={{ width: '375px' }}> | |
<button onClick={handleClick}>토스트 테스트</button> | |
{isOpen && <Toast isError message="토스트 메세지" />} | |
</div> |
요것들은 fragment로 안감싸도 되겠네용
2023-10-06.9.48.39.movcontext를 활용해 토스트를 구현하였습니다. 물론 이 방식도 토스트 호출을 마구 갈기면 토스트가 사라질 때 엉망진창으로 사라지는 오류가 있습니다....ㅠ 오랜만에 context를 사용해서 제대로 사용한게 맞나 모르겠네요 확인 부탁드려요! const [isShown, setIsShown] = useState(true);
useEffect(() => {
setTimeout(() => setIsShown(false), 2000);
if (!isShown) {
setTimeout(() => deleteToast(id), 500);
}
}, [isShown]); 이 부분을 Context에 옮기고 싶었는데 id를 못받아와서 저기에 뒀습니다... toast provider를 어디에 둘 지 몰라서 Index.tsx에 RouterProvider 상위에 감쌌습니다. |
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.
해옹 토스트 굽느라 고생했어요 코멘트 몇 개만 확인해주세요!
그리고 저만 뭔가 토스트 빨리 사라지는 것 같나요?🤔
<> | ||
<button onClick={handleClick}>토스트 성공</button> | ||
</> |
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.
Fragment 지워도 될 것 같네용
<> | ||
<button onClick={handleClick}>토스트 에러</button> | ||
</> |
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.
여기도요
frontend/src/pages/HomePage.tsx
Outdated
@@ -19,6 +19,7 @@ export const HomePage = () => { | |||
|
|||
return ( | |||
<> | |||
<button>하이</button> |
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.
하이
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.
바이
{toasts.map((toast) => ( | ||
<Toast key={toast.id} id={toast.id} message={toast.message} isError={toast.isError} /> | ||
))} |
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.
{toasts.map((toast) => ( | |
<Toast key={toast.id} id={toast.id} message={toast.message} isError={toast.isError} /> | |
))} | |
{toasts.map(({id, message, isError}) => ( | |
<Toast key={id} id={id} message={message} isError={isError} /> | |
))} |
destructing 해서 쓰는게 어떤가요?!
|
||
return ( | ||
<ToastWrapper isError={isError} isAnimating={isShown}> | ||
<MessageWrapper color={theme.colors.white}>{message}</MessageWrapper> |
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.
Text 컴포넌트라서 MessageWrapper보다 Message라고 네이밍 하는게 더 좋을 것 같아요!
|
||
const toastAction = { | ||
toast, | ||
setToasts, |
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.
얘는 내보냈는데 안 쓰는 것 같아요 맞나요?
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.
토스트 대장정 수고했어요 해온
이제 진정한 토스트 장인이네요!
<ToastProvider> | ||
<RouterProvider router={router} fallbackElement={<p>...loading</p>} /> | ||
</ToastProvider> |
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.
👍
useEffect(() => { | ||
setTimeout(() => setIsShown(false), 2000); | ||
if (!isShown) { | ||
setTimeout(() => deleteToast(id), 500); | ||
} | ||
}, [isShown]); |
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.
클린업 함수 작성해주세요~
Co-authored-by: Leejin Yang <[email protected]>
2023-10-06.3.20.38.mov속도 조절했습니다! 대신 저번처럼 위치 바뀌고 삭제되는게 아니라 그 자리에서 삭제 되네요! 참고해주세요~ |
Issue
✨ 구현한 기능
토스트를 구현하였습니다.
📢 논의하고 싶은 내용
에러 버전과 기본 버전만 만들었습니다.
추후 상황에 따라 더 추가하거나 리팩터링 하도록 하겠습니다.
🎸 기타
⏰ 일정