Skip to content
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] 주식 상세페이지 웹소켓 연결 & 거래창 UI 개선 #204

Merged
merged 13 commits into from
Nov 27, 2024

Conversation

dongree
Copy link
Collaborator

@dongree dongree commented Nov 26, 2024

✅ 주요 작업

  • 주식 상세페이지 웹소켓 연결
  • 거래창 UI 개선
  • 내 정보 레이아웃 구현 및 API 연동
  • 주문 요청 취소 시 모달 추가
image image

💭 고민과 해결과정

주식 상세페이지 헤더 부분에 실시간으로 데이터가 반영되도록 웹소켓을 연결했다.
백엔드와 한국 투자증권 사이의 웹소켓 연결을 끊기 위해 상세페이지에서 나갈 때 unsubscribe API를 호출해주어야 하는데 useEffect hooks안에서 socket 이벤트를 받고 클린업 함수에 unsbscribe API를 호출해주었다.

주문 요청을 취소할 때 모달을 띄어주는 작업에서 각 리스트 데이터들을 어떻게 모달에 전달해줄 지 고민했다.
다음과 같은 store를 만들어서 모달을 관리할 수 있었다.

type ModalStore = {
  isOpen: boolean;
  order: Order | null;
  onSuccess: () => void;
  open: (order: Order, callback?: () => void) => void;
  close: () => void;
};

const useOrderCancelAlertModalStore = create<ModalStore>((set) => ({
  isOpen: false,
  order: null,
  onSuccess: () => {},
  open: (order, callback?) =>
    set(() => ({ isOpen: true, order, onSuccess: callback })),
  close: () => set(() => ({ isOpen: false })),
}));

@dongree dongree added FE 프론트엔드 LAYOUT 레이아웃 구현 INTEGRATION API/Socket 연동 labels Nov 26, 2024
@dongree dongree requested a review from dannysir November 26, 2024 14:58
@dongree dongree self-assigned this Nov 26, 2024
Copy link
Collaborator

@dannysir dannysir 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 +28 to +48
useEffect(() => {
const handleSocketData = (data: {
stck_prpr: string;
prdy_vrss: string;
prdy_vrss_sign: string;
prdy_ctrt: string;
}) => {
const { stck_prpr, prdy_vrss, prdy_vrss_sign, prdy_ctrt } = data;
setCurrPrice(stck_prpr);
setCurrPrdyVrss(prdy_vrss);
setCurrPrdyVrssSign(prdy_vrss_sign);
setCurrPrdyRate(prdy_ctrt);
};

socket.on(`detail/${code}`, handleSocketData);

return () => {
unsbscribe(code);
};
}, [code]);

Copy link
Collaborator

Choose a reason for hiding this comment

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

🟢이렇게 해도 소켓으로 정보가 잘 오나요? 이렇게 했을 때 저는 리렌더가 발생할 때 클린업 코드가 실행되서 서버에 구독해지가 가버려서 이후에 소켓으로 이벤트가 안오는데 ㅜ🥲

Comment on lines +8 to +11
return fetch(url, {
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
}).then((res) => res.json());
Copy link
Collaborator

Choose a reason for hiding this comment

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

🟢여기서 에러가 발생해도 errorBoundary나 useQuery의 isError로 에러 관리가 되나요?

@dannysir dannysir merged commit 3b7e9cb into front/main Nov 27, 2024
2 checks passed
@dongree dongree deleted the feature/tradeAndMypage branch December 5, 2024 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FE 프론트엔드 INTEGRATION API/Socket 연동 LAYOUT 레이아웃 구현
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants