-
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 112] 문제풀기 Floating Button 구현 #173
Changes from 1 commit
e81f6a5
bfcc8a8
8ec4a8a
11a5ce2
de0072a
87e5d4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"use client"; | ||
|
||
import { useParams, useRouter } from "next/navigation"; | ||
|
||
import { useEffect, useState } from "react"; | ||
|
||
import { Button } from "@shared/components/ui/button"; | ||
import { useProblemIdsViewModel } from "@shared/models/useProblemIdsViewModel"; | ||
import { cn } from "@shared/utils/cn"; | ||
|
||
import ProblemIcon from "public/assets/icon/problemIcon.svg"; | ||
|
||
export default function ArticleFloatingButton() { | ||
const { articleId } = useParams<{ articleId: string }>(); | ||
const { push } = useRouter(); | ||
const { getCurrentProblemId } = useProblemIdsViewModel(); | ||
|
||
const [showButton, setShowButton] = useState(true); | ||
|
||
const onClickGoProblem = () => { | ||
push(`/problem/${getCurrentProblemId()}`); | ||
// Mixpanel.track({ | ||
// name: EVENT_NAME.ARTICLE_PROBLEMBUTTON_TAPPED, | ||
// property: { id: articleId }, | ||
// }); | ||
}; | ||
|
||
useEffect(() => { | ||
const handleShowButton = () => { | ||
const scrollY = window.scrollY; | ||
const viewportHeight = window.innerHeight; | ||
const documentHeight = document.documentElement.scrollHeight; | ||
|
||
// Hide button only if the user reaches the bottom of the page | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 어디선가 로직을 가져온것이냐...아니면 숨니의 영어실력..? ㅋㅎㅋㅎㅋㅎ진실을 알려줘! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 지피티의 초안 ㅋㅎㅋㅎㅋㅎ |
||
if (scrollY + viewportHeight >= documentHeight - 1) { | ||
setShowButton(false); | ||
} else { | ||
setShowButton(true); | ||
} | ||
}; | ||
|
||
window.addEventListener("scroll", handleShowButton); | ||
return () => { | ||
window.removeEventListener("scroll", handleShowButton); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<> | ||
{showButton && ( | ||
<div className="fixed bottom-[48px] left-[60%] z-10 w-fit"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 혹시 여기 bottom은 px로 하고 left는 %로 사용하신 이유가 있을 까요? |
||
<Button | ||
className={cn( | ||
"h-[55px] px-5 py-3.5 bg-[#264932] rounded-[99px] shadow flex justify-center items-center gap-2" | ||
)} | ||
onClick={onClickGoProblem} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. button type 명시해주면 시멘틱스러울 것 같습니다! |
||
> | ||
<ProblemIcon /> | ||
<span className="text-base font-bold text-white">퀴즈 풀기</span> | ||
</Button> | ||
</div> | ||
)} | ||
</> | ||
); | ||
} |
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.
이안에서 function ~ 함수명 으로 컨벤션 맞춰주시면 좋을 것 같아요!