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 --- packages/trpc/models/users.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'packages/trpc/models') diff --git a/packages/trpc/models/users.ts b/packages/trpc/models/users.ts index a327e7db..7e6be7a5 100644 --- a/packages/trpc/models/users.ts +++ b/packages/trpc/models/users.ts @@ -506,6 +506,7 @@ export class User implements PrivacyAware { [{ thisYear }], bookmarkTimestamps, tagUsage, + bookmarksBySource, ] = await Promise.all([ // Basic counts this.ctx.db @@ -677,6 +678,17 @@ export class User implements PrivacyAware { .groupBy(bookmarkTags.name) .orderBy(desc(count())) .limit(10), + + // Bookmarks by source + this.ctx.db + .select({ + source: bookmarks.source, + count: count(), + }) + .from(bookmarks) + .where(eq(bookmarks.userId, this.user.id)) + .groupBy(bookmarks.source) + .orderBy(desc(count())), ]); // Process bookmarks by type @@ -735,6 +747,7 @@ export class User implements PrivacyAware { byDayOfWeek: dailyActivity, }, tagUsage, + bookmarksBySource, }; } -- cgit v1.2.3-70-g09d2