diff --git a/apps/dashboard/src/app/(app)/[organizationSlug]/[projectId]/realtime/map/map.tsx b/apps/dashboard/src/app/(app)/[organizationSlug]/[projectId]/realtime/map/map.tsx index 2d724d63..1a9a7af1 100644 --- a/apps/dashboard/src/app/(app)/[organizationSlug]/[projectId]/realtime/map/map.tsx +++ b/apps/dashboard/src/app/(app)/[organizationSlug]/[projectId]/realtime/map/map.tsx @@ -1,8 +1,9 @@ 'use client'; -import React, { Fragment, useEffect, useRef, useState } from 'react'; -import { Button } from '@/components/ui/button'; +import { Fragment, useEffect, useRef, useState } from 'react'; +import { useFullscreen } from '@/components/fullscreen-toggle'; import { Tooltiper } from '@/components/ui/tooltip'; +import { cn } from '@/utils/cn'; import { bind } from 'bind-event-listener'; import { ComposableMap, @@ -25,12 +26,13 @@ import { getBoundingBox, useAnimatedState, } from './map.helpers'; -import useActiveMarkers, { calculateMarkerSize } from './markers'; +import { calculateMarkerSize } from './markers'; type Props = { markers: Coordinate[]; }; const Map = ({ markers }: Props) => { + const [isFullscreen] = useFullscreen(); const showCenterMarker = false; const ref = useRef(null); const [size, setSize] = useState<{ width: number; height: number } | null>( @@ -54,31 +56,33 @@ const Map = ({ markers }: Props) => { const [lat] = useAnimatedState(center.lat); useEffect(() => { - if (ref.current) { - setSize({ - width: ref.current.clientWidth, - height: ref.current.clientHeight, - }); - } - }, []); + requestAnimationFrame(() => { + if (ref.current) { + setSize({ + width: ref.current.clientWidth, + height: ref.current.clientHeight, + }); + } + }); + }, [isFullscreen]); - // useEffect(() => { - // return bind(window, { - // type: 'resize', - // listener() { - // if (ref.current) { - // setSize({ - // width: ref.current.clientWidth, - // height: ref.current.clientHeight, - // }); - // } - // }, - // }); - // }, []); + useEffect(() => { + return bind(window, { + type: 'resize', + listener() { + if (ref.current) { + setSize({ + width: ref.current.clientWidth, + height: ref.current.clientHeight, + }); + } + }, + }); + }, []); const adjustSizeBasedOnZoom = (size: number) => { const minMultiplier = 1; - const maxMultiplier = 3; + const maxMultiplier = 7; // Linearly interpolate the multiplier based on the zoom level const multiplier = @@ -88,7 +92,13 @@ const Map = ({ markers }: Props) => { }; return ( -
+
{size === null ? ( <> ) : ( @@ -102,7 +112,7 @@ const Map = ({ markers }: Props) => { scale: 100 * 20, }} > - + {({ geographies }) => geographies.map((geo) => ( diff --git a/apps/dashboard/src/app/(app)/[organizationSlug]/[projectId]/realtime/page.tsx b/apps/dashboard/src/app/(app)/[organizationSlug]/[projectId]/realtime/page.tsx index 27b50165..aab89132 100644 --- a/apps/dashboard/src/app/(app)/[organizationSlug]/[projectId]/realtime/page.tsx +++ b/apps/dashboard/src/app/(app)/[organizationSlug]/[projectId]/realtime/page.tsx @@ -1,4 +1,5 @@ import { Suspense } from 'react'; +import { Fullscreen, FullscreenToggle } from '@/components/fullscreen-toggle'; import { LazyChart } from '@/components/report/chart/LazyChart'; import PageLayout from '../page-layout'; @@ -17,22 +18,25 @@ export default function Page({ params: { projectId, organizationSlug }, }: Props) { return ( -
- - - - - -
-
+ <> + } + {...{ projectId, organizationSlug }} + /> + + + + + +
-
+
-
+
Pages
@@ -130,7 +134,7 @@ export default function Page({ />
-
-
+ + ); } diff --git a/apps/dashboard/src/components/fullscreen-toggle.tsx b/apps/dashboard/src/components/fullscreen-toggle.tsx new file mode 100644 index 00000000..884cf86e --- /dev/null +++ b/apps/dashboard/src/components/fullscreen-toggle.tsx @@ -0,0 +1,51 @@ +'use client'; + +import { cn } from '@/utils/cn'; +import { FullscreenIcon } from 'lucide-react'; +import { parseAsBoolean, useQueryState } from 'nuqs'; + +import { Tooltiper } from './ui/tooltip'; + +type Props = { + children: React.ReactNode; + className?: string; +}; + +export const useFullscreen = () => + useQueryState( + 'fullscreen', + parseAsBoolean.withDefault(false).withOptions({ + history: 'push', + clearOnDefault: true, + }) + ); + +export const Fullscreen = (props: Props) => { + const [isFullscreen] = useFullscreen(); + return ( +
+ {props.children} +
+ ); +}; + +export const FullscreenToggle = () => { + const [, setIsFullscreen] = useFullscreen(); + return ( + + + + ); +};