Skip to content

Commit 1ed85ed

Browse files
committed
move particlemap to hero; lazy load it
1 parent e4c8892 commit 1ed85ed

4 files changed

Lines changed: 62 additions & 31 deletions

File tree

apps/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "frontend",
3-
"version": "0.1.10",
3+
"version": "0.1.11",
44
"private": true,
55
"type": "module",
66
"scripts": {

apps/frontend/src/components/homepage/landing-hero.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { ArrowUpRightIcon } from "@phosphor-icons/react";
22
import { Link } from "@tanstack/react-router";
33
import { motion } from "motion/react";
4-
import { useId } from "react";
4+
import { Suspense, lazy, useId } from "react";
55

66
import { buttonVariants } from "@/components/ui/button";
7+
import { Skeleton } from "@/components/ui/skeleton";
8+
9+
const ParticlesMap = lazy(() => import("@/components/homepage/particles-map"));
710

811
export function LandingHero() {
912
const patternId = useId();
@@ -89,6 +92,23 @@ export function LandingHero() {
8992
</Link>
9093
</motion.div>
9194
</motion.div>
95+
96+
<div className="relative hidden min-h-[360px] overflow-visible pt-14 lg:block">
97+
<div className="absolute inset-0">
98+
<Suspense
99+
fallback={
100+
<div className="flex h-full items-center justify-center px-6 py-2">
101+
<Skeleton className="aspect-square w-full max-w-[520px] rounded-3xl" />
102+
</div>
103+
}>
104+
<ParticlesMap
105+
interactive
106+
className="h-full items-end justify-end p-0 pt-10"
107+
canvasClassName="h-auto w-full max-w-[520px] opacity-65 lg:translate-y-8 xl:translate-y-16 [mask-image:radial-gradient(circle_at_45%_50%,black_45%,transparent_82%)]"
108+
/>
109+
</Suspense>
110+
</div>
111+
</div>
92112
</div>
93113
</section>
94114
);

apps/frontend/src/components/homepage/particles-map.tsx

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { memo, useCallback, useEffect, useRef } from "react";
22

33
import mapData from "@/data/costa_rica.json";
4+
import { cn } from "@/lib/utils";
45

56
import type React from "react";
67

@@ -16,7 +17,13 @@ interface ParticleOrigin {
1617
y: number;
1718
}
1819

19-
function ParticlesMap() {
20+
interface ParticlesMapProps {
21+
className?: string;
22+
canvasClassName?: string;
23+
interactive?: boolean;
24+
}
25+
26+
function ParticlesMap({ className, canvasClassName, interactive = true }: ParticlesMapProps) {
2027
const canvasRef = useRef<HTMLCanvasElement>(null);
2128
const animationRef = useRef<number | undefined>(undefined);
2229
const mouseRef = useRef({ x: -1000, y: -1000 });
@@ -220,23 +227,39 @@ function ParticlesMap() {
220227
};
221228

222229
return (
223-
<div className="flex w-full items-center justify-center p-8">
230+
<div className={cn("flex w-full items-center justify-center p-8", className)}>
224231
<canvas
225232
ref={canvasRef}
226-
onMouseMove={handleMouseMove}
227-
onMouseDown={() => {
228-
isMouseDownRef.current = true;
229-
}}
230-
onMouseUp={() => {
231-
isMouseDownRef.current = false;
232-
}}
233-
onMouseLeave={() => {
234-
isMouseDownRef.current = false;
235-
}}
236-
onTouchStart={handleTouchStart}
237-
onTouchMove={handleTouchMove}
238-
onTouchEnd={handleTouchEnd}
239-
className="w-full max-w-[600px]"
233+
onMouseMove={interactive ? handleMouseMove : undefined}
234+
onMouseDown={
235+
interactive
236+
? () => {
237+
isMouseDownRef.current = true;
238+
}
239+
: undefined
240+
}
241+
onMouseUp={
242+
interactive
243+
? () => {
244+
isMouseDownRef.current = false;
245+
}
246+
: undefined
247+
}
248+
onMouseLeave={
249+
interactive
250+
? () => {
251+
isMouseDownRef.current = false;
252+
}
253+
: undefined
254+
}
255+
onTouchStart={interactive ? handleTouchStart : undefined}
256+
onTouchMove={interactive ? handleTouchMove : undefined}
257+
onTouchEnd={interactive ? handleTouchEnd : undefined}
258+
className={cn(
259+
"w-full max-w-[600px]",
260+
!interactive && "pointer-events-none",
261+
canvasClassName
262+
)}
240263
style={{ aspectRatio: "600/600", touchAction: "none" }}
241264
/>
242265
</div>

apps/frontend/src/routes/_dashboard/index.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { createFileRoute } from "@tanstack/react-router";
2-
import { Suspense, lazy } from "react";
32
import { z } from "zod";
43

54
import { AnnualRecapSection } from "@/components/homepage/annual-recap-section";
@@ -8,11 +7,8 @@ import { HighlightedIncidents } from "@/components/homepage/highlighted-incident
87
import { IncidentTypesChart } from "@/components/homepage/incident-types-chart";
98
import { LandingHero } from "@/components/homepage/landing-hero";
109
import { LatestIncidents } from "@/components/homepage/latest-incidents";
11-
// import { MapCTA } from "@/components/homepage/map-cta";
1210
import { Separator } from "@/components/homepage/separator";
13-
import { Skeleton } from "@/components/ui/skeleton";
14-
15-
const ParticlesMap = lazy(() => import("@/components/homepage/particles-map"));
11+
// import { MapCTA } from "@/components/homepage/map-cta";
1612

1713
const title = "Emergencias CR - Incidentes de Bomberos en Tiempo Real";
1814
const description =
@@ -66,14 +62,6 @@ function HomePage() {
6662
{/* <MapCTA /> */}
6763
<Separator />
6864
<IncidentTypesChart />
69-
<Suspense
70-
fallback={
71-
<div className="flex w-full items-center justify-center p-8">
72-
<Skeleton className="aspect-square w-full max-w-[600px]" />
73-
</div>
74-
}>
75-
<ParticlesMap />
76-
</Suspense>
7765
</div>
7866
);
7967
}

0 commit comments

Comments
 (0)