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

feat: added scroll indicator #418

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 2 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Footer from "@/components/core/footer";
import Navbar from "@/components/core/navbar";
import { cookies } from "next/headers";
import { getGithubStars } from "@/helper/getGithubStars";
import ProgressBar from "@/components/ProgressBar";

export default async function Home() {
const starCount: number = await getGithubStars();
Expand All @@ -13,6 +14,7 @@ export default async function Home() {

return (
<>
<ProgressBar />
Copy link
Owner

Choose a reason for hiding this comment

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

can't we use the framer motion here? The same is implemented in:
src/components/pages/contribute/index.tsx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure working on it

<Navbar starCount={starCount} />
<HomePage accountId={accountId} />
<Footer />
Expand Down
33 changes: 33 additions & 0 deletions src/components/ProgressBar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use client";
Copy link
Owner

Choose a reason for hiding this comment

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

feels a lot of extra work since this feature is already developed

import { useEffect, useState } from "react"

const ProgressBar = () => {
const [progressWidth, setProgressWidth] = useState(0)

useEffect(() => {
const handleScroll = ()=>{
const windowHeight = window.innerHeight;
const docHeight = document.documentElement.scrollHeight;

const scrollY = window.scrollY;

const scrollPercentage = Math.floor((scrollY / (docHeight - windowHeight)) * 100);
setProgressWidth(scrollPercentage);
}

window.addEventListener("scroll", handleScroll);

return ()=>{
window.removeEventListener("scroll", handleScroll);
}
}, [progressWidth])


return (
<div className="progress-container h-2 w-full bg-transparent fixed top-0 z-10 backdrop-blur-sm">
<div className={`progress-fill bg-[rgb(240,46,101)] h-full`} style={{width : `${progressWidth}%`}}></div>
</div>
)
}

export default ProgressBar
2 changes: 1 addition & 1 deletion src/components/core/navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const Navbar = ({ starCount }: { starCount?: number }) => {

return (
<>
<nav className="w-full sticky top-0 shadow-md py-2 px-4 md:px-10 backdrop-blur-sm dark:shadow-gray-600 z-50">
<nav className="w-full sticky top-2 shadow-md py-2 px-4 md:px-10 backdrop-blur-sm dark:shadow-gray-600 z-50">
{/* Desktop menu items */}
<div className="max-w-screen-lg mx-auto flex items-center content-center justify-between backdrop-blur-sm bg-grey-100 bg-opacity-20 h-16 my-2">
<Link href={userAuth.creds?.userId ? "/feed" : "/"}>
Expand Down
Loading