feat: fix spacing and comment out trpc

This commit is contained in:
Jet Pham 2025-11-25 14:49:23 -08:00
parent 2010438475
commit 234e637b20
No known key found for this signature in database
8 changed files with 225 additions and 122 deletions

View file

@ -1,50 +1,62 @@
"use client";
import { useEffect, useRef } from "react";
import { useEffect, useRef, useCallback } from "react";
export function CgolCanvas() {
const canvasRef = useRef<HTMLCanvasElement>(null);
const initializedRef = useRef(false);
const cleanupRef = useRef<(() => void) | null>(null);
useEffect(() => {
const initializeWasm = useCallback(async () => {
if (typeof window === "undefined") return;
const initializeWasm = async () => {
try {
const canvas = canvasRef.current;
if (!canvas || initializedRef.current) return;
try {
const canvas = canvasRef.current;
if (!canvas || initializedRef.current) return;
const cgolModule = await import("cgol");
// Initialize WASM module
const initFunction = cgolModule.default;
if (initFunction && typeof initFunction === "function") {
await initFunction();
}
// Start CGOL
if (typeof cgolModule.start === "function") {
cgolModule.start();
initializedRef.current = true;
}
} catch (error: unknown) {
console.error("Failed to initialize CGOL WebAssembly module:", error);
const cgolModule = await import("cgol");
// Initialize WASM module
const initFunction = cgolModule.default;
if (initFunction && typeof initFunction === "function") {
await initFunction();
}
};
const timeoutId = setTimeout(() => {
void initializeWasm();
}, 100);
// Start CGOL
if (typeof cgolModule.start === "function") {
cgolModule.start();
initializedRef.current = true;
return () => clearTimeout(timeoutId);
const cleanupFn = (cgolModule as { cleanup?: () => void }).cleanup;
if (typeof cleanupFn === "function") {
cleanupRef.current = cleanupFn;
}
}
} catch (error: unknown) {
console.error("Failed to initialize CGOL WebAssembly module:", error);
}
}, []);
useEffect(() => {
// Initialize immediately without delay
void initializeWasm();
return () => {
// Call cleanup if available from WASM module
if (cleanupRef.current) {
cleanupRef.current();
}
// Reset initialization state on unmount
initializedRef.current = false;
};
}, [initializeWasm]);
return (
<canvas
ref={canvasRef}
id="canvas"
className="fixed top-0 left-0 w-screen h-screen -z-10"
className="fixed top-0 left-0 -z-10 h-screen w-screen"
aria-hidden="true"
/>
);
}