mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 06:27:16 +08:00
* 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
48 lines
1.4 KiB
TypeScript
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
|