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

[#20] 유저가 작성한 코드 결과 서버로 보내기 #106

Merged

Conversation

dev2820
Copy link
Collaborator

@dev2820 dev2820 commented Nov 23, 2023

한 일

  • 소켓 로직 추가 및 연결
  • msw 로직은 우선 주석 처리 했습니다.

기존에 우찬님이 작성한 코드, 유석님이 작성한 코드를 변경한 내역이 많아서 먼저 Draft PR로 공유 드립니다. 미리 리뷰 해주세요. 이후 서버 쪽 채점 로직 배포되면 테스트 수행하고 반영해서 새 PR로 올리겠습니다.

스크린 샷

image
현재 소켓이 연결되어 connected 라는 문구가 뜨지만, 응답을 받고 있지 못해 무한 로딩이 도는 상황

@dev2820 dev2820 requested review from mahwin and dmdmdkdkr November 23, 2023 09:59
@dev2820 dev2820 self-assigned this Nov 23, 2023
useEffect(() => {
if (!socket.hasListeners('message')) {
socket.on('message', handleMessage);
const totalSubmissionResult = 10;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

여기는 임시로 값을 넣어둔거에요. 나중에 소켓에서 데이터를 받게되면 대체할 예정입니다.

const totalSubmissionResult = 10;
setScoreResults(
range(0, totalSubmissionResult).map((_, index) => ({
problemId: -1,
Copy link
Collaborator

Choose a reason for hiding this comment

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

따로 변수 안 만들고 -1 넣어서 로딩 걸어주고 진짜 문제 번호 들어오면 점수 넣는 거 너무 좋네요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

동작 안시킨 케이스를 빼먹었네요 감사합니다

Comment on lines -32 to +76
axios
.get(`http://101.101.208.240:3000/competitions/${competitionId}`)
.then((response) => {
setCompetition(response.data);
})
.catch((error) => {
console.error('Error fetching competition data:', error);
});
updateCompetition(competitionId);
Copy link
Collaborator

@dmdmdkdkr dmdmdkdkr Nov 23, 2023

Choose a reason for hiding this comment

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

api분리한 거 좋네요

import type { ManagerOptions, SocketOptions } from 'socket.io-client';
import { io } from 'socket.io-client';

export type { Socket } from 'socket.io-client';
Copy link
Collaborator

Choose a reason for hiding this comment

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

자주 쓰는 라이브러리 타입도 export 하시네요 👍🏻

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

네 여기는 Socket.io를 사용한다는 로직을 socket 유틸 아래로 숨긴거에요

Copy link
Collaborator

Choose a reason for hiding this comment

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

와우

@dmdmdkdkr
Copy link
Collaborator

소켓 부분은 학습이 부족해서 제대로 이해하진 못했지만, 다른 부분은 잘 봤습니다 감사합니다!

Copy link
Collaborator

@dmdmdkdkr dmdmdkdkr Nov 23, 2023

Choose a reason for hiding this comment

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

다른 훅에서는 axios를 사용한 api를 분리하셨는데, 이 훅에서는 axios를 사용하는 이유가 있나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

그냥 분리하는걸 깜빡한 겁니다. 감사합니다

};

useEffect(() => {
if (!socket.hasListeners('message')) {
Copy link
Collaborator

@mahwin mahwin Nov 23, 2023

Choose a reason for hiding this comment

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

아 message라는 이벤트가 소켓 객체를 만들면 항상 리슨하고 있다고 생각했는데,
scoket.on('message',cb) 하는 행위가 이벤트 등록이네요 ! 👍🏻

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

네 소켓에 hasListeners API가 있습니다. 정확히는 Socket은 Emitter를 상속하는데 그래서 Emitter에 있는 hasListeners를 쓸 수 있는 거에요

아래 링크 참고
https://socket.io/docs/v3/client-api/#socketoneventname-callback

Copy link
Collaborator

Choose a reason for hiding this comment

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

와우

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 +79 to +82
const form = {
problemId: currentProblem.id,
code,
} satisfies SubmissionForm;
Copy link
Collaborator

Choose a reason for hiding this comment

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

satisfies는 처음 보네요. 진짜 고수..

Copy link
Collaborator

@mahwin mahwin left a comment

Choose a reason for hiding this comment

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

satisfies,
socket.io 객체를 커스텀해서 utils/socket 으로 사용한거 진짜 좋았습니다.

Copy link
Collaborator

@dmdmdkdkr dmdmdkdkr left a comment

Choose a reason for hiding this comment

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

덕분에 잘 배웠습니다!

@dev2820 dev2820 marked this pull request as ready for review November 23, 2023 15:40
Copy link
Collaborator

@mahwin mahwin left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@dmdmdkdkr dmdmdkdkr left a comment

Choose a reason for hiding this comment

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

Nice!

…o-with-me into 20-유저가-작성한-코드-결과-서버로-보내기
@dev2820 dev2820 merged commit 6558a13 into fe-dev Nov 23, 2023
@dev2820 dev2820 deleted the 20-유저가-작성한-코드-결과-서버로-보내기 branch November 23, 2023 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants