From 725b5218ea03d677cebbe62aadd2d227f8b6e214 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 9 Nov 2025 11:52:39 +0000 Subject: feat: Add bookmark sources statistics section (#2110) * feat: add bookmark sources statistics to usage stats page Add a new section to the usage statistics page that displays stats about bookmark sources (mobile, extension, web, API, CLI, etc). Changes: - Add bookmarksBySource field to user stats response schema - Implement backend query to fetch bookmarks grouped by source - Add new "Bookmark Sources" card to stats page UI - Add helper function to format source names for display * refactor: use stricter enum type for bookmark sources in stats API Replace generic string type with zBookmarkSourceSchema enum for better type safety and autocomplete. This ensures the API contract matches the database schema definition. Changes: - Import and use zBookmarkSourceSchema in user stats response - Define BookmarkSource type alias in frontend - Update formatSourceName to use stricter type and return non-nullable - Remove fallback case since all enum values are now handled * refactor: use shared BookmarkSource type and add i18n support - Replace local BookmarkSource type with canonical type from shared package using z.infer - Add translation support for "Bookmark Sources" title and empty state - Add bookmark_sources.title and bookmark_sources.empty keys to English locale file This ensures type consistency across the codebase and prepares for future localization of the bookmark sources feature. * fix icons --------- Co-authored-by: Claude --- apps/web/app/settings/stats/page.tsx | 90 ++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'apps/web/app/settings') diff --git a/apps/web/app/settings/stats/page.tsx b/apps/web/app/settings/stats/page.tsx index 599e5362..944d1c59 100644 --- a/apps/web/app/settings/stats/page.tsx +++ b/apps/web/app/settings/stats/page.tsx @@ -11,18 +11,30 @@ import { Archive, BarChart3, BookOpen, + Chrome, Clock, + Code, Database, FileText, Globe, Hash, Heart, + HelpCircle, Highlighter, Image, Link, List, + Rss, + Smartphone, TrendingUp, + Upload, + Zap, } from "lucide-react"; +import { z } from "zod"; + +import { zBookmarkSourceSchema } from "@karakeep/shared/types/bookmarks"; + +type BookmarkSource = z.infer; function formatBytes(bytes: number): string { if (bytes === 0) return "0 Bytes"; @@ -47,6 +59,45 @@ const hourLabels = Array.from({ length: 24 }, (_, i) => i === 0 ? "12 AM" : i < 12 ? `${i} AM` : i === 12 ? "12 PM" : `${i - 12} PM`, ); +function formatSourceName(source: BookmarkSource | null): string { + if (!source) return "Unknown"; + const sourceMap: Record = { + api: "API", + web: "Web", + extension: "Browser Extension", + cli: "CLI", + mobile: "Mobile App", + singlefile: "SingleFile", + rss: "RSS Feed", + import: "Import", + }; + return sourceMap[source]; +} + +function getSourceIcon(source: BookmarkSource | null): React.ReactNode { + const iconProps = { className: "h-4 w-4 text-muted-foreground" }; + switch (source) { + case "api": + return ; + case "web": + return ; + case "extension": + return ; + case "cli": + return ; + case "mobile": + return ; + case "singlefile": + return ; + case "rss": + return ; + case "import": + return ; + default: + return ; + } +} + function SimpleBarChart({ data, maxValue, @@ -439,6 +490,45 @@ export default function StatsPage() { )} + + {/* Bookmark Sources */} + + + + + {t("settings.stats.bookmark_sources.title")} + + + + {stats.bookmarksBySource.length > 0 ? ( +
+ {stats.bookmarksBySource.map( + (source: { + source: BookmarkSource | null; + count: number; + }) => ( +
+
+ {getSourceIcon(source.source)} + + {formatSourceName(source.source)} + +
+ {source.count} +
+ ), + )} +
+ ) : ( +

+ {t("settings.stats.bookmark_sources.empty")} +

+ )} +
+
{/* Activity Patterns */} -- cgit v1.2.3-70-g09d2