-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor : modify model type customhook to class
- Loading branch information
Showing
6 changed files
with
161 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { ANSWER_CHOICHE_BUTTON_INFO } from "@problem/constants/problemInfo"; | ||
import { ProblemAnswerMuationState } from "@problem/types/problemInfo"; | ||
|
||
export class AnswerChoiceModel { | ||
constructor({ | ||
problemAnswerInfo, | ||
choiceNumber, | ||
renderNumber, | ||
}: { | ||
problemAnswerInfo: ProblemAnswerMuationState | undefined; | ||
choiceNumber: string | null; | ||
renderNumber: string; | ||
}) { | ||
this.problemAnswerInfo = problemAnswerInfo; | ||
this.choiceNumber = choiceNumber; | ||
this.renderNumber = renderNumber; | ||
|
||
this.answerChoiceButtonType(); | ||
} | ||
|
||
private answerChoiceButtonType() { | ||
const isSubmitAnswer = Boolean(this.problemAnswerInfo?.data); | ||
const answerResultInfo = this.problemAnswerInfo?.data; | ||
const postChoiceAnswer = this.problemAnswerInfo?.variables; | ||
|
||
this.INIT_CHOICE_ANSWER = | ||
!isSubmitAnswer && this.choiceNumber !== this.renderNumber; | ||
this.CURRENT_CHOICE_ANSWER = | ||
!isSubmitAnswer && this.choiceNumber === this.renderNumber; | ||
|
||
this.CHOICE_ANSWER_CORRECT = | ||
isSubmitAnswer && answerResultInfo?.data.answer === this.renderNumber; | ||
this.CHOICE_ANSWER_FAIL = | ||
isSubmitAnswer && | ||
answerResultInfo?.data.isSolved === false && | ||
this.renderNumber === postChoiceAnswer?.sub; | ||
} | ||
get answerChoiceButtonClassName() { | ||
if (this.INIT_CHOICE_ANSWER) | ||
return ANSWER_CHOICHE_BUTTON_INFO.INIT_CHOICE_ANSWER; | ||
|
||
if (this.CURRENT_CHOICE_ANSWER) | ||
return ANSWER_CHOICHE_BUTTON_INFO.CURRENT_CHOICE_ANSWER; | ||
|
||
if (this.CHOICE_ANSWER_CORRECT) | ||
return ANSWER_CHOICHE_BUTTON_INFO.CHOICE_ANSWER_CORRECT; | ||
|
||
if (this.CHOICE_ANSWER_FAIL) | ||
return ANSWER_CHOICHE_BUTTON_INFO.CHOICE_ANSWER_FAIL; | ||
|
||
return ANSWER_CHOICHE_BUTTON_INFO.INIT_CHOICE_ANSWER; | ||
} | ||
|
||
get isChoiceFillCircle() { | ||
if (this.INIT_CHOICE_ANSWER) return false; | ||
if ( | ||
!this.CURRENT_CHOICE_ANSWER && | ||
!this.CHOICE_ANSWER_CORRECT && | ||
!this.CHOICE_ANSWER_FAIL | ||
) | ||
return false; | ||
return true; | ||
} | ||
|
||
get getChoiceFillColor() { | ||
if (this.INIT_CHOICE_ANSWER) return "#A5A5A5"; | ||
if (this.CURRENT_CHOICE_ANSWER) return "white"; | ||
if (this.CHOICE_ANSWER_CORRECT) return "#0166B3"; | ||
if (this.CHOICE_ANSWER_FAIL) return "#B00020"; | ||
return "#A5A5A5"; | ||
} | ||
|
||
get isProblemAnswerInfo() { | ||
return Boolean(this.problemAnswerInfo); | ||
} | ||
|
||
private problemAnswerInfo: ProblemAnswerMuationState | undefined; | ||
private choiceNumber: string | null; | ||
private renderNumber: string; | ||
|
||
private INIT_CHOICE_ANSWER: boolean = false; | ||
private CURRENT_CHOICE_ANSWER: boolean = false; | ||
private CHOICE_ANSWER_CORRECT: boolean = false; | ||
private CHOICE_ANSWER_FAIL: boolean = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { BUTTON_INFO, BUTTON_STATE } from "@problem/constants/answerButtonInfo"; | ||
|
||
export class AnswerSubmitModel { | ||
constructor({ | ||
isPostAnswerSuccess, | ||
isChoiceAnswer, | ||
isExistNextProblem, | ||
}: { | ||
isPostAnswerSuccess: boolean; | ||
isExistNextProblem: boolean; | ||
isChoiceAnswer: boolean; | ||
}) { | ||
this.isPostAnswerSuccess = isPostAnswerSuccess; | ||
this.isChoiceAnswer = isChoiceAnswer; | ||
this.isExistNextProblem = isExistNextProblem; | ||
|
||
this.answerSubmitType(); | ||
} | ||
|
||
private answerSubmitType() { | ||
this.LAST_PROBLEM_LINK_TO_MAIN = | ||
this.isPostAnswerSuccess && !this.isExistNextProblem; | ||
this.POST_ANSWER_SUBMIT = | ||
this.isPostAnswerSuccess && this.isExistNextProblem; | ||
this.BEFORE_CHOICHE_ANSWER = | ||
!this.isChoiceAnswer && !this.isPostAnswerSuccess; | ||
this.POST_ANSWER_PRE_SUBMIT = | ||
this.isChoiceAnswer && !this.isPostAnswerSuccess; | ||
} | ||
get answerSubmitButtonClassName() { | ||
if (this.BEFORE_CHOICHE_ANSWER) return BUTTON_INFO.PRE_ANSWER_SELECT; | ||
|
||
if (this.POST_ANSWER_SUBMIT) return BUTTON_INFO.POST_SUBMIT; | ||
|
||
if (this.POST_ANSWER_PRE_SUBMIT) return BUTTON_INFO.POST_ANSWER_PRE_SUBMIT; | ||
|
||
if (this.LAST_PROBLEM_LINK_TO_MAIN) return BUTTON_INFO.LINK_TO_MAIN; | ||
} | ||
|
||
get answerButtonState() { | ||
if (this.POST_ANSWER_PRE_SUBMIT) return BUTTON_STATE[0]; | ||
|
||
if (this.POST_ANSWER_SUBMIT) return BUTTON_STATE[2]; | ||
|
||
if (this.LAST_PROBLEM_LINK_TO_MAIN) return BUTTON_STATE[3]; | ||
} | ||
|
||
private isPostAnswerSuccess: boolean = false; | ||
private isExistNextProblem: boolean = false; | ||
private isChoiceAnswer: boolean = false; | ||
|
||
private LAST_PROBLEM_LINK_TO_MAIN: boolean = false; | ||
private POST_ANSWER_SUBMIT: boolean = false; | ||
private BEFORE_CHOICHE_ANSWER: boolean = false; | ||
private POST_ANSWER_PRE_SUBMIT: boolean = false; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.