Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 10s
Build & Deploy / 🧪 QA (push) Failing after 1m26s
Build & Deploy / 🏗️ Build (push) Failing after 3m19s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🩺 Health Check (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 2s
34 lines
958 B
TypeScript
34 lines
958 B
TypeScript
"use client";
|
|
|
|
import * as React from "react";
|
|
import { useEffect } from "react";
|
|
|
|
interface BlogPostClientProps {
|
|
readingTime: number;
|
|
title: string;
|
|
}
|
|
|
|
export const BlogPostClient: React.FC<BlogPostClientProps> = () => {
|
|
useEffect(() => {
|
|
const handleScroll = () => {
|
|
// Update progress bar
|
|
const winScroll =
|
|
document.body.scrollTop || document.documentElement.scrollTop;
|
|
const height =
|
|
document.documentElement.scrollHeight -
|
|
document.documentElement.clientHeight;
|
|
const scrolled = winScroll / height;
|
|
const progressBar = document.querySelector(
|
|
".reading-progress-bar",
|
|
) as HTMLElement;
|
|
if (progressBar) {
|
|
progressBar.style.transform = `scaleX(${scrolled})`;
|
|
}
|
|
};
|
|
window.addEventListener("scroll", handleScroll);
|
|
return () => window.removeEventListener("scroll", handleScroll);
|
|
}, []);
|
|
|
|
return <div className="reading-progress-bar" />;
|
|
};
|