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

[ Refactor/problem 94 ] 문제풀이 페이지 model 구현 #114

Merged
merged 5 commits into from
Jul 21, 2024

Conversation

Happhee
Copy link
Collaborator

@Happhee Happhee commented Jul 15, 2024

🔥 Related Issues

resolve #94
close #94

💜 작업 내용

  • 컴포넌트에 모여있던 비즈니스 로직을 model로 분리
  • 커스텀훅 형태로 model 계층 구현

✅ PR Point

useAnswerChoiceModel

  • 문제 선지에 대한 비즈니스 로직을 관리하는 모델입니다.
// 선지 클래스 명 반환
 const getAnswerChoiceButtonClassName = () => {
    if (INIT_CHOICE_ANSWER)
      return ANSWER_CHOICHE_BUTTON_INFO.INIT_CHOICE_ANSWER;

    if (CURRENT_CHOICE_ANSWER)
      return ANSWER_CHOICHE_BUTTON_INFO.CURRENT_CHOICE_ANSWER;

    if (CHOICE_ANSWER_CORRECT)
      return ANSWER_CHOICHE_BUTTON_INFO.CHOICE_ANSWER_CORRECT;

    if (CHOICE_ANSWER_FAIL)
      return ANSWER_CHOICHE_BUTTON_INFO.CHOICE_ANSWER_FAIL;

    return ANSWER_CHOICHE_BUTTON_INFO.INIT_CHOICE_ANSWER;
  };
// 동그라미 채울지여부판단
  const isChoiceFillCircle = () => {
    if (INIT_CHOICE_ANSWER) return false;
    if (!CURRENT_CHOICE_ANSWER && !CHOICE_ANSWER_CORRECT && !CHOICE_ANSWER_FAIL)
      return false;
    return true;
  };

// 동그라미 원 색깔 반환
  const getChoiceFillColor = () => {
    if (INIT_CHOICE_ANSWER) return "#A5A5A5";
    if (CURRENT_CHOICE_ANSWER) return "white";
    if (CHOICE_ANSWER_CORRECT) return "#0166B3";
    if (CHOICE_ANSWER_FAIL) return "#B00020";
    return "#A5A5A5";
  };

// 문제 제출한지 여부 판단
  const isProblemAnswerInfo = () => {
    return Boolean(problemAnswerInfo);
  };

useAnswerSubmitModel

  • 문제 풀이 하단 버튼에 대한 비즈니스 로직을 관리하는 모델입니다.
// 하단 버튼 속성 반환
const getAnswerSubmitButtonInfo = () => {
    if (BEFORE_CHOICHE_ANSWER) return BUTTON_INFO.PRE_ANSWER_SELECT;

    if (POST_ANSWER_SUBMIT) return BUTTON_INFO.POST_SUBMIT;

    if (POST_ANSWER_PRE_SUBMIT) return BUTTON_INFO.POST_ANSWER_PRE_SUBMIT;

    if (LAST_PROBLEM_LINK_TO_MAIN) return BUTTON_INFO.LINK_TO_MAIN;
  };

// 문제풀이 버튼 상태 반환
  const getAnswerButtonState = () => {
    if (POST_ANSWER_PRE_SUBMIT) return BUTTON_STATE[0];

    if (POST_ANSWER_SUBMIT) return BUTTON_STATE[2];

    if (LAST_PROBLEM_LINK_TO_MAIN) return BUTTON_STATE[3];
  };

- button info with title, classname
- button state with problem state
- get svg fill color
- isChoiceFill state
- button Info with classname
@soomin9106
Copy link
Collaborator

오!! 비즈니스 로직을 한 번에 model 로 분리하니까 깔끔하네요 !! 👍


const onClickAnswerChoice = () => {
if (!problemAnswerInfo) updateChoiceAnswer(number);
if (!isProblemAnswerInfo()) updateChoiceAnswer(number);
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 Author

Choose a reason for hiding this comment

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

model에서 만드는 비즈니스 로직들을 일단 다 함수로 만들고있긴해서 통일성을 지키려다보니 함수가 되었습니다. 혹시 더 좋은 의견이 있을까요?

(answerResultInfo && postChoiceAnswer.sub !== number && "#A5A5A5") ||
""
}
isChoice={isChoiceFillCircle()}
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.

models 폴더 위치는
problem/models 같은 폴더 구조로 가져가는거죵??
좋습니다!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

네네! 문제페이지에서만 사용하는 모델이라 해당 폴더에 넣었습니다!

@Happhee
Copy link
Collaborator Author

Happhee commented Jul 17, 2024

@soomin9106 모델 class로 수정한 commit 입니다!

Copy link
Collaborator

Choose a reason for hiding this comment

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

오 굿굿 좋습니다 👍

@Happhee Happhee merged commit d33fa88 into develop Jul 21, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants