Files
site/components/Ported.jsx
zeekay 24fb4859f4 Load the sign-in pages whole
hanzo.ai's /login and /signup are the app's pages, so the site's
in-place navigation fetched their data from the app's build and fell
back to a page load with an error. Only this site's own pages move in
place now (lib/route has); everything else here loads whole.

Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk
2026-11-09 06:08:14 -08:00

33 lines
1.8 KiB
React

'use client';
/* A page ported from hanzo.ai as Hanzo renders it, given the new motion layer: each block rises into place as it
is reached, and links inside the site navigate without a reload. */
import { useEffect, useRef } from 'react';
import { useRouter } from 'next/navigation';
import { has } from '../lib/route';
export default function Ported({ html }) {
const ref = useRef(null);
const router = useRouter();
useEffect(() => {
const root = ref.current;
if (!root) return;
// the blocks worth revealing: top-level sections, else the first layer of children
let blocks = [...root.querySelectorAll(':scope > section, :scope > div > section, :scope > div > div > section')];
if (blocks.length < 2) blocks = [...root.children].flatMap((c) => (c.children.length > 1 ? [...c.children] : [c]));
const calm = matchMedia('(prefers-reduced-motion: reduce)').matches;
const vh = innerHeight;
blocks.forEach((b) => { if (!calm && b.getBoundingClientRect().top > vh * 0.9) b.classList.add('x-rv'); });
const io = new IntersectionObserver((es) => es.forEach((e) => { if (e.isIntersecting) { e.target.classList.add('in'); io.unobserve(e.target); } }), { rootMargin: '0px 0px -12% 0px' });
blocks.forEach((b) => b.classList.contains('x-rv') && io.observe(b));
const click = (e) => {
const a = e.target.closest('a[href^="/"]');
if (!a || a.target === '_blank' || e.metaKey || e.ctrlKey || e.shiftKey || a.hasAttribute('download') || !has(a.getAttribute('href'))) return;
e.preventDefault();
router.push(a.getAttribute('href'));
};
root.addEventListener('click', click);
return () => { io.disconnect(); root.removeEventListener('click', click); };
}, [html, router]);
return <div ref={ref} className="x-port" dangerouslySetInnerHTML={{ __html: html }} />;
}