Skip to content

Commit

Permalink
refactor: AnswerStatusMode
Browse files Browse the repository at this point in the history
  • Loading branch information
soomin9106 committed Aug 29, 2024
1 parent 940ac02 commit 25df6bc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/problem/components/BackToArticle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from "@problem/types/problemInfo";
import { Button } from "@shared/components/ui/button";
import ArticleDropDownWrapper from "../ArticleDropDownWrapper";
import { AnswerStatusModel } from "@problem/models/AnswerStatusModel";

interface BackToArticleProps extends HTMLAttributes<HTMLDivElement> {}

Expand All @@ -41,18 +42,18 @@ export default function BackToArticle({ className }: BackToArticleProps) {
},
});

const problemAnswerInfo = problemAnswersInfo[0];
const answerStatus = new AnswerStatusModel({
problemAnswerInfo: problemAnswersInfo[0],
});

const backToArticleWords = problemAnswerInfo
? BACK_TO_ARTICLE_WORDS.AFTER
: BACK_TO_ARTICLE_WORDS.BEFORE;
const backToArticleWords = answerStatus.problemSolvedStatus

return (
<div
className={cn(
"flex flex-row space-x-[3px] relative",
className,
!problemAnswerInfo && "mt-[91px]",
!answerStatus.isProblemAnswerInfo && "mt-[91px]",
)}
>
<ArticleDropDownWrapper
Expand Down
24 changes: 24 additions & 0 deletions src/problem/models/AnswerStatusModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { BACK_TO_ARTICLE_WORDS } from "@problem/constants/backToArticle";
import { ProblemAnswerMuationState } from "@problem/types/problemInfo";

export class AnswerStatusModel {
constructor({
problemAnswerInfo,
}: {
problemAnswerInfo: ProblemAnswerMuationState | undefined;
}) {
this.problemAnswerInfo = problemAnswerInfo;
}

get problemSolvedStatus() {
return this.problemAnswerInfo
? BACK_TO_ARTICLE_WORDS.AFTER
: BACK_TO_ARTICLE_WORDS.BEFORE;
}

get isProblemAnswerInfo() {
return Boolean(this.problemAnswerInfo);
}

private problemAnswerInfo: ProblemAnswerMuationState | undefined;
}

0 comments on commit 25df6bc

Please sign in to comment.