|
|
@@ -2,7 +2,13 @@
|
|
|
|
|
|
import { Tab, Tabs } from "@heroui/react";
|
|
|
import { Responsive } from "react-grid-layout";
|
|
|
-import { useEffect, useState, useTransition } from "react";
|
|
|
+import {
|
|
|
+ useEffect,
|
|
|
+ useState,
|
|
|
+ useTransition,
|
|
|
+ useRef,
|
|
|
+ useCallback,
|
|
|
+} from "react";
|
|
|
import { useRouter } from "next/navigation";
|
|
|
import dynamic from "next/dynamic";
|
|
|
import { HashLoader } from "react-spinners";
|
|
|
@@ -13,10 +19,7 @@ import { cn } from "@/lib/utils";
|
|
|
import AvatarTransition from "@/components/avatar";
|
|
|
import { DockDemo } from "@/components/dock-demo";
|
|
|
import { ThemeSwitch } from "@/components/theme-switch";
|
|
|
-import CardStack from "@/components/card-stack";
|
|
|
-import AnimatedEmoji from "@/components/animated-emoji";
|
|
|
-import WebAgent from "@/components/webagent";
|
|
|
-import Chatbot from "@/components/chatbot";
|
|
|
+import MiniPic from "@/components/mini-pic";
|
|
|
import Actions from "@/components/actions";
|
|
|
import { layouts, selectedCard } from "@/config/layout";
|
|
|
import { icons } from "@/config/icons";
|
|
|
@@ -49,6 +52,50 @@ const MiniModel = dynamic(
|
|
|
},
|
|
|
);
|
|
|
|
|
|
+// Lazy load components that were previously eagerly imported
|
|
|
+const AnimatedEmoji = dynamic(() => import("@/components/animated-emoji"), {
|
|
|
+ ssr: false,
|
|
|
+ loading: LoadingPlaceholder,
|
|
|
+});
|
|
|
+
|
|
|
+const CardStack = dynamic(() => import("@/components/card-stack"), {
|
|
|
+ ssr: false,
|
|
|
+ loading: LoadingPlaceholder,
|
|
|
+});
|
|
|
+
|
|
|
+const WebAgent = dynamic(() => import("@/components/webagent"), {
|
|
|
+ ssr: false,
|
|
|
+ loading: LoadingPlaceholder,
|
|
|
+});
|
|
|
+
|
|
|
+const Chatbot = dynamic(() => import("@/components/chatbot"), {
|
|
|
+ ssr: false,
|
|
|
+ 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;
|
|
|
@@ -74,6 +121,19 @@ export default function HomeClient({
|
|
|
const [tabSelected, setTabSelected] = useState("all");
|
|
|
const [, startTransition] = useTransition();
|
|
|
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);
|
|
|
+ }, []);
|
|
|
|
|
|
useEffect(() => {
|
|
|
router.prefetch("/blog");
|
|
|
@@ -169,6 +229,7 @@ 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]",
|
|
|
@@ -177,9 +238,10 @@ export default function HomeClient({
|
|
|
: "opacity-50",
|
|
|
)}
|
|
|
>
|
|
|
- <MapComponent />
|
|
|
+ {mapIO.inView ? <MapComponent /> : <LoadingPlaceholder />}
|
|
|
</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]",
|
|
|
@@ -188,7 +250,11 @@ export default function HomeClient({
|
|
|
: "opacity-50",
|
|
|
)}
|
|
|
>
|
|
|
- <IconCloud iconSlugs={icons} />
|
|
|
+ {iconCloudIO.inView ? (
|
|
|
+ <IconCloud iconSlugs={icons} />
|
|
|
+ ) : (
|
|
|
+ <LoadingPlaceholder />
|
|
|
+ )}
|
|
|
</div>
|
|
|
<div
|
|
|
key="webAgent"
|
|
|
@@ -211,6 +277,7 @@ 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",
|
|
|
@@ -219,7 +286,11 @@ export default function HomeClient({
|
|
|
: "opacity-50",
|
|
|
)}
|
|
|
>
|
|
|
- <MiniModel />
|
|
|
+ {show3D && miniIO.inView ? (
|
|
|
+ <MiniModel />
|
|
|
+ ) : (
|
|
|
+ <MiniPic onClick={handleMiniClick} showOverlay={miniIO.inView} />
|
|
|
+ )}
|
|
|
</div>
|
|
|
<div
|
|
|
key="actions"
|