aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/models/users.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-11-09 11:52:39 +0000
committerGitHub <noreply@github.com>2025-11-09 11:52:39 +0000
commit725b5218ea03d677cebbe62aadd2d227f8b6e214 (patch)
treea4abbbb7fc0b62d6dda468b4e3eac0c684266fb2 /packages/trpc/models/users.ts
parent3083be0c9dc9ec0ded58eda937b83fbdf511f386 (diff)
downloadkarakeep-725b5218ea03d677cebbe62aadd2d227f8b6e214.tar.zst
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<typeof zBookmarkSourceSchema> - 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 <noreply@anthropic.com>
Diffstat (limited to 'packages/trpc/models/users.ts')
-rw-r--r--packages/trpc/models/users.ts13
1 files changed, 13 insertions, 0 deletions
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,
};
}