浏览代码

fix: remove Intersection Observer causing stuck loading, fix SecondSelf URL

- IO conflicts with react-grid-layout absolute positioning
- Map and IconCloud already lazy-loaded via next/dynamic
- Fix SecondSelf link to secondself.us
- Use mousedown/mouseup for Mini click detection (avoid drag conflict)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
rriecc 9 月之前
父节点
当前提交
7145d2b154
共有 3 个文件被更改,包括 29 次插入 和 52 次删除
  1. 1 1
      components/actions.tsx
  2. 5 49
      components/home-client.tsx
  3. 23 2
      components/mini-pic.tsx

+ 1 - 1
components/actions.tsx

@@ -24,7 +24,7 @@ const Actions = ({ photoUrl }: ActionsProps) => {
           <Link
             isExternal
             color="foreground"
-            href="https://secondself.com/"
+            href="https://secondself.us/"
           >
             <span className="text-sm md:text-medium text-nowrap hidden group-hover:block invisible group-hover:visible mr-1 animate-fade">
               SecondSelf

+ 5 - 49
components/home-client.tsx

@@ -2,13 +2,7 @@
 
 import { Tab, Tabs } from "@heroui/react";
 import { Responsive } from "react-grid-layout";
-import {
-  useEffect,
-  useState,
-  useTransition,
-  useRef,
-  useCallback,
-} from "react";
+import { useEffect, useState, useTransition, useCallback } from "react";
 import { useRouter } from "next/navigation";
 import dynamic from "next/dynamic";
 import { HashLoader } from "react-spinners";
@@ -73,29 +67,6 @@ const Chatbot = dynamic(() => import("@/components/chatbot"), {
   loading: LoadingPlaceholder,
 });
 
-// Hook for viewport detection via Intersection Observer
-function useInView(options?: IntersectionObserverInit) {
-  const ref = useRef<HTMLDivElement>(null);
-  const [inView, setInView] = useState(false);
-
-  useEffect(() => {
-    const el = ref.current;
-    if (!el) return;
-
-    const observer = new IntersectionObserver(([entry]) => {
-      if (entry.isIntersecting) {
-        setInView(true);
-        observer.disconnect();
-      }
-    }, options);
-
-    observer.observe(el);
-    return () => observer.disconnect();
-  }, [options]);
-
-  return { ref, inView };
-}
-
 interface HomeClientProps {
   photos: string[];
   avatarUrl: string;
@@ -123,14 +94,6 @@ export default function HomeClient({
   const router = useRouter();
   const [show3D, setShow3D] = useState(false);
 
-  // Intersection observers for heavy components
-  const ioOptions = useRef<IntersectionObserverInit>({
-    rootMargin: "200px",
-  }).current;
-  const mapIO = useInView(ioOptions);
-  const iconCloudIO = useInView(ioOptions);
-  const miniIO = useInView(ioOptions);
-
   const handleMiniClick = useCallback(() => {
     setShow3D(true);
   }, []);
@@ -229,7 +192,6 @@ export default function HomeClient({
           <AnimatedEmoji />
         </div>
         <div
-          ref={mapIO.ref}
           key="mapComponent"
           className={cn(
             "bg-white dark:bg-darkBg cursor-grab active:cursor-grabbing rounded-[2rem] flex justify-center items-center z-[1]",
@@ -238,10 +200,9 @@ export default function HomeClient({
               : "opacity-50",
           )}
         >
-          {mapIO.inView ? <MapComponent /> : <LoadingPlaceholder />}
+          <MapComponent />
         </div>
         <div
-          ref={iconCloudIO.ref}
           key="iconCloud"
           className={cn(
             "bg-white dark:bg-darkBg border-2 border-transparent dark:border-knight cursor-grab active:cursor-grabbing rounded-[2rem] flex justify-center items-center relative overflow-hidden p-10 md:p-8 z-[1]",
@@ -250,11 +211,7 @@ export default function HomeClient({
               : "opacity-50",
           )}
         >
-          {iconCloudIO.inView ? (
-            <IconCloud iconSlugs={icons} />
-          ) : (
-            <LoadingPlaceholder />
-          )}
+          <IconCloud iconSlugs={icons} />
         </div>
         <div
           key="webAgent"
@@ -277,7 +234,6 @@ export default function HomeClient({
           <Chatbot chatbotUrl={chatbotUrl} />
         </div>
         <div
-          ref={miniIO.ref}
           key="miniModel"
           className={cn(
             "bg-white dark:bg-darkBg border-2 border-transparent dark:border-knight cursor-grab active:cursor-grabbing rounded-[2rem] flex justify-center items-center z-[1] overflow-hidden",
@@ -286,10 +242,10 @@ export default function HomeClient({
               : "opacity-50",
           )}
         >
-          {show3D && miniIO.inView ? (
+          {show3D ? (
             <MiniModel />
           ) : (
-            <MiniPic onClick={handleMiniClick} showOverlay={miniIO.inView} />
+            <MiniPic onClick={handleMiniClick} showOverlay />
           )}
         </div>
         <div

+ 23 - 2
components/mini-pic.tsx

@@ -1,5 +1,6 @@
 import { useTheme } from "next-themes";
 import { Image } from "@heroui/react";
+import { useRef } from "react";
 
 interface MiniPicProps {
   onClick?: () => void;
@@ -9,9 +10,29 @@ interface MiniPicProps {
 const MiniPic = ({ onClick, showOverlay = false }: MiniPicProps) => {
   const { theme } = useTheme();
   const isDark = theme === "dark";
+  const startPos = useRef<{ x: number; y: number } | null>(null);
+
+  const handleMouseDown = (e: React.MouseEvent) => {
+    startPos.current = { x: e.clientX, y: e.clientY };
+  };
+
+  const handleMouseUp = (e: React.MouseEvent) => {
+    if (!startPos.current) return;
+    const dx = Math.abs(e.clientX - startPos.current.x);
+    const dy = Math.abs(e.clientY - startPos.current.y);
+    // Only trigger click if mouse didn't move much (not a drag)
+    if (dx < 5 && dy < 5) {
+      onClick?.();
+    }
+    startPos.current = null;
+  };
 
   return (
-    <div className="relative w-full h-full cursor-pointer" onClick={onClick}>
+    <div
+      className="relative w-full h-full cursor-pointer"
+      onMouseDown={handleMouseDown}
+      onMouseUp={handleMouseUp}
+    >
       {isDark ? (
         <Image
           alt="cover"
@@ -26,7 +47,7 @@ const MiniPic = ({ onClick, showOverlay = false }: MiniPicProps) => {
         />
       )}
       {showOverlay && (
-        <div className="absolute inset-0 flex items-end justify-center pb-4 z-10">
+        <div className="absolute inset-0 flex items-end justify-center pb-4 z-10 pointer-events-none">
           <span className="bg-black/50 text-white text-xs px-3 py-1.5 rounded-full backdrop-blur-sm">
             Click for 3D
           </span>