🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Standardize images
Bill Yang1350488826e6
diff --git a/client/src/app/[site]/components/shared/icons/Browser.tsx b/client/src/app/[site]/components/shared/icons/Browser.tsxnew file mode 100644index 000000000..65742ed3d--- /dev/null+++ b/client/src/app/[site]/components/shared/icons/Browser.tsx@@ -0,0 +1,68 @@+import { Compass } from "lucide-react";+import Image from "next/image";++const BROWSER_TO_LOGO: Record<string, string> = {+ Chrome: "Chrome.svg",+ "Mobile Chrome": "Chrome.svg",+ "Chrome WebView": "Chrome.svg",+ "Chrome Headless": "Chromium.svg",+ Chromium: "Chromium.svg",+ GSA: "Chromium.svg",+ Firefox: "Firefox.svg",+ "Mobile Firefox": "Firefox.svg",+ Safari: "Safari.svg",+ "Mobile Safari": "Safari.svg",+ Edge: "Edge.svg",+ Opera: "Opera.svg",+ "Opera Touch": "Opera.svg",+ "Opera GX": "OperaGX.svg",+ "Samsung Internet": "SamsungInternet.svg",+ Yandex: "Yandex.svg",+ QQBrowser: "QQ.webp",+ Whale: "Whale.svg",+ Baidu: "Baidu.svg",+ WebKit: "WebKit.svg",+ DuckDuckGo: "DuckDuckGo.svg",+ Facebook: "Facebook.svg",+ "Sogou Explorer": "Sogou.png",+ "Avast Secure Browser": "Avast.png",+ NAVER: "Naver.webp",+ UCBrowser: "UCBrowser.svg",+ "Android Browser": "Android.svg",+ "AVG Secure Browser": "AVG.svg",+ "Smart Lenovo Browser": "Lenovo.png",+ "Vivo Browser": "Vivo.webp",+ Instagram: "Instagram.svg",+ Silk: "Silk.png",+ KAKAOTALK: "KAKAOTALK.svg",+ Iron: "Iron.png",+ Sleipnir: "Sleipnir.webp",+ HeyTap: "HeyTap.png",+ Line: "Line.svg",+ "Oculus Browser": "Oculus.svg",+ Wolvic: "Wolvic.png",+ "360": "360.png",+ PaleMoon: "PaleMoon.png",+ WeChat: "WeChat.svg",+ "Coc Coc": "CocCoc.svg",+ "Huawei Browser": "Huawei.svg",+ IE: "IE.svg",+};++export function Browser({ browser }: { browser: string }) {+ return (+ <>+ {BROWSER_TO_LOGO[browser] ? (+ <Image+ src={`/browsers/${BROWSER_TO_LOGO[browser]}`}+ alt={browser || "Other"}+ className="w-4 h-4"+ width={16}+ height={16}+ />+ ) : (+ <Compass width={16} />+ )}+ </>+ );+}diff --git a/client/src/app/[site]/components/shared/icons/CountryFlag.tsx b/client/src/app/[site]/components/shared/icons/CountryFlag.tsxnew file mode 100644index 000000000..f9e66ee5c--- /dev/null+++ b/client/src/app/[site]/components/shared/icons/CountryFlag.tsx@@ -0,0 +1,19 @@+import * as CountryFlags from "country-flag-icons/react/3x2";+import React from "react";+import { getCountryName } from "../../../../../lib/utils";++export function CountryFlag({ country }: { country: string }) {+ return (+ <>+ {CountryFlags[country as keyof typeof CountryFlags]+ ? React.createElement(+ CountryFlags[country as keyof typeof CountryFlags],+ {+ title: getCountryName(country),+ className: "w-5",+ }+ )+ : null}+ </>+ );+}diff --git a/client/src/app/[site]/components/shared/icons/OperatingSystem.tsx b/client/src/app/[site]/components/shared/icons/OperatingSystem.tsxnew file mode 100644index 000000000..5c73f4b65--- /dev/null+++ b/client/src/app/[site]/components/shared/icons/OperatingSystem.tsx@@ -0,0 +1,35 @@+import { Compass } from "lucide-react";+import Image from "next/image";++const OS_TO_LOGO: Record<string, string> = {+ Windows: "Windows.svg",+ Android: "Android.svg",+ android: "Android.svg",+ Linux: "Tux.svg",+ macOS: "macOS.png",+ iOS: "Apple.svg",+ "Chrome OS": "Chrome.svg",+ Ubuntu: "Ubuntu.svg",+ HarmonyOS: "HarmonyOS.svg",+ OpenHarmony: "OpenHarmony.png",+ PlayStation: "PlayStation.svg",+ Tizen: "Tizen.png",+};++export function OperatingSystem({ os = "" }: { os?: string }) {+ return (+ <>+ {OS_TO_LOGO[os] ? (+ <Image+ src={`/operating-systems/${OS_TO_LOGO[os]}`}+ alt={os || "Other"}+ className="w-4 h-4"+ width={16}+ height={16}+ />+ ) : (+ <Compass width={16} />+ )}+ </>+ );+}diff --git a/client/src/app/[site]/main/components/sections/Browsers.tsx b/client/src/app/[site]/main/components/sections/Browsers.tsxindex 83c4db0d0..c37f7d441 100644--- a/client/src/app/[site]/main/components/sections/Browsers.tsx+++ b/client/src/app/[site]/main/components/sections/Browsers.tsx@@ -1,57 +1,8 @@"use client";import { useSingleCol } from "@/hooks/api";-import { Compass } from "lucide-react";-import Image from "next/image";import { StandardCard } from "../../../components/shared/StandardCard";--const BROWSER_TO_LOGO: Record<string, string> = {- Chrome: "Chrome.svg",- "Mobile Chrome": "Chrome.svg",- "Chrome WebView": "Chrome.svg",- "Chrome Headless": "Chromium.svg",- Chromium: "Chromium.svg",- GSA: "Chromium.svg",- Firefox: "Firefox.svg",- "Mobile Firefox": "Firefox.svg",- Safari: "Safari.svg",- "Mobile Safari": "Safari.svg",- Edge: "Edge.svg",- Opera: "Opera.svg",- "Opera Touch": "Opera.svg",- "Opera GX": "OperaGX.svg",- "Samsung Internet": "SamsungInternet.svg",- Yandex: "Yandex.svg",- QQBrowser: "QQ.webp",- Whale: "Whale.svg",- Baidu: "Baidu.svg",- WebKit: "WebKit.svg",- DuckDuckGo: "DuckDuckGo.svg",- Facebook: "Facebook.svg",- "Sogou Explorer": "Sogou.png",- "Avast Secure Browser": "Avast.png",- NAVER: "Naver.webp",- UCBrowser: "UCBrowser.svg",- "Android Browser": "Android.svg",- "AVG Secure Browser": "AVG.svg",- "Smart Lenovo Browser": "Lenovo.png",- "Vivo Browser": "Vivo.webp",- Instagram: "Instagram.svg",- Silk: "Silk.png",- KAKAOTALK: "KAKAOTALK.svg",- Iron: "Iron.png",- Sleipnir: "Sleipnir.webp",- HeyTap: "HeyTap.png",- Line: "Line.svg",- "Oculus Browser": "Oculus.svg",- Wolvic: "Wolvic.png",- "360": "360.png",- PaleMoon: "PaleMoon.png",- WeChat: "WeChat.svg",- "Coc Coc": "CocCoc.svg",- "Huawei Browser": "Huawei.svg",- IE: "IE.svg",-};+import { Browser } from "../../../components/shared/icons/Browser";export function Browsers() {const { data, isFetching } = useSingleCol({ parameter: "browser" });@@ -64,17 +15,7 @@ export function Browsers() {getKey={(e) => e.value}getLabel={(e) => (<div className="flex gap-2 items-center">- {BROWSER_TO_LOGO[e.value] ? (- <Image- src={`/browsers/${BROWSER_TO_LOGO[e.value]}`}- alt={e.value || "Other"}- className="w-4 h-4"- width={16}- height={16}- />- ) : (- <Compass width={16} />- )}+ <Browser browser={e.value} />{e.value || "Other"}</div>)}diff --git a/client/src/app/[site]/main/components/sections/Countries.tsx b/client/src/app/[site]/main/components/sections/Countries.tsxindex d16414bb0..a2f687426 100644--- a/client/src/app/[site]/main/components/sections/Countries.tsx+++ b/client/src/app/[site]/main/components/sections/Countries.tsx@@ -1,10 +1,10 @@"use client";import { useSingleCol } from "@/hooks/api";-import * as CountryFlags from "country-flag-icons/react/3x2";import React from "react";import { getCountryName } from "../../../../../lib/utils";import { StandardCard } from "../../../components/shared/StandardCard";+import { CountryFlag } from "../../../components/shared/icons/CountryFlag";export function Countries() {const { data, isFetching } = useSingleCol({ parameter: "country" });@@ -19,15 +19,7 @@ export function Countries() {<span className="flex items-center gap-2">{e.value && getCountryName(e.value) ? (<>- {CountryFlags[e.value as keyof typeof CountryFlags]- ? React.createElement(- CountryFlags[e.value as keyof typeof CountryFlags],- {- title: getCountryName(e.value),- className: "w-5",- }- )- : null}+ <CountryFlag country={e.value} />{getCountryName(e.value)}</>) : (diff --git a/client/src/app/[site]/main/components/sections/OperatingSystems.tsx b/client/src/app/[site]/main/components/sections/OperatingSystems.tsxindex 94a1dd499..390f2496f 100644--- a/client/src/app/[site]/main/components/sections/OperatingSystems.tsx+++ b/client/src/app/[site]/main/components/sections/OperatingSystems.tsx@@ -1,24 +1,8 @@"use client";-import { Compass } from "lucide-react";-import Image from "next/image";import { useSingleCol } from "@/hooks/api";import { StandardCard } from "../../../components/shared/StandardCard";--const OS_TO_LOGO: Record<string, string> = {- Windows: "Windows.svg",- Android: "Android.svg",- android: "Android.svg",- Linux: "Tux.svg",- macOS: "macOS.png",- iOS: "Apple.svg",- "Chrome OS": "Chrome.svg",- Ubuntu: "Ubuntu.svg",- HarmonyOS: "HarmonyOS.svg",- OpenHarmony: "OpenHarmony.png",- PlayStation: "PlayStation.svg",- Tizen: "Tizen.png",-};+import { OperatingSystem } from "../../../components/shared/icons/OperatingSystem";export function OperatingSystems() {const { data, isFetching } = useSingleCol({ parameter: "operating_system" });@@ -32,17 +16,7 @@ export function OperatingSystems() {getKey={(e) => e.value}getLabel={(e) => (<div className="flex gap-2 items-center">- {OS_TO_LOGO[e.value] ? (- <Image- src={`/operating-systems/${OS_TO_LOGO[e.value]}`}- alt={e.value || "Other"}- className="w-4 h-4"- width={16}- height={16}- />- ) : (- <Compass width={16} />- )}+ <OperatingSystem os={e.value || "Other"} />{e.value || "Other"}</div>)}diff --git a/client/src/app/[site]/sessions/components/SessionsTable.tsx b/client/src/app/[site]/sessions/components/SessionsTable.tsxnew file mode 100644index 000000000..e62be5679--- /dev/null+++ b/client/src/app/[site]/sessions/components/SessionsTable.tsx@@ -0,0 +1,199 @@+import {+ createColumnHelper,+ flexRender,+ getCoreRowModel,+ useReactTable,+} from "@tanstack/react-table";+import { format, parseISO } from "date-fns";+import { useEffect, useMemo, useRef } from "react";+import { getCountryName } from "../../../../lib/utils";+import { APIResponse } from "@/hooks/api";+import { CountryFlag } from "../../components/shared/icons/CountryFlag";+import { Browser } from "../../components/shared/icons/Browser";+import { OperatingSystem } from "../../components/shared/icons/OperatingSystem";++type Session = {+ session_id: string;+ user_id: string;+ country: string;+ iso_3166_2: string;+ language: string;+ device_type: string;+ browser: string;+ operating_system: string;+ referrer: string;+ last_pageview_timestamp: string;+ pageviews: number;+};++interface SessionsTableProps {+ data: Session[];+ isLoading: boolean;+ fetchNextPage: () => void;+ hasNextPage: boolean | undefined;+ isFetchingNextPage: boolean;+}++export default function SessionsTable({+ data,+ isLoading,+ fetchNextPage,+ hasNextPage,+ isFetchingNextPage,+}: SessionsTableProps) {+ // Reference for the scroll container+ const tableContainerRef = useRef<HTMLDivElement>(null);++ // Infinite scroll implementation+ useEffect(() => {+ const handleScroll = () => {+ if (!tableContainerRef.current) return;++ const { scrollHeight, scrollTop, clientHeight } =+ tableContainerRef.current;++ // Load more when user scrolls to bottom (with a 200px buffer)+ if (+ scrollHeight - scrollTop - clientHeight < 200 &&+ !isFetchingNextPage &&+ hasNextPage+ ) {+ fetchNextPage();+ }+ };++ const tableContainer = tableContainerRef.current;+ if (tableContainer) {+ tableContainer.addEventListener("scroll", handleScroll);+ return () => {+ tableContainer.removeEventListener("scroll", handleScroll);+ };+ }+ }, [fetchNextPage, hasNextPage, isFetchingNextPage]);++ // Column definition+ const columnHelper = createColumnHelper<Session>();++ const columns = useMemo(+ () => [+ columnHelper.accessor("last_pageview_timestamp", {+ header: "Last Seen",+ cell: (info) => {+ const date = parseISO(info.getValue());+ return format(date, "MMM d, yyyy h:mm a");+ },+ }),+ columnHelper.accessor("pageviews", {+ header: "Pageviews",+ cell: (info) => info.getValue(),+ }),+ columnHelper.accessor("country", {+ header: "Country",+ cell: (info) => (+ <div className="flex items-center gap-2">+ <CountryFlag country={info.getValue() || "Unknown"} />+ {getCountryName(info.getValue() || "Unknown")}+ </div>+ ),+ }),+ columnHelper.accessor("browser", {+ header: "Browser",+ cell: (info) => (+ <div className="flex items-center gap-2">+ <Browser browser={info.getValue() || "Unknown"} />+ {info.getValue() || "Unknown"}+ </div>+ ),+ }),+ columnHelper.accessor("operating_system", {+ header: "OS",+ cell: (info) =>+ info.getValue() ? (+ <div className="flex items-center gap-2">+ <OperatingSystem os={info.getValue()} />+ {info.getValue()}+ </div>+ ) : (+ "-"+ ),+ }),+ columnHelper.accessor("device_type", {+ header: "Device",+ cell: (info) => info.getValue() || "Unknown",+ }),+ columnHelper.accessor("referrer", {+ header: "Referrer",+ cell: (info) => info.getValue() || "-",+ }),+ ],+ []+ );++ // Table instance+ const table = useReactTable({+ data,+ columns,+ getCoreRowModel: getCoreRowModel(),+ });++ return (+ <div+ ref={tableContainerRef}+ className="overflow-auto rounded-lg"+ style={{ height: "calc(100vh - 200px)" }}+ >+ <table className="min-w-full divide-y divide-gray-200">+ <thead className="bg-neutral-900 sticky top-0">+ {table.getHeaderGroups().map((headerGroup) => (+ <tr key={headerGroup.id}>+ {headerGroup.headers.map((header) => (+ <th+ key={header.id}+ className="px-6 py-3 text-left font-medium text-gray-400 tracking-wider"+ >+ <div className="flex items-center">+ {flexRender(+ header.column.columnDef.header,+ header.getContext()+ )}+ </div>+ </th>+ ))}+ </tr>+ ))}+ </thead>+ <tbody className="divide-y divide-neutral-650">+ {isLoading ? (+ <tr>+ <td colSpan={columns.length} className="px-6 py-4">+ <div className="flex justify-center">Loading...</div>+ </td>+ </tr>+ ) : data.length === 0 ? (+ <tr>+ <td colSpan={columns.length} className="px-6 py-4">+ <div className="flex justify-center">No sessions found</div>+ </td>+ </tr>+ ) : (+ table.getRowModel().rows.map((row) => (+ <tr key={row.id} className="hover:bg-neutral-850 bg-neutral-900">+ {row.getVisibleCells().map((cell) => (+ <td key={cell.id} className="px-6 py-4 whitespace-nowrap">+ {flexRender(cell.column.columnDef.cell, cell.getContext())}+ </td>+ ))}+ </tr>+ ))+ )}+ </tbody>+ </table>++ {isFetchingNextPage && (+ <div className="flex justify-center p-4">+ <div className="text-sm text-gray-500">Loading more sessions...</div>+ </div>+ )}+ </div>+ );+}diff --git a/client/src/app/[site]/sessions/page.tsx b/client/src/app/[site]/sessions/page.tsxindex 239241671..aaf23d97e 100644--- a/client/src/app/[site]/sessions/page.tsx+++ b/client/src/app/[site]/sessions/page.tsx@@ -1,29 +1,8 @@"use client";import { useGetSessionsInfinite } from "@/hooks/api";-import {- createColumnHelper,- flexRender,- getCoreRowModel,- useReactTable,-} from "@tanstack/react-table";-import { format, parseISO } from "date-fns";-import { useEffect, useMemo, useRef } from "react";-import { getCountryName } from "../../../lib/utils";--type Session = {- session_id: string;- user_id: string;- country: string;- iso_3166_2: string;- language: string;- device_type: string;- browser: string;- operating_system: string;- referrer: string;- last_pageview_timestamp: string;- pageviews: number;-};+import { useMemo } from "react";+import SessionsTable from "./components/SessionsTable";export default function SessionsPage() {const {@@ -41,155 +20,17 @@ export default function SessionsPage() {return data.pages.flatMap((page) => page.data || []);}, [data]);- // Reference for the scroll container- const tableContainerRef = useRef<HTMLDivElement>(null);-- // Infinite scroll implementation- useEffect(() => {- const handleScroll = () => {- if (!tableContainerRef.current) return;-- const { scrollHeight, scrollTop, clientHeight } =- tableContainerRef.current;-- // Load more when user scrolls to bottom (with a 200px buffer)- if (- scrollHeight - scrollTop - clientHeight < 200 &&- !isFetchingNextPage &&- hasNextPage- ) {- fetchNextPage();- }- };-- const tableContainer = tableContainerRef.current;- if (tableContainer) {- tableContainer.addEventListener("scroll", handleScroll);- return () => {- tableContainer.removeEventListener("scroll", handleScroll);- };- }- }, [fetchNextPage, hasNextPage, isFetchingNextPage]);-- // Column definition- const columnHelper = createColumnHelper<Session>();-- const columns = useMemo(- () => [- columnHelper.accessor("last_pageview_timestamp", {- header: "Last Seen",- cell: (info) => {- const date = parseISO(info.getValue());- return format(date, "MMM d, yyyy h:mm a");- },- }),- columnHelper.accessor("pageviews", {- header: "Pageviews",- cell: (info) => info.getValue(),- }),- columnHelper.accessor("country", {- header: "Country",- cell: (info) => getCountryName(info.getValue() || "Unknown"),- }),- columnHelper.accessor("browser", {- header: "Browser",- cell: (info) => info.getValue() || "Unknown",- }),- columnHelper.accessor("operating_system", {- header: "OS",- cell: (info) => info.getValue() || "Unknown",- }),- columnHelper.accessor("device_type", {- header: "Device",- cell: (info) => info.getValue() || "Unknown",- }),- columnHelper.accessor("referrer", {- header: "Referrer",- cell: (info) => info.getValue() || "Direct",- }),- ],- []- );-- // Table instance- const table = useReactTable({- data: flattenedData,- columns,- getCoreRowModel: getCoreRowModel(),- });-- if (error)- return <div className="p-6">Error: {(error as Error).message}</div>;+ if (error) return <div>Error: {(error as Error).message}</div>;return (- <div className="p-6">- <h1 className="text-2xl font-bold mb-4">Sessions</h1>- <div- ref={tableContainerRef}- className="overflow-auto rounded-lg"- style={{ height: "calc(100vh - 200px)" }}- >- <table className="min-w-full divide-y divide-gray-200">- <thead className="bg-neutral-900 sticky top-0">- {table.getHeaderGroups().map((headerGroup) => (- <tr key={headerGroup.id}>- {headerGroup.headers.map((header) => (- <th- key={header.id}- className="px-6 py-3 text-left font-medium text-gray-400 tracking-wider"- >- <div className="flex items-center">- {flexRender(- header.column.columnDef.header,- header.getContext()- )}- </div>- </th>- ))}- </tr>- ))}- </thead>- <tbody className="divide-y divide-neutral-650">- {isLoading ? (- <tr>- <td colSpan={columns.length} className="px-6 py-4">- <div className="flex justify-center">Loading...</div>- </td>- </tr>- ) : flattenedData.length === 0 ? (- <tr>- <td colSpan={columns.length} className="px-6 py-4">- <div className="flex justify-center">No sessions found</div>- </td>- </tr>- ) : (- table.getRowModel().rows.map((row) => (- <tr- key={row.id}- className="hover:bg-neutral-850 bg-neutral-900"- >- {row.getVisibleCells().map((cell) => (- <td key={cell.id} className="px-6 py-4 whitespace-nowrap">- {flexRender(- cell.column.columnDef.cell,- cell.getContext()- )}- </td>- ))}- </tr>- ))- )}- </tbody>- </table>-- {isFetchingNextPage && (- <div className="flex justify-center p-4">- <div className="text-sm text-gray-500">- Loading more sessions...- </div>- </div>- )}- </div>+ <div>+ <SessionsTable+ data={flattenedData}+ isLoading={isLoading}+ fetchNextPage={fetchNextPage}+ hasNextPage={hasNextPage}+ isFetchingNextPage={isFetchingNextPage}+ /></div>);}