From 6b4c7b3329678bd472f3bc60375f68308c6b20e7 Mon Sep 17 00:00:00 2001
From: sasha-astiadi
Date: Mon, 24 Nov 2025 14:13:40 +0100
Subject: [PATCH] refactor: implement smart navigation for "Get Mycelium
Connector" button with smooth scroll utility
- Added smoothScrollToElement utility function in src/utils/scroll.ts with easeInOutQuad animation and configurable duration
- Changed Header and HeaderDark "Get Mycelium Connector" button from static /download link to onClick handler with conditional navigation
- Added handleGetConnectorClick function that scrolls to #download section when on /network page, otherwise navigates to /network
- Change
---
src/components/Header.tsx | 26 ++++++++++++++++++++++---
src/components/HeaderDark.tsx | 26 ++++++++++++++++++++++---
src/components/ui/floating-navbar.tsx | 16 ++++++++++++---
src/pages/network/Hero.tsx | 7 ++++++-
src/pages/nodes/NodeHero.tsx | 8 ++------
src/utils/scroll.ts | 28 +++++++++++++++++++++++++++
6 files changed, 95 insertions(+), 16 deletions(-)
create mode 100644 src/utils/scroll.ts
diff --git a/src/components/Header.tsx b/src/components/Header.tsx
index abbc88d..c651c1e 100644
--- a/src/components/Header.tsx
+++ b/src/components/Header.tsx
@@ -1,5 +1,6 @@
import { useState } from 'react'
-import { Link } from 'react-router-dom'
+import { Link, useLocation, useNavigate } from 'react-router-dom'
+import { smoothScrollToElement } from '@/utils/scroll'
import { Container } from './Container'
import { Button } from './Button'
import pmyceliumLogo from '../images/logos/mainlogo.svg'
@@ -9,6 +10,17 @@ import { Bars3Icon, XMarkIcon } from '@heroicons/react/24/outline'
export function Header() {
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
+ const navigate = useNavigate()
+ const location = useLocation()
+
+ const handleGetConnectorClick = () => {
+ if (location.pathname === '/network') {
+ smoothScrollToElement('download', 1200)
+ } else {
+ navigate('/network')
+ }
+ }
+
return (
-
+ smoothScrollToElement('download', 1200)}
+ >
Get Started
{
- const el = document.getElementById('node-how-it-works')
- if (el) {
- el.scrollIntoView({ behavior: 'smooth', block: 'start' })
- }
- }}
+ onClick={() => smoothScrollToElement('node-how-it-works', 1200)}
>
How it works
diff --git a/src/utils/scroll.ts b/src/utils/scroll.ts
new file mode 100644
index 0000000..167463f
--- /dev/null
+++ b/src/utils/scroll.ts
@@ -0,0 +1,28 @@
+export function smoothScrollToElement(id: string, duration = 800) {
+ const element = document.getElementById(id)
+ if (!element) return
+
+ const startY = window.scrollY || window.pageYOffset
+ const targetRect = element.getBoundingClientRect()
+ const targetY = startY + targetRect.top
+ const startTime = performance.now()
+
+ function easeInOutQuad(t: number) {
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t
+ }
+
+ function step(currentTime: number) {
+ const elapsed = currentTime - startTime
+ const progress = Math.min(elapsed / duration, 1)
+ const eased = easeInOutQuad(progress)
+ const nextY = startY + (targetY - startY) * eased
+
+ window.scrollTo(0, nextY)
+
+ if (progress < 1) {
+ requestAnimationFrame(step)
+ }
+ }
+
+ requestAnimationFrame(step)
+}