🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Refactor SubHeader and Realtime components for improved layout and responsiveness
Bill Yangff141229201e
diff --git a/client/src/app/[site]/components/SubHeader/SubHeader.tsx b/client/src/app/[site]/components/SubHeader/SubHeader.tsxindex df0b18e9a..92410f19d 100644--- a/client/src/app/[site]/components/SubHeader/SubHeader.tsx+++ b/client/src/app/[site]/components/SubHeader/SubHeader.tsx@@ -17,6 +17,7 @@ import {SheetTrigger,} from "../../../../components/ui/sheet";import { Sidebar } from "../Sidebar/Sidebar";+import { MobileSidebar } from "../../../../components/MobileSidebar";const canGoForward = (time: Time) => {const currentDay = DateTime.now().startOf("day");@@ -53,23 +54,7 @@ export function SubHeader({return (<div className="flex gap-2 mb-3 justify-between"><div className="flex items-center gap-2">- <div className=" md:hidden">- <Sheet>- <SheetTrigger asChild>- <Button size="icon" variant="outline">- <Menu />- </Button>- </SheetTrigger>- <VisuallyHidden.Root>- <SheetHeader>- <SheetTitle>Frogstats Sidebar</SheetTitle>- </SheetHeader>- </VisuallyHidden.Root>- <SheetContent side="left" className="p-0 w-[223px]">- <Sidebar />- </SheetContent>- </Sheet>- </div>+ <MobileSidebar /><Filters availableFilters={availableFilters} /></div><div className="flex items-center gap-2">diff --git a/client/src/app/[site]/realtime/RealtimeChart/RealtimeChart.tsx b/client/src/app/[site]/realtime/RealtimeChart/RealtimeChart.tsxindex f65d8179b..9079d7edf 100644--- a/client/src/app/[site]/realtime/RealtimeChart/RealtimeChart.tsx+++ b/client/src/app/[site]/realtime/RealtimeChart/RealtimeChart.tsx@@ -48,58 +48,56 @@ export function RealtimeChart() {}return (- <div style={{ height: 70 }}>- <ResponsiveBar- data={chartData}- keys={["users"]}- indexBy="time"- margin={{ top: 0, right: 0, bottom: 12, left: 0 }}- padding={0.3}- valueScale={{ type: "linear" }}- indexScale={{ type: "band", round: true }}- colors={["hsl(var(--amber-200))"]}- theme={nivoTheme}- axisTop={null}- axisRight={null}- axisBottom={null}- axisLeft={null}- enableLabel={false}- enableGridX={false}- enableGridY={false}- tooltip={({- id,- value,- data,- }: {- id: string | number;- value: number;- data: { time: string; users: number };- }) => {- const currentTime = DateTime.fromFormat(- data.time,- "yyyy-MM-dd HH:mm:ss",- { zone: "utc" }- ).toLocal();- const currentY = Number(value);+ <ResponsiveBar+ data={chartData}+ keys={["users"]}+ indexBy="time"+ margin={{ top: 0, right: 0, bottom: 12, left: 0 }}+ padding={0.3}+ valueScale={{ type: "linear" }}+ indexScale={{ type: "band", round: true }}+ colors={["hsl(var(--amber-200))"]}+ theme={nivoTheme}+ axisTop={null}+ axisRight={null}+ axisBottom={null}+ axisLeft={null}+ enableLabel={false}+ enableGridX={false}+ enableGridY={false}+ tooltip={({+ id,+ value,+ data,+ }: {+ id: string | number;+ value: number;+ data: { time: string; users: number };+ }) => {+ const currentTime = DateTime.fromFormat(+ data.time,+ "yyyy-MM-dd HH:mm:ss",+ { zone: "utc" }+ ).toLocal();+ const currentY = Number(value);- return (- <div className="bg-neutral-950 p-2 rounded-md text-xs">- <div className="font-semibold mb-1">- {currentTime.isValid- ? currentTime.toFormat("h:mm")- : "Invalid Time"}- </div>- <div className="flex justify-between items-center">- <span className="font-medium">{currentY.toLocaleString()}</span>- <span className="text-muted-foreground ml-1">{id}</span>- </div>+ return (+ <div className="bg-neutral-950 p-2 rounded-md text-xs">+ <div className="font-semibold mb-1">+ {currentTime.isValid+ ? currentTime.toFormat("h:mm")+ : "Invalid Time"}</div>- );- }}- animate={true}- motionConfig="gentle"- borderRadius={2}- />- </div>+ <div className="flex justify-between items-center">+ <span className="font-medium">{currentY.toLocaleString()}</span>+ <span className="text-muted-foreground ml-1">{id}</span>+ </div>+ </div>+ );+ }}+ animate={true}+ motionConfig="gentle"+ borderRadius={2}+ />);}diff --git a/client/src/app/[site]/realtime/RealtimeGlobe/RealtimeGlobe.tsx b/client/src/app/[site]/realtime/RealtimeGlobe/RealtimeGlobe.tsxindex 0cf95e1e2..efbe062b6 100644--- a/client/src/app/[site]/realtime/RealtimeGlobe/RealtimeGlobe.tsx+++ b/client/src/app/[site]/realtime/RealtimeGlobe/RealtimeGlobe.tsx@@ -71,6 +71,8 @@ export const World = ({ width }: { width: number }) => {}));}, [liveSessionLocations]);+ const { width: windowWidth } = useWindowSize();+return (<divonMouseDown={() => {@@ -83,13 +85,20 @@ export const World = ({ width }: { width: number }) => {onGlobeReady={() => {if (globeEl.current) {// Set initial view: lat, lng, and altitude (zoom)- globeEl.current.pointOfView({ lat: 20, lng: -36, altitude: 2 });+ globeEl.current.pointOfView({+ lat: 20,+ lng: -36,+ altitude: windowWidth && windowWidth > 768 ? 2 : 3,+ });}}}ref={globeEl as any}width={width ?? 0}height={(size.height ?? 0) - 50}- globeOffset={[-100, 0]}+ globeOffset={[+ windowWidth && windowWidth > 768 ? -100 : 0,+ windowWidth && windowWidth > 768 ? 0 : 100,+ ]}atmosphereColor="rgba(170, 170, 200, 1)"globeMaterial={oceanBlueMaterial}hexPolygonsData={countries.features}diff --git a/client/src/app/[site]/realtime/page.tsx b/client/src/app/[site]/realtime/page.tsxindex d0ba384d4..35bd446fe 100644--- a/client/src/app/[site]/realtime/page.tsx+++ b/client/src/app/[site]/realtime/page.tsx@@ -19,6 +19,7 @@ import {import { useAtom } from "jotai";import { minutesAtom, MinutesType } from "./realtimeStore";import NumberFlow from "@number-flow/react";+import { MobileSidebar } from "../../../components/MobileSidebar";export default function RealtimePage() {const [ref, { width }] = useMeasure();@@ -35,8 +36,9 @@ export default function RealtimePage() {><World width={width ?? 0} />- <div className="absolute top-4 left-4 ">- <div className="flex flex-col p-3 bg-neutral-900 rounded-lg shadow-lg border border-neutral-750 w-[400px]">+ <div className="absolute top-2 left-2 md:top-4 md:left-4 flex flex-row gap-2">+ <MobileSidebar />+ <div className="flex flex-col p-2 md:p-3 bg-neutral-900 rounded-lg shadow-lg border border-neutral-750 w-[300px] md:w-[400px]"><div className="p-2"><div className="text-sm text-gray-400 flex gap-2 text-nowrap items-center"><div className="flex justify-center">@@ -66,7 +68,7 @@ export default function RealtimePage() {</SelectContent></Select></div>- <div className="text-5xl font-bold flex items-center gap-2">+ <div className="text-3xl md:text-5xl font-bold flex items-center gap-2">{<NumberFlowrespectMotionPreference={false}@@ -75,11 +77,13 @@ export default function RealtimePage() {}</div></div>- <RealtimeChart />+ <div className="h-[50px] md:h-[70px]">+ <RealtimeChart />+ </div></div></div>- <div className="absolute top-4 right-4 w-[320px]">+ <div className="hidden md:block absolute top-4 right-4 w-[320px]"><RealtimeEvents /></div>diff --git a/client/src/components/MobileSidebar.tsx b/client/src/components/MobileSidebar.tsxnew file mode 100644index 000000000..f38c19266--- /dev/null+++ b/client/src/components/MobileSidebar.tsx@@ -0,0 +1,36 @@+"use client";++import { Sidebar } from "../app/[site]/components/Sidebar/Sidebar";+import { Button } from "./ui/button";+import {+ Sheet,+ SheetContent,+ SheetHeader,+ SheetTitle,+ SheetTrigger,+} from "./ui/sheet";++import { Menu } from "lucide-react";+import { VisuallyHidden } from "radix-ui";++export function MobileSidebar() {+ return (+ <div className="md:hidden">+ <Sheet>+ <SheetTrigger asChild>+ <Button size="icon" variant="outline">+ <Menu />+ </Button>+ </SheetTrigger>+ <VisuallyHidden.Root>+ <SheetHeader>+ <SheetTitle>Frogstats Sidebar</SheetTitle>+ </SheetHeader>+ </VisuallyHidden.Root>+ <SheetContent side="left" className="p-0 w-[223px]">+ <Sidebar />+ </SheetContent>+ </Sheet>+ </div>+ );+}