-
Notifications
You must be signed in to change notification settings - Fork 1
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
[ Feature/dev 97 ] 퀴즈에서 아티클로 다시 넘어가기 #165
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
de102c6
feature: add article back link
soomin9106 e572337
fix: sticky top bar
soomin9106 08e5054
feature: show article view
soomin9106 c523cd5
test: add Aritcle view test code
soomin9106 ca99229
style: padding on Article
soomin9106 f316aa3
fix: remove console log
soomin9106 940ac02
refactor: cancle button classname props
soomin9106 25df6bc
refactor: AnswerStatusMode
soomin9106 238091f
style: fix WorkbookDetailInfoWrapper height
soomin9106 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,16 @@ | ||
import { XIcon } from "lucide-react"; | ||
import { HTMLAttributes } from "react"; | ||
|
||
interface CancelButtonProps extends HTMLAttributes<HTMLDivElement> { | ||
handleToggle: () => void; | ||
} | ||
|
||
export default function CancelButton({ handleToggle, ...props }: CancelButtonProps) { | ||
const { className } = props | ||
|
||
return ( | ||
<div className={className}> | ||
<XIcon data-testid="x-menu" width={36} height={36} className="mr-[23px]" onClick={handleToggle} /> | ||
</div> | ||
) | ||
} |
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,14 @@ | ||
"use client"; | ||
|
||
import { useProblemIdsViewModel } from "@shared/models/useProblemIdsViewModel"; | ||
import ProblemArticleTemplate from "../ProblemArticleTemplate"; | ||
|
||
export function ArticleDropDown() { | ||
const { getArticleId } = useProblemIdsViewModel(); | ||
|
||
return ( | ||
<div className="absolute left-0 top-[66px] z-20 h-screen w-full bg-white overflow-y-scroll px-[20px] pb-[100px]"> | ||
<ProblemArticleTemplate articleId={getArticleId()} /> | ||
</div> | ||
); | ||
} |
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,28 @@ | ||
import { ArticleDropDown } from "../ArticleDropDown"; | ||
import CancelButton from "@common/components/CancelButton"; | ||
|
||
interface ArticleDropDownWrapperProps { | ||
toggleArticle: boolean; | ||
handleToggleArticle: () => void; | ||
} | ||
|
||
export default function ArticleDropDownWrapper({ | ||
toggleArticle, | ||
handleToggleArticle, | ||
}: ArticleDropDownWrapperProps) { | ||
return ( | ||
<> | ||
{toggleArticle && ( | ||
<div className="fixed inset-0 z-50 flex justify-center bg-white"> | ||
<div className="relative w-full max-w-[480px] bg-white"> | ||
<CancelButton | ||
handleToggle={handleToggleArticle} | ||
className="absolute right-0 top-0 p-4" | ||
/> | ||
<ArticleDropDown /> | ||
</div> | ||
</div> | ||
)} | ||
</> | ||
); | ||
} |
62 changes: 62 additions & 0 deletions
62
src/problem/components/BackToArticle/BackToArticle.test.tsx
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,62 @@ | ||
import { beforeAll, beforeEach,describe, expect, it, vi } from "vitest"; | ||
|
||
import BackToArticle from "./"; | ||
import { BACK_TO_ARTICLE_WORDS } from "@problem/constants/backToArticle"; | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import QueryClientProviders from "@shared/components/queryClientProvider"; | ||
|
||
// Mocking the useParams hook from next/navigation | ||
vi.mock("next/navigation", () => ({ | ||
useParams: vi.fn(), | ||
})); | ||
|
||
const renderWithQueryClient = () => { | ||
return render( | ||
<QueryClientProviders> | ||
<BackToArticle /> | ||
</QueryClientProviders>, | ||
); | ||
}; | ||
|
||
describe("BackToArticle Component 동작 테스트", () => { | ||
beforeAll(() => { | ||
vi.mock("next/navigation", async () => { | ||
const actual = | ||
await vi.importActual<typeof import("next/navigation")>( | ||
"next/navigation", | ||
); | ||
return { | ||
...actual, | ||
useParams: vi.fn(() => ({ | ||
problemId: "1", | ||
})), | ||
}; | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
renderWithQueryClient(); | ||
}); | ||
|
||
it("아티클 다시보기 버튼 클릭 시 문제에 해당하는 아티클이 보인다.", async () => { | ||
|
||
expect(screen.queryByText(BACK_TO_ARTICLE_WORDS.ARTICLE)).toBeInTheDocument(); | ||
|
||
const articleLink = screen.getByText(BACK_TO_ARTICLE_WORDS.ARTICLE); | ||
await userEvent.click(articleLink); | ||
|
||
expect(screen.getByTestId("x-menu")).toBeInTheDocument(); | ||
}); | ||
|
||
it("X 버튼 클릭 시 아티클 뷰가 없어진다.", async () => { | ||
|
||
const articleLink = screen.getByText(BACK_TO_ARTICLE_WORDS.ARTICLE); | ||
await userEvent.click(articleLink); | ||
|
||
const cancelButton = screen.getByTestId("x-menu"); | ||
await userEvent.click(cancelButton); | ||
|
||
expect(screen.queryByTestId("x-menu")).not.toBeInTheDocument(); | ||
}); | ||
}); |
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,74 @@ | ||
"use client"; | ||
import { useParams } from "next/navigation"; | ||
|
||
import { HTMLAttributes, useState } from "react"; | ||
|
||
import { useMutationState } from "@tanstack/react-query"; | ||
|
||
import { ApiResponse } from "@api/fewFetch"; | ||
|
||
import { cn } from "@shared/utils/cn"; | ||
|
||
import { BACK_TO_ARTICLE_WORDS } from "@problem/constants/backToArticle"; | ||
import { QUERY_KEY } from "@problem/remotes/api"; | ||
import { | ||
AnswerCheckInfo, | ||
ProblemAnswerBody, | ||
ProblemAnswerMuationState, | ||
} 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> {} | ||
|
||
export default function BackToArticle({ className }: BackToArticleProps) { | ||
const [toggleArticle, setToggleArticle] = useState(false); | ||
|
||
const handleToggleArticle = () => { | ||
setToggleArticle((prev) => !prev); | ||
}; | ||
|
||
const { problemId } = useParams<{ problemId: string }>(); | ||
const problemAnswersInfo = useMutationState<ProblemAnswerMuationState>({ | ||
filters: { | ||
mutationKey: [QUERY_KEY.POST_PROBLEM_ANSWER, problemId], | ||
}, | ||
select: (mutation) => { | ||
return { | ||
data: mutation.state.data as ApiResponse<AnswerCheckInfo>, | ||
variables: mutation.state.variables as ProblemAnswerBody, | ||
}; | ||
}, | ||
}); | ||
|
||
const answerStatus = new AnswerStatusModel({ | ||
problemAnswerInfo: problemAnswersInfo[0], | ||
}); | ||
|
||
const backToArticleWords = answerStatus.problemSolvedStatus | ||
|
||
return ( | ||
<div | ||
className={cn( | ||
"flex flex-row space-x-[3px] relative", | ||
className, | ||
!answerStatus.isProblemAnswerInfo && "mt-[91px]", | ||
)} | ||
> | ||
<ArticleDropDownWrapper | ||
toggleArticle={toggleArticle} | ||
handleToggleArticle={handleToggleArticle} | ||
/> | ||
<span className="text-sm font-medium text-black"> | ||
{backToArticleWords} | ||
</span> | ||
<span | ||
onClick={handleToggleArticle} | ||
className="cursor-pointer text-sm font-bold text-main underline" | ||
> | ||
{BACK_TO_ARTICLE_WORDS.ARTICLE} | ||
</span> | ||
</div> | ||
); | ||
} |
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,43 @@ | ||
"use client"; | ||
|
||
import { useQueries } from "@tanstack/react-query"; | ||
|
||
import ArticleSkeleton from "@article/components/ArticleSkeleton"; | ||
import { ARTICLE_INFO_TYPE } from "@article/constants/articleCase"; | ||
import { getArticleQueryOptions } from "@article/remotes/getArticleQueryOptions"; | ||
|
||
interface ProblemArticleTemplateProps { | ||
articleId: string | ||
} | ||
|
||
export default function ProblemArticleTemplate({ articleId }: ProblemArticleTemplateProps) { | ||
|
||
const results = useQueries({ | ||
queries: [ | ||
{ | ||
...getArticleQueryOptions({ articleId }), | ||
staleTime: Infinity, | ||
}, | ||
], | ||
}); | ||
const { | ||
data: articleInfo, | ||
isLoading, | ||
isError, | ||
} = results[ARTICLE_INFO_TYPE.ONLY_ARTICLE]; | ||
|
||
if (isLoading || isError || !articleInfo) | ||
return <ArticleSkeleton.EmailContentTemplateSkeleton />; | ||
|
||
const { content } = articleInfo; | ||
|
||
return ( | ||
<table> | ||
<tbody> | ||
<tr style={{}}> | ||
<td dangerouslySetInnerHTML={{ __html: content }}></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
); | ||
} |
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,5 @@ | ||
export const BACK_TO_ARTICLE_WORDS = { | ||
BEFORE: "정답을 모르겠다면?", | ||
AFTER: "복습을 하고 싶다면?", | ||
ARTICLE: "아티클 다시보기" | ||
} |
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,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; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
외부에서 제어하지 않고 articleDropdown wrapper에서 제어하신 이유가 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ArticleDropDownWrapper 하위에 있는 ArticleDropDown 은 toggle 에 영향을 받지 않도록 구성하고 싶어서 wrapper 로 하나 더 감쌌습니다!!