🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Refactor RealtimeEvents and RealtimeGlobe components for improved readability and consistency
Bill Yangc37fe50aaa5f
diff --git a/client/src/app/[site]/realtime/RealtimeEvents/RealtimeEvents.tsx b/client/src/app/[site]/realtime/RealtimeEvents/RealtimeEvents.tsxindex c94c2413d..f3cc3f82f 100644--- a/client/src/app/[site]/realtime/RealtimeEvents/RealtimeEvents.tsx+++ b/client/src/app/[site]/realtime/RealtimeEvents/RealtimeEvents.tsx@@ -1,15 +1,8 @@-import {- Tooltip,- TooltipContent,- TooltipTrigger,-} from "@/components/ui/tooltip";+import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";import { FileText, Laptop, MousePointerClick, Smartphone } from "lucide-react";import { DateTime } from "luxon";import Link from "next/link";-import {- Event,- useGetEvents,-} from "../../../../api/analytics/events/useGetEvents";+import { Event, useGetEvents } from "../../../../api/analytics/events/useGetEvents";import { Skeleton } from "../../../../components/ui/skeleton";import { cn, getCountryName } from "../../../../lib/utils";import { Browser } from "../../components/shared/icons/Browser";@@ -45,16 +38,10 @@ function EventCard({ event }: { event: Event }) {// Determine if it's a pageview or custom eventconst isPageview = event.type === "pageview";- const fullPath = `https://${event.hostname}${event.pathname}${- event.querystring ? `${event.querystring}` : ""- }`;+ const fullPath = `https://${event.hostname}${event.pathname}${event.querystring ? `${event.querystring}` : ""}`;return (- <Link- href={`user/${event.user_id}`}- target="_blank"- rel="noopener noreferrer"- >+ <Link href={`user/${event.user_id}`} target="_blank" rel="noopener noreferrer"><div className="mb-3 rounded-lg bg-neutral-850/50 border border-neutral-800 overflow-hidden p-3 flex flex-col filter backdrop-blur-sm hover:bg-neutral-800/70 transition-all duration-200"><div className="flex items-center gap-2 text-sm text-neutral-100 mb-2"><div className="flex items-center gap-2">@@ -75,11 +62,7 @@ function EventCard({ event }: { event: Event }) {maxWidth: "calc(min(100vw, 1150px) - 250px)",}}>- {truncatePath(- `${event.pathname}${- event.querystring ? `${event.querystring}` : ""- }`- )}+ {truncatePath(`${event.pathname}${event.querystring ? `${event.querystring}` : ""}`)}</div></Link></div>@@ -173,18 +156,11 @@ export function RealtimeEvents() {}if (!data || data.length === 0) {- return (- <div className="text-sm text-gray-400 p-4 text-center">- No events recorded yet- </div>- );+ return <div className="text-sm text-gray-400 p-4 text-center">No events recorded yet</div>;}return (- <div- className="overflow-y-auto p-2"- style={{ height: "calc(100vh - 100px)" }}- >+ <div className="overflow-y-auto p-2" style={{ height: "100vh" }}>{data.map((event: Event, index: number) => (<EventCard key={`${event.timestamp}-${index}`} event={event} />))}@@ -231,10 +207,7 @@ function EventCardSkeleton() {));return (- <div- className="overflow-y-auto p-2"- style={{ height: "calc(100vh - 100px)" }}- >+ <div className="overflow-y-auto p-2" style={{ height: "100vh" }}>{skeletons}</div>);diff --git a/client/src/app/[site]/realtime/RealtimeGlobe/RealtimeGlobe.tsx b/client/src/app/[site]/realtime/RealtimeGlobe/RealtimeGlobe.tsxindex fa4a0c5c8..e9f4a1106 100644--- a/client/src/app/[site]/realtime/RealtimeGlobe/RealtimeGlobe.tsx+++ b/client/src/app/[site]/realtime/RealtimeGlobe/RealtimeGlobe.tsx@@ -22,10 +22,9 @@ export const World = ({ width }: { width: number }) => {const [minutes] = useAtom(minutesAtom);- const {- data: liveSessionLocations,- isLoading: isLiveSessionLocationsLoading,- } = useGetLiveSessionLocations(Number(minutes));+ const { data: liveSessionLocations, isLoading: isLiveSessionLocationsLoading } = useGetLiveSessionLocations(+ Number(minutes)+ );const { data: countries = { features: [] } } = useQuery({queryKey: ["countries"],@@ -35,15 +34,10 @@ export const World = ({ width }: { width: number }) => {},});- const highest =- liveSessionLocations?.reduce((acc, curr) => Math.max(acc, curr.count), 0) ??- 1;+ const highest = liveSessionLocations?.reduce((acc, curr) => Math.max(acc, curr.count), 0) ?? 1;const normalized = 5 / Number(minutes);- const weightColor = scaleSequentialSqrt(interpolateYlOrRd).domain([- 0,- highest * normalized * 15,- ]);+ const weightColor = scaleSequentialSqrt(interpolateYlOrRd).domain([0, highest * normalized * 15]);useEffect(() => {// Auto-rotate@@ -59,17 +53,17 @@ export const World = ({ width }: { width: number }) => {const updateAltitude = useCallback(debounce(() => {if (!globeEl.current) return;-+const controls = globeEl.current.controls();const distance = Math.round(controls.getDistance());-- const low = 0.001, mid = 0.005, high = 0.02;- const near = 300, far = 600;- const nextAlt =- distance <= near ? low :- distance >= far ? high :- mid;-++ const low = 0.001,+ mid = 0.005,+ high = 0.02;+ const near = 300,+ far = 600;+ const nextAlt = distance <= near ? low : distance >= far ? high : mid;+// set only if changedif (nextAlt !== hexAltitude) {setHexAltitude(nextAlt);@@ -84,9 +78,9 @@ export const World = ({ width }: { width: number }) => {// Limit distance maximal distancecontrols.maxDistance = 900;// Subscribe on change event- controls.addEventListener('end', updateAltitude);+ controls.addEventListener("end", updateAltitude);return () => {- controls.removeEventListener('end', updateAltitude);+ controls.removeEventListener("end", updateAltitude);updateAltitude.cancel(); // cancel any pending call};}, [globeEl, updateAltitude]);@@ -132,11 +126,8 @@ export const World = ({ width }: { width: number }) => {}}ref={globeEl as any}width={width ?? 0}- height={(size.height ?? 0) - 100}- globeOffset={[- windowWidth && windowWidth > 768 ? -100 : 0,- windowWidth && windowWidth > 768 ? 0 : 100,- ]}+ height={size.height ?? 0}+ globeOffset={[windowWidth && windowWidth > 768 ? -100 : 0, windowWidth && windowWidth > 768 ? 0 : 100]}atmosphereColor="rgba(170, 170, 200, 1)"globeMaterial={oceanBlueMaterial}hexPolygonsData={countries.features}