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

[ Feature/dev 112] 문제풀기 Floating Button 구현 #173

Merged
merged 6 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions public/assets/icon/problemIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/app/article/[articleId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ArticleFloatingButton from "@article/components/ArticleFloatingButton";
import ArticleTitle from "@article/components/ArticleTitle";
import EmailContentTemplate from "@article/components/EmailContentTemplate";
import { prefetchArticleQuery } from "@article/remotes/prefetchArticleQuery";
Expand Down Expand Up @@ -33,6 +34,7 @@ export default async function ArticlePage({
<ArticleTitle />
<EmailContentTemplate />
</div>
<ArticleFloatingButton />
</HydrationBoundary>
);
}
65 changes: 65 additions & 0 deletions src/article/components/ArticleFloatingButton/index.tsx
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(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

이안에서 function ~ 함수명 으로 컨벤션 맞춰주시면 좋을 것 같아요!

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
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.

지피티의 초안 ㅋㅎㅋㅎㅋㅎ

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">
Copy link
Collaborator

Choose a reason for hiding this comment

The 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}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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>
)}
</>
);
}