home-client.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. "use client";
  2. import { Tab, Tabs } from "@heroui/react";
  3. import { Responsive } from "react-grid-layout";
  4. import {
  5. useEffect,
  6. useState,
  7. useTransition,
  8. useRef,
  9. useCallback,
  10. } from "react";
  11. import { useRouter } from "next/navigation";
  12. import dynamic from "next/dynamic";
  13. import { HashLoader } from "react-spinners";
  14. import Paper from "./paper";
  15. import { cn } from "@/lib/utils";
  16. import AvatarTransition from "@/components/avatar";
  17. import { DockDemo } from "@/components/dock-demo";
  18. import { ThemeSwitch } from "@/components/theme-switch";
  19. import MiniPic from "@/components/mini-pic";
  20. import Actions from "@/components/actions";
  21. import { layouts, selectedCard } from "@/config/layout";
  22. import { icons } from "@/config/icons";
  23. import useWindowWidth from "@/hooks/useWindowWidth";
  24. const LoadingPlaceholder = () => (
  25. <div className="w-full h-full flex justify-center items-center">
  26. <HashLoader color="#eef0f7" size={50} />
  27. </div>
  28. );
  29. // Lazy load heavy client components with next/dynamic
  30. // These components use browser APIs (WebGL, Mapbox) so ssr: false is required
  31. const IconCloud = dynamic(() => import("@/components/icon-cloud"), {
  32. ssr: false,
  33. loading: LoadingPlaceholder,
  34. });
  35. const MapComponent = dynamic(() => import("@/components/map"), {
  36. ssr: false,
  37. loading: LoadingPlaceholder,
  38. });
  39. // Named export requires .then(mod => mod.Name)
  40. const MiniModel = dynamic(
  41. () => import("@/components/mini").then((mod) => mod.MiniModel),
  42. {
  43. ssr: false,
  44. loading: LoadingPlaceholder,
  45. },
  46. );
  47. // Lazy load components that were previously eagerly imported
  48. const AnimatedEmoji = dynamic(() => import("@/components/animated-emoji"), {
  49. ssr: false,
  50. loading: LoadingPlaceholder,
  51. });
  52. const CardStack = dynamic(() => import("@/components/card-stack"), {
  53. ssr: false,
  54. loading: LoadingPlaceholder,
  55. });
  56. const WebAgent = dynamic(() => import("@/components/webagent"), {
  57. ssr: false,
  58. loading: LoadingPlaceholder,
  59. });
  60. const Chatbot = dynamic(() => import("@/components/chatbot"), {
  61. ssr: false,
  62. loading: LoadingPlaceholder,
  63. });
  64. // Hook for viewport detection via Intersection Observer
  65. function useInView(options?: IntersectionObserverInit) {
  66. const ref = useRef<HTMLDivElement>(null);
  67. const [inView, setInView] = useState(false);
  68. useEffect(() => {
  69. const el = ref.current;
  70. if (!el) return;
  71. const observer = new IntersectionObserver(([entry]) => {
  72. if (entry.isIntersecting) {
  73. setInView(true);
  74. observer.disconnect();
  75. }
  76. }, options);
  77. observer.observe(el);
  78. return () => observer.disconnect();
  79. }, [options]);
  80. return { ref, inView };
  81. }
  82. interface HomeClientProps {
  83. photos: string[];
  84. avatarUrl: string;
  85. dogUrl: string;
  86. actionImageUrl: string;
  87. resumeUrl: string;
  88. webagentUrl: string;
  89. chatbotUrl: string;
  90. paperUrl: string;
  91. }
  92. export default function HomeClient({
  93. photos,
  94. avatarUrl,
  95. dogUrl,
  96. actionImageUrl,
  97. resumeUrl,
  98. webagentUrl,
  99. chatbotUrl,
  100. paperUrl,
  101. }: HomeClientProps) {
  102. const width = useWindowWidth();
  103. const [tabSelected, setTabSelected] = useState("all");
  104. const [, startTransition] = useTransition();
  105. const router = useRouter();
  106. const [show3D, setShow3D] = useState(false);
  107. // Intersection observers for heavy components
  108. const ioOptions = useRef<IntersectionObserverInit>({
  109. rootMargin: "200px",
  110. }).current;
  111. const mapIO = useInView(ioOptions);
  112. const iconCloudIO = useInView(ioOptions);
  113. const miniIO = useInView(ioOptions);
  114. const handleMiniClick = useCallback(() => {
  115. setShow3D(true);
  116. }, []);
  117. useEffect(() => {
  118. router.prefetch("/blog");
  119. }, [router]);
  120. if (!width) {
  121. return null;
  122. }
  123. return (
  124. <div className="flex justify-center flex-col items-center">
  125. <Tabs
  126. aria-label="Tabs"
  127. className="mb-2 md:mb-6 rounded-full"
  128. classNames={{
  129. cursor: "shadow-none",
  130. tabList:
  131. "bg-[#ece7e7] dark:bg-darkBg border-2 border-transparent dark:border-knight rounded-full",
  132. }}
  133. radius={"full"}
  134. onSelectionChange={(selected) => {
  135. if (selected === "blog") {
  136. startTransition(() => {
  137. router.push("/blog");
  138. });
  139. return;
  140. }
  141. setTabSelected(selected as string);
  142. }}
  143. >
  144. <Tab key="all" title="All" />
  145. <Tab key="about" title="About" />
  146. <Tab key="projects" title="Projects" />
  147. <Tab key="blog" title="Blog" />
  148. </Tabs>
  149. <Responsive
  150. breakpoints={{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }}
  151. className="layout w-full h-full"
  152. cols={{ lg: 4, md: 4, sm: 2, xs: 2, xxs: 2 }}
  153. layouts={layouts[tabSelected]}
  154. margin={[15, 15]}
  155. width={width}
  156. >
  157. <div
  158. key="avatar"
  159. className={cn(
  160. "bg-white dark:bg-darkBg border-2 border-transparent dark:border-knight cursor-grab active:cursor-grabbing rounded-[2rem] flex flex-col justify-between p-5 overflow-hidden z-[1]",
  161. selectedCard[tabSelected]["avatar"] ? "opacity-100" : "opacity-50",
  162. )}
  163. >
  164. <AvatarTransition avatarUrl={avatarUrl} dogUrl={dogUrl} />
  165. <p className="text-sm md:text-medium">
  166. Hey! I&apos;m <span className="font-oleo text-2xl"> Eric</span>, a
  167. SDE at AWS building agentic systems and generative UI. UCLA &amp;
  168. Purdue alum. Passionate about crafting AI experiences that make
  169. life easier. Outside work, I&apos;m hiking with my dog Bert and
  170. planning to summit Mount Rainier in 2027!
  171. </p>
  172. <DockDemo resumeUrl={resumeUrl} />
  173. </div>
  174. <div
  175. key="themeSwitch"
  176. className={cn(
  177. "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]",
  178. selectedCard[tabSelected]["themeSwitch"]
  179. ? "opacity-100"
  180. : "opacity-50",
  181. )}
  182. >
  183. <ThemeSwitch />
  184. </div>
  185. <div
  186. key="cardStack"
  187. className={cn(
  188. "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-[2]",
  189. selectedCard[tabSelected]["cardStack"]
  190. ? "opacity-100"
  191. : "opacity-50",
  192. )}
  193. >
  194. <CardStack photos={photos} />
  195. </div>
  196. <div
  197. key="animatedEmoji"
  198. className={cn(
  199. "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]",
  200. selectedCard[tabSelected]["animatedEmoji"]
  201. ? "opacity-100"
  202. : "opacity-50",
  203. )}
  204. >
  205. <AnimatedEmoji />
  206. </div>
  207. <div
  208. ref={mapIO.ref}
  209. key="mapComponent"
  210. className={cn(
  211. "bg-white dark:bg-darkBg cursor-grab active:cursor-grabbing rounded-[2rem] flex justify-center items-center z-[1]",
  212. selectedCard[tabSelected]["mapComponent"]
  213. ? "opacity-100"
  214. : "opacity-50",
  215. )}
  216. >
  217. {mapIO.inView ? <MapComponent /> : <LoadingPlaceholder />}
  218. </div>
  219. <div
  220. ref={iconCloudIO.ref}
  221. key="iconCloud"
  222. className={cn(
  223. "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]",
  224. selectedCard[tabSelected]["iconCloud"]
  225. ? "opacity-100"
  226. : "opacity-50",
  227. )}
  228. >
  229. {iconCloudIO.inView ? (
  230. <IconCloud iconSlugs={icons} />
  231. ) : (
  232. <LoadingPlaceholder />
  233. )}
  234. </div>
  235. <div
  236. key="webAgent"
  237. className={cn(
  238. "bg-white dark:bg-darkBg dark:border-2 dark:border-knight cursor-grab active:cursor-grabbing rounded-[2rem] flex justify-center items-center overflow-hidden z-[1]",
  239. selectedCard[tabSelected]["webAgent"]
  240. ? "opacity-100"
  241. : "opacity-50",
  242. )}
  243. >
  244. <WebAgent webAgentUrl={webagentUrl} />
  245. </div>
  246. <div
  247. key="chatBot"
  248. className={cn(
  249. "bg-white dark:bg-darkBg dark:border-2 dark:border-knight cursor-grab active:cursor-grabbing rounded-[2rem] flex justify-center items-center overflow-hidden z-[1]",
  250. selectedCard[tabSelected]["chatBot"] ? "opacity-100" : "opacity-50",
  251. )}
  252. >
  253. <Chatbot chatbotUrl={chatbotUrl} />
  254. </div>
  255. <div
  256. ref={miniIO.ref}
  257. key="miniModel"
  258. className={cn(
  259. "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",
  260. selectedCard[tabSelected]["miniModel"]
  261. ? "opacity-100"
  262. : "opacity-50",
  263. )}
  264. >
  265. {show3D && miniIO.inView ? (
  266. <MiniModel />
  267. ) : (
  268. <MiniPic onClick={handleMiniClick} showOverlay={miniIO.inView} />
  269. )}
  270. </div>
  271. <div
  272. key="actions"
  273. className={cn(
  274. "bg-white dark:bg-darkBg dark:border-2 dark:border-knight cursor-grab active:cursor-grabbing rounded-[2rem] flex justify-center items-center overflow-hidden z-[1]",
  275. selectedCard[tabSelected]["actions"] ? "opacity-100" : "opacity-50",
  276. )}
  277. >
  278. <Actions photoUrl={actionImageUrl} />
  279. </div>
  280. <div
  281. key="paper"
  282. className={cn(
  283. "bg-white dark:bg-darkBg dark:border-2 dark:border-knight cursor-grab active:cursor-grabbing rounded-[2rem] flex justify-center items-center z-[1] overflow-hidden",
  284. selectedCard[tabSelected]["paper"] ? "opacity-100" : "opacity-50",
  285. )}
  286. >
  287. <Paper paperUrl={paperUrl} />
  288. </div>
  289. </Responsive>
  290. </div>
  291. );
  292. }