Files
supabase/apps/www/components/ScrollProgress.tsx
Francesco Sansalvadore 2feda5ee19 cms www blog (#38045)
* show cms blog posts in www
* remove contentlayer from www
* outputFileTracingExcludes
* update remotePatterns
* fetch cms posts server-side with revalidation
* add cms env vars to turbo.json
* add www env vars to turbo.json
* include cms posts in www sitemap
* add migration to remove image from cms post
* update cms meta image mapping in www
2025-09-03 14:49:28 +02:00

48 lines
1.4 KiB
TypeScript

'use client'
import { usePathname } from 'next/navigation'
import React, { useEffect, useState } from 'react'
const ScrollProgress = () => {
const [progressPercentage, setProgressPercentage] = useState(0)
const pathname = usePathname()
const isBlogPost = pathname?.includes('/blog/')
if (!isBlogPost) return null
const handleScroll = () => {
if (typeof document === 'undefined') return null
const article = document?.querySelector('article')
if (!article) return null
const { top, height } = (article as any)?.getBoundingClientRect()
let scrollDistance = -top
let progressPercentage =
(scrollDistance / (height - document.documentElement.clientHeight)) * 100
setProgressPercentage(progressPercentage)
}
useEffect(() => {
window.addEventListener('scroll', handleScroll)
return () => {
window.removeEventListener('scroll', handleScroll)
}
}, [])
let isActive = progressPercentage <= 100
return (
<div className="h-[2px] w-full flex justify-start relative">
<div
className="h-full top-0 bottom-0 right-0 absolute w-screen bg-brand will-change-transform transition-opacity"
style={{
display: isActive ? 'absolute' : 'relative',
transform: `translate3d(${isActive ? progressPercentage - 100 + '%' : '0'},0,0)`,
opacity: isActive ? 1 : 0,
}}
/>
</div>
)
}
export default ScrollProgress