Skip to content

Commit

Permalink
fix routing persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
wheattoast11 committed Nov 21, 2024
1 parent 62be2ec commit d36c81d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
30 changes: 22 additions & 8 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect } from 'react';
import { createRoot } from 'react-dom/client';
import React, { useEffect, useState } from 'react';
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import Home from './pages/Home';
import Manifesto from './pages/Manifesto';
Expand All @@ -9,14 +8,19 @@ import { ScrollEffects } from './ui/ScrollEffects';
import { RemotionVideo } from './Video';

function App() {
const [scene, setScene] = useState(null);
const [effects, setEffects] = useState({ card: null, scroll: null });

useEffect(() => {
// Initialize Three.js scene
const scene = new Scene();
scene.animate();
const newScene = new Scene();
newScene.animate();
setScene(newScene);

// Initialize UI effects
new CardEffects();
new ScrollEffects();
const cardEffects = new CardEffects();
const scrollEffects = new ScrollEffects();
setEffects({ card: cardEffects, scroll: scrollEffects });

// Initialize Remotion video
const videoContainer = document.createElement('div');
Expand All @@ -31,18 +35,28 @@ function App() {
videoRoot.render(<RemotionVideo />);

return () => {
// Cleanup
if (scene) {
scene.dispose();
}
if (videoContainer.parentNode) {
videoContainer.parentNode.removeChild(videoContainer);
}
};
}, []);

// Reinitialize effects on route change
const handleRouteChange = () => {
if (effects.card) effects.card.init();
if (effects.scroll) effects.scroll.init();
};

return (
<Router>
<canvas id="bg"></canvas>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/manifesto" element={<Manifesto />} />
<Route path="/" element={<Home onMount={handleRouteChange} />} />
<Route path="/manifesto" element={<Manifesto onMount={handleRouteChange} />} />
<Route path="*" element={<Navigate to="/" />} />
</Routes>
</Router>
Expand Down
8 changes: 6 additions & 2 deletions src/pages/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React from 'react';
import React, { useEffect } from 'react';
import { Link } from 'react-router-dom';

function Home() {
function Home({ onMount }) {
useEffect(() => {
onMount();
}, [onMount]);

return (
<div id="app">
<canvas id="bg"></canvas>
Expand Down
8 changes: 6 additions & 2 deletions src/pages/Manifesto.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React from 'react';
import React, { useEffect } from 'react';
import { Link } from 'react-router-dom';

function Manifesto() {
function Manifesto({ onMount }) {
useEffect(() => {
onMount();
}, [onMount]);

return (
<div id="app">
<canvas id="bg"></canvas>
Expand Down
20 changes: 20 additions & 0 deletions src/three/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,24 @@ export class Scene {

this.renderer.render(this.scene, this.camera);
}

dispose() {
// Remove event listeners
window.removeEventListener('resize', this.handleResize);
document.removeEventListener('mousemove', this.handleMouseMove);

// Dispose of Three.js resources
this.scene.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
if (Array.isArray(object.material)) {
object.material.forEach(material => material.dispose());
} else {
object.material.dispose();
}
}
});

this.renderer.dispose();
}
}

0 comments on commit d36c81d

Please sign in to comment.