Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Refactor RealtimeChart layout and enhance styling

Bill Yang344c11bf3646
diff --git a/client/src/app/[site]/realtime/RealtimeChart/RealtimeChart.tsx b/client/src/app/[site]/realtime/RealtimeChart/RealtimeChart.tsx
index a2bbd305c..4a11ed29a 100644
--- a/client/src/app/[site]/realtime/RealtimeChart/RealtimeChart.tsx
+++ b/client/src/app/[site]/realtime/RealtimeChart/RealtimeChart.tsx
@@ -5,6 +5,12 @@ import { DateTime } from "luxon";
import { ResponsiveBar } from "@nivo/bar";
import { formatter } from "../../../../lib/utils";
import { nivoTheme } from "../../../../lib/nivo";
+import {
+ Card,
+ CardContent,
+ CardTitle,
+ CardHeader,
+} from "../../../../components/ui/card";
export function RealtimeChart() {
const { site } = useStore();
@@ -49,79 +55,88 @@ export function RealtimeChart() {
}
return (
- <div style={{ height: 300 }}>
- <ResponsiveBar
- data={chartData}
- keys={["users"]}
- indexBy="time"
- margin={{ top: 10, right: 10, bottom: 40, left: 35 }}
- padding={0.3}
- valueScale={{ type: "linear" }}
- indexScale={{ type: "band", round: true }}
- // colors={["hsla(210, 40%, 50%, 0.7)"]}
- colors={["hsl(var(--accent-500))"]}
- theme={nivoTheme}
- axisTop={null}
- axisRight={null}
- axisBottom={{
- tickSize: 5,
- tickPadding: 5,
- legend: "",
- legendPosition: "middle",
- legendOffset: 32,
- format: (value: string) => {
- const dt = DateTime.fromFormat(value, "yyyy-MM-dd HH:mm:ss", {
- zone: "utc",
- }).toLocal();
- return dt.isValid ? dt.toFormat("h:mm") : "";
- },
- }}
- axisLeft={{
- tickSize: 5,
- tickPadding: 5,
- tickRotation: 0,
- legend: "",
- legendPosition: "middle",
- legendOffset: -30,
- format: formatter,
- tickValues: 3,
- }}
- enableLabel={false}
- enableGridX={false}
- enableGridY={true}
- 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);
+ <Card>
+ <CardHeader>
+ <CardTitle>Realtime - Last 30 minutes</CardTitle>
+ </CardHeader>
+ <CardContent>
+ <div style={{ height: 300 }}>
+ <ResponsiveBar
+ data={chartData}
+ keys={["users"]}
+ indexBy="time"
+ margin={{ top: 20, right: 0, bottom: 30, left: 35 }}
+ padding={0.3}
+ valueScale={{ type: "linear" }}
+ indexScale={{ type: "band", round: true }}
+ // colors={["hsla(210, 40%, 50%, 0.7)"]}
+ colors={["hsl(var(--accent-500))"]}
+ theme={nivoTheme}
+ axisTop={null}
+ axisRight={null}
+ axisBottom={{
+ tickSize: 5,
+ tickPadding: 5,
+ legend: "",
+ legendPosition: "middle",
+ legendOffset: 32,
+ format: (value: string) => {
+ const dt = DateTime.fromFormat(value, "yyyy-MM-dd HH:mm:ss", {
+ zone: "utc",
+ }).toLocal();
+ return dt.isValid ? dt.toFormat("h:mm") : "";
+ },
+ }}
+ axisLeft={{
+ tickSize: 5,
+ tickPadding: 5,
+ tickRotation: 0,
+ legend: "",
+ legendPosition: "middle",
+ legendOffset: -30,
+ format: formatter,
+ tickValues: 3,
+ }}
+ enableLabel={false}
+ enableGridX={false}
+ enableGridY={true}
+ 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("HH: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>
- </div>
- );
- }}
- animate={true}
- motionConfig="gentle"
- />
- </div>
+ return (
+ <div className="bg-neutral-950 p-2 rounded-md text-xs">
+ <div className="font-semibold mb-1">
+ {currentTime.isValid
+ ? currentTime.toFormat("HH: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>
+ </div>
+ );
+ }}
+ animate={true}
+ motionConfig="gentle"
+ />
+ </div>
+ </CardContent>
+ </Card>
);
}
diff --git a/client/src/app/[site]/realtime/RealtimeMap/RealtimeMap.tsx b/client/src/app/[site]/realtime/RealtimeMap/RealtimeMap.tsx
index 4db078cbf..952db9bc4 100644
--- a/client/src/app/[site]/realtime/RealtimeMap/RealtimeMap.tsx
+++ b/client/src/app/[site]/realtime/RealtimeMap/RealtimeMap.tsx
@@ -91,7 +91,7 @@ export function RealtimeMap() {
return (
<div>
<div
- className="w-full h-[600px] rounded-lg overflow-hidden border border-neutral-800"
+ className="w-full h-[600px] rounded-lg overflow-hidden border border-neutral-850"
onMouseMove={(e) => {
if (tooltipContent) {
setTooltipPosition({
diff --git a/client/src/components/TopBar.tsx b/client/src/components/TopBar.tsx
index 72affad41..4820e4709 100644
--- a/client/src/components/TopBar.tsx
+++ b/client/src/components/TopBar.tsx
@@ -1,6 +1,7 @@
"use client";
import { User } from "@phosphor-icons/react";
+import { useQueryClient } from "@tanstack/react-query";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { authClient } from "../lib/auth";
@@ -10,13 +11,6 @@ import {
DropdownMenuItem,
DropdownMenuTrigger,
} from "./ui/dropdown-menu";
-import {
- NavigationMenu,
- NavigationMenuItem,
- NavigationMenuLink,
- NavigationMenuList,
-} from "./ui/navigation-menu";
-import { useQueryClient } from "@tanstack/react-query";
export function TopBar() {
const session = authClient.useSession();
@@ -24,37 +18,13 @@ export function TopBar() {
const queryClient = useQueryClient();
return (
- <div className="flex pt-2 pb-4 px-3 items-center w-full bg-neutral-900 justify-center">
+ <div className="flex pt-2 pb-2 px-3 items-center w-full bg-neutral-900 justify-center">
<div className="flex items-center justify-between flex-1">
<div className="flex items-center space-x-4">
- <Link href="/" className="font-bold text-xl">
+ <Link href="/" className="font-bold text-lg">
🐸 Frogstats
</Link>
</div>
- <NavigationMenu>
- <NavigationMenuList>
- <NavigationMenuItem>
- <Link href="/" legacyBehavior passHref>
- <NavigationMenuLink className="text-neutral-100 flex items-center gap-1 text-sm font-medium">
- Websites
- </NavigationMenuLink>
- </Link>
- </NavigationMenuItem>
- </NavigationMenuList>
- </NavigationMenu>
- {/* <nav className="ml-auto flex items-center space-x-6 text-sm">
- <Link href="/" className="text-neutral-100">
- Websites
- </Link>
- <Link
- href="/settings"
- className="text-neutral-100 flex items-center gap-1"
- >
- <GearSix size={18} weight="bold" />
- Settings
- </Link>
- <ThemeToggle />
- </nav> */}
<DropdownMenu>
<DropdownMenuTrigger className="flex items-center gap-1 text-sm font-medium">
<User size={16} weight="bold" />
diff --git a/client/src/components/ui/card.tsx b/client/src/components/ui/card.tsx
index 52f655bb3..de8378a36 100644
--- a/client/src/components/ui/card.tsx
+++ b/client/src/components/ui/card.tsx
@@ -11,7 +11,7 @@ const Card = React.forwardRef<
<div
ref={ref}
className={cn(
- "relative rounded-xl border border-neutral-200 bg-white text-neutral-950 dark:border-neutral-850 dark:bg-neutral-900 dark:text-neutral-50 overflow-hidden transition-all duration-300 animate-in fade-in-0 zoom-in-95",
+ "relative rounded-lg border border-neutral-200 bg-white text-neutral-950 dark:border-neutral-850 dark:bg-neutral-900 dark:text-neutral-50 overflow-hidden transition-all duration-300 animate-in fade-in-0 zoom-in-95",
className
)}
{...props}