Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions apps/web-dashboard/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Routes, Route } from 'react-router-dom';
import { Toaster } from 'react-hot-toast';
import ScrollToTop from './components/Layout/ScrollToTop';
import Login from './pages/Login';
import Signup from './pages/Signup';
import MainLayout from './components/Layout/MainLayout';
Expand Down Expand Up @@ -51,6 +52,8 @@ function AppContent() {
}}
/>

<ScrollToTop />

<Routes>
<Route path="/" element={<LandingPage />} />
<Route path="/pricing" element={<Pricing />} />
Expand Down
50 changes: 48 additions & 2 deletions apps/web-dashboard/src/components/Hyperspeed/Hyperspeed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ const Hyperspeed = ({ effectOptions = DEFAULT_EFFECT_OPTIONS }) => {
alpha: true
});
this.renderer.setSize(initW, initH, false);
this.renderer.setPixelRatio(window.devicePixelRatio);
this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.5));
this.composer = new EffectComposer(this.renderer);
container.append(this.renderer.domElement);

Expand All @@ -382,6 +382,7 @@ const Hyperspeed = ({ effectOptions = DEFAULT_EFFECT_OPTIONS }) => {
this.clock = new THREE.Clock();
this.assets = {};
this.disposed = false;
this.paused = false;

this.road = new Road(this, options);
this.leftCarLights = new CarLights(
Expand Down Expand Up @@ -584,8 +585,20 @@ const Hyperspeed = ({ effectOptions = DEFAULT_EFFECT_OPTIONS }) => {
this.composer.render(delta);
}

pause() {
this.paused = true;
}

resume() {
if (this.disposed || !this.paused) return;
this.paused = false;
this.clock.getDelta();
requestAnimationFrame(this.tick);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

dispose() {
this.disposed = true;
this.paused = true;

if (this.scene) {
this.scene.traverse(object => {
Expand Down Expand Up @@ -639,7 +652,7 @@ const Hyperspeed = ({ effectOptions = DEFAULT_EFFECT_OPTIONS }) => {
}

tick() {
if (this.disposed) return;
if (this.disposed || this.paused) return;

if (!this.hasValidSize) {
const w = this.container.offsetWidth;
Expand Down Expand Up @@ -1183,6 +1196,39 @@ const Hyperspeed = ({ effectOptions = DEFAULT_EFFECT_OPTIONS }) => {
};
}, [effectOptions]);

useEffect(() => {
const el = hyperspeed.current;
if (!el) return;

const syncPauseState = (shouldPause) => {
if (!appRef.current) return;
if (shouldPause) appRef.current.pause();
else appRef.current.resume();
};

const observer = new IntersectionObserver(
([entry]) => syncPauseState(!entry.isIntersecting),
{ rootMargin: '80px', threshold: 0 }
);
observer.observe(el);

const onVisibilityChange = () => {
if (document.hidden) {
syncPauseState(true);
return;
}
const rect = el.getBoundingClientRect();
const inView = rect.bottom > 0 && rect.top < window.innerHeight;
syncPauseState(!inView);
};
document.addEventListener('visibilitychange', onVisibilityChange);

return () => {
observer.disconnect();
document.removeEventListener('visibilitychange', onVisibilityChange);
};
}, []);

return <div id="lights" ref={hyperspeed}></div>;
};

Expand Down
13 changes: 13 additions & 0 deletions apps/web-dashboard/src/components/Layout/ScrollToTop.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';

export default function ScrollToTop() {
const { pathname, hash } = useLocation();

useEffect(() => {
if (hash) return;
window.scrollTo(0, 0);
}, [pathname, hash]);

return null;
}
29 changes: 29 additions & 0 deletions apps/web-dashboard/src/hooks/useInView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useEffect, useRef, useState } from 'react';

const DEFAULT_ROOT_MARGIN = '200px 0px';
const DEFAULT_THRESHOLD = 0;

export function useInView({
rootMargin = DEFAULT_ROOT_MARGIN,
threshold = DEFAULT_THRESHOLD,
} = {}) {
const ref = useRef(null);
const [inView, setInView] = useState(false);

useEffect(() => {
const node = ref.current;
if (!node) return;

const observer = new IntersectionObserver(([entry]) => {
if (entry.isIntersecting) {
setInView(true);
observer.disconnect();
}
}, { rootMargin, threshold });

observer.observe(node);
return () => observer.disconnect();
}, [rootMargin, threshold]);

return [ref, inView];
}
17 changes: 17 additions & 0 deletions apps/web-dashboard/src/hooks/usePrefersReducedMotion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useEffect, useState } from 'react';

export function usePrefersReducedMotion() {
const [prefersReducedMotion, setPrefersReducedMotion] = useState(() => {
if (typeof window === 'undefined') return false;
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
});

useEffect(() => {
const media = window.matchMedia('(prefers-reduced-motion: reduce)');
const onChange = (event) => setPrefersReducedMotion(event.matches);
media.addEventListener('change', onChange);
return () => media.removeEventListener('change', onChange);
}, []);

return prefersReducedMotion;
}
Loading
Loading