Skip to content

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

Add more tabs to analytics page

Bill Yang07280c40dbb1
diff --git a/client/src/app/[site]/components/Header/Header.tsx b/client/src/app/[site]/components/Header/Header.tsx
index 103c5ed38..5e171886a 100644
--- a/client/src/app/[site]/components/Header/Header.tsx
+++ b/client/src/app/[site]/components/Header/Header.tsx
@@ -1,36 +1,10 @@
"use client";
import { Circle } from "@phosphor-icons/react";
-
-import { Time, useStore } from "@/lib/store";
-import { DateTime } from "luxon";
+import Link from "next/link";
+import { useStore } from "@/lib/store";
import { usePathname } from "next/navigation";
import { useGetLiveUsercount, useGetSites } from "../../../../hooks/api";
-const canGoForward = (time: Time) => {
- const currentDay = DateTime.now().startOf("day");
- if (time.mode === "day") {
- return !(DateTime.fromISO(time.day).startOf("day") >= currentDay);
- }
-
- if (time.mode === "range") {
- return !(DateTime.fromISO(time.endDate).startOf("day") >= currentDay);
- }
-
- if (time.mode === "week") {
- return !(DateTime.fromISO(time.week).startOf("week") >= currentDay);
- }
-
- if (time.mode === "month") {
- return !(DateTime.fromISO(time.month).startOf("month") >= currentDay);
- }
-
- if (time.mode === "year") {
- return !(DateTime.fromISO(time.year).startOf("year") >= currentDay);
- }
-
- return false;
-};
-
export function Header() {
const { data } = useGetLiveUsercount();
const { time } = useStore();
@@ -38,9 +12,21 @@ export function Header() {
const pathname = usePathname();
const site = sites?.data?.find(
- (site) => site.site_id === Number(pathname.slice(1))
+ (site) => site.site_id === Number(pathname.split("/")[1])
);
+ // Check which tab is active based on the current path
+ const getTabPath = (tabName: string) => {
+ return `/${pathname.split("/")[1]}/${tabName.toLowerCase()}`;
+ };
+
+ const isActiveTab = (tabName: string) => {
+ if (!pathname.includes("/")) return false;
+
+ const route = pathname.split("/")[2] || "main";
+ return route === tabName.toLowerCase();
+ };
+
return (
<div className="flex items-center justify-between py-2">
<div className="flex gap-3">
@@ -56,6 +42,53 @@ export function Header() {
{data?.count} users online
</div>
</div>
+ <div className="flex space-x-2">
+ <TabButton
+ label="Main"
+ active={isActiveTab("main")}
+ href={getTabPath("main")}
+ />
+ <TabButton
+ label="Sessions"
+ active={isActiveTab("sessions")}
+ href={getTabPath("sessions")}
+ />
+ <TabButton
+ label="Realtime"
+ active={isActiveTab("realtime")}
+ href={getTabPath("realtime")}
+ />
+ <TabButton
+ label="Reports"
+ active={isActiveTab("reports")}
+ href={getTabPath("reports")}
+ />
+ </div>
</div>
);
}
+
+// Tab Button component with navigation
+function TabButton({
+ label,
+ active = false,
+ href,
+}: {
+ label: string;
+ active?: boolean;
+ href: string;
+}) {
+ return (
+ <Link href={href} className="focus:outline-none">
+ <button
+ className={`px-4 py-2 rounded-lg font-medium transition-colors ${
+ active
+ ? "bg-neutral-800 text-white"
+ : "text-neutral-400 hover:text-white hover:bg-neutral-800/50"
+ }`}
+ >
+ {label}
+ </button>
+ </Link>
+ );
+}
diff --git a/client/src/app/[site]/layout.tsx b/client/src/app/[site]/layout.tsx
new file mode 100644
index 000000000..8a8f5e3d1
--- /dev/null
+++ b/client/src/app/[site]/layout.tsx
@@ -0,0 +1,31 @@
+"use client";
+import { usePathname } from "next/navigation";
+import { useEffect } from "react";
+import { useStore } from "../../lib/store";
+import { Header } from "./components/Header/Header";
+
+export default function SiteLayout({
+ children,
+}: {
+ children: React.ReactNode;
+}) {
+ const pathname = usePathname();
+ const { setSite, site } = useStore();
+
+ useEffect(() => {
+ if (pathname.includes("/")) {
+ setSite(pathname.split("/")[1]);
+ }
+ }, [pathname]);
+
+ if (!site) {
+ return null;
+ }
+
+ return (
+ <>
+ <Header />
+ {children}
+ </>
+ );
+}
diff --git a/client/src/app/[site]/main/page.tsx b/client/src/app/[site]/main/page.tsx
new file mode 100644
index 000000000..80db32387
--- /dev/null
+++ b/client/src/app/[site]/main/page.tsx
@@ -0,0 +1,57 @@
+"use client";
+import { usePathname } from "next/navigation";
+import { useGetSites, useSiteHasData } from "../../../hooks/api";
+import { useStore } from "../../../lib/store";
+import { MainSection } from "../components/MainSection/MainSection";
+import { NoData } from "../components/NoData";
+import { Browsers } from "../components/sections/Browsers/Browsers";
+import { Countries } from "../components/sections/Countries/Countries";
+import { Devices } from "../components/sections/Devices/Devices";
+import { Map } from "../components/sections/Map/Map";
+import { OperatingSystems } from "../components/sections/OperatingSystems/OperatingSystems";
+import { Pages } from "../components/sections/Pages/Pages";
+import { Referrers } from "../components/sections/Referrers/Referrers";
+import { SubHeader } from "../components/SubHeader/SubHeader";
+import { useGetSiteMetadata } from "../../../hooks/hooks";
+
+export default function MainPage() {
+ const { site } = useStore();
+
+ if (!site) {
+ return null;
+ }
+
+ return <MainPageContent site={site} />;
+}
+
+function MainPageContent({ site }: { site: string }) {
+ const { data: siteHasData, isLoading } = useSiteHasData(site);
+
+ const { siteMetadata, isLoading: isLoadingSiteMetadata } =
+ useGetSiteMetadata(site);
+
+ if (isLoadingSiteMetadata || isLoading || !siteMetadata) {
+ return null;
+ }
+
+ if (!siteHasData?.data && !isLoading && !isLoadingSiteMetadata) {
+ return <NoData siteMetadata={siteMetadata} />;
+ }
+
+ return (
+ <>
+ <SubHeader />
+ <MainSection />
+ <div className="grid grid-cols-2 gap-4 mt-4">
+ <OperatingSystems />
+ <Browsers />
+ <Devices />
+ <Pages siteMetadata={siteMetadata} />
+ <Referrers />
+ <Countries />
+ <Map />
+ {/* <Chloropleth /> */}
+ </div>
+ </>
+ );
+}
diff --git a/client/src/app/[site]/page.tsx b/client/src/app/[site]/page.tsx
index 4f73422ab..793c817f5 100644
--- a/client/src/app/[site]/page.tsx
+++ b/client/src/app/[site]/page.tsx
@@ -1,67 +1,17 @@
"use client";
-import { usePathname } from "next/navigation";
import { useEffect } from "react";
-import { useGetSites, useSiteHasData } from "../../hooks/api";
-import { useStore } from "../../lib/store";
-import { Header } from "./components/Header/Header";
-import { MainSection } from "./components/MainSection/MainSection";
-import { NoData } from "./components/NoData";
-import { Browsers } from "./components/sections/Browsers/Browsers";
-import { Countries } from "./components/sections/Countries/Countries";
-import { Devices } from "./components/sections/Devices/Devices";
-import { Map } from "./components/sections/Map/Map";
-import { OperatingSystems } from "./components/sections/OperatingSystems/OperatingSystems";
-import { Pages } from "./components/sections/Pages/Pages";
-import { Referrers } from "./components/sections/Referrers/Referrers";
-import { SubHeader } from "./components/SubHeader/SubHeader";
-import { useGetSiteMetadata } from "../../hooks/hooks";
+import { useRouter, useParams } from "next/navigation";
-export default function SitePage() {
- const pathname = usePathname();
- const { setSite, site } = useStore();
+export default function SiteRedirect() {
+ const router = useRouter();
+ const params = useParams();
+ const siteId = params.site;
useEffect(() => {
- if (pathname.includes("/")) {
- setSite(pathname.split("/")[1]);
+ if (siteId) {
+ router.replace(`/${siteId}/main`);
}
- }, [pathname]);
+ }, [siteId, router]);
- if (!site) {
- return null;
- }
-
- return <SitePageInner site={site} />;
-}
-
-function SitePageInner({ site }: { site: string }) {
- const { data: siteHasData, isLoading } = useSiteHasData(site);
-
- const { siteMetadata, isLoading: isLoadingSiteMetadata } =
- useGetSiteMetadata(site);
-
- if (isLoadingSiteMetadata || isLoading || !siteMetadata) {
- return null;
- }
-
- if (!siteHasData?.data && !isLoading && !isLoadingSiteMetadata) {
- return <NoData siteMetadata={siteMetadata} />;
- }
-
- return (
- <>
- <Header />
- <SubHeader />
- <MainSection />
- <div className="grid grid-cols-2 gap-4 mt-4">
- <OperatingSystems />
- <Browsers />
- <Devices />
- <Pages siteMetadata={siteMetadata} />
- <Referrers />
- <Countries />
- <Map />
- {/* <Chloropleth /> */}
- </div>
- </>
- );
+ return null;
}
diff --git a/client/src/app/[site]/realtime/page.tsx b/client/src/app/[site]/realtime/page.tsx
new file mode 100644
index 000000000..f84947841
--- /dev/null
+++ b/client/src/app/[site]/realtime/page.tsx
@@ -0,0 +1,12 @@
+"use client";
+
+export default function RealtimePage() {
+ return (
+ <div className="p-6">
+ <h1 className="text-2xl font-bold mb-4">Realtime</h1>
+ <p className="text-neutral-400">
+ Realtime analytics content will go here.
+ </p>
+ </div>
+ );
+}
diff --git a/client/src/app/[site]/reports/page.tsx b/client/src/app/[site]/reports/page.tsx
new file mode 100644
index 000000000..ef06d5b10
--- /dev/null
+++ b/client/src/app/[site]/reports/page.tsx
@@ -0,0 +1,12 @@
+"use client";
+
+export default function ReportsPage() {
+ return (
+ <div className="p-6">
+ <h1 className="text-2xl font-bold mb-4">Reports</h1>
+ <p className="text-neutral-400">
+ Reports and analytics content will go here.
+ </p>
+ </div>
+ );
+}
diff --git a/client/src/app/[site]/sessions/page.tsx b/client/src/app/[site]/sessions/page.tsx
new file mode 100644
index 000000000..8296ba954
--- /dev/null
+++ b/client/src/app/[site]/sessions/page.tsx
@@ -0,0 +1,10 @@
+"use client";
+
+export default function SessionsPage() {
+ return (
+ <div className="p-6">
+ <h1 className="text-2xl font-bold mb-4">Sessions</h1>
+ <p className="text-neutral-400">Sessions page content will go here.</p>
+ </div>
+ );
+}