From be7ba764179a01f3e9ff4bc5d18cd917918c0aac Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Thu, 22 Jan 2026 16:07:06 +0530 Subject: [PATCH] chore: ran backend and frontend linting --- .../app/routes/notifications_routes.py | 87 +++++++++++-------- .../dashboard/[search_space_id]/team/page.tsx | 9 +- .../comment-sheet/comment-sheet.tsx | 8 +- .../layout/providers/LayoutDataProvider.tsx | 18 ++-- .../ui/sidebar/AllPrivateChatsSidebar.tsx | 8 +- .../ui/sidebar/AllSharedChatsSidebar.tsx | 8 +- .../components/shared/llm-config-form.tsx | 4 +- surfsense_web/components/ui/drawer.tsx | 47 +++------- surfsense_web/components/ui/spinner.tsx | 47 +++++----- surfsense_web/contracts/types/inbox.types.ts | 1 - surfsense_web/hooks/use-inbox.ts | 9 +- 11 files changed, 119 insertions(+), 127 deletions(-) diff --git a/surfsense_backend/app/routes/notifications_routes.py b/surfsense_backend/app/routes/notifications_routes.py index f7b52f3e7..6172aacc5 100644 --- a/surfsense_backend/app/routes/notifications_routes.py +++ b/surfsense_backend/app/routes/notifications_routes.py @@ -6,7 +6,6 @@ For older items (beyond the sync window), use the list endpoint. """ from datetime import datetime -from typing import Optional from fastapi import APIRouter, Depends, HTTPException, Query, status from pydantic import BaseModel @@ -24,14 +23,14 @@ class NotificationResponse(BaseModel): id: int user_id: str - search_space_id: Optional[int] + search_space_id: int | None type: str title: str message: str read: bool metadata: dict created_at: str - updated_at: Optional[str] + updated_at: str | None class Config: from_attributes = True @@ -43,7 +42,7 @@ class NotificationListResponse(BaseModel): items: list[NotificationResponse] total: int has_more: bool - next_offset: Optional[int] + next_offset: int | None class MarkReadResponse(BaseModel): @@ -63,9 +62,15 @@ class MarkAllReadResponse(BaseModel): @router.get("", response_model=NotificationListResponse) async def list_notifications( - search_space_id: Optional[int] = Query(None, description="Filter by search space ID"), - type_filter: Optional[str] = Query(None, alias="type", description="Filter by notification type"), - before_date: Optional[str] = Query(None, description="Get notifications before this ISO date (for pagination)"), + search_space_id: int | None = Query( + None, description="Filter by search space ID" + ), + type_filter: str | None = Query( + None, alias="type", description="Filter by notification type" + ), + before_date: str | None = Query( + None, description="Get notifications before this ISO date (for pagination)" + ), limit: int = Query(50, ge=1, le=100, description="Number of items to return"), offset: int = Query(0, ge=0, description="Number of items to skip"), user: User = Depends(current_active_user), @@ -73,32 +78,34 @@ async def list_notifications( ) -> NotificationListResponse: """ List notifications for the current user with pagination. - + This endpoint is used as a fallback for older notifications that are outside the Electric SQL sync window (2 weeks). - + Use `before_date` to paginate through older notifications efficiently. """ # Build base query query = select(Notification).where(Notification.user_id == user.id) - count_query = select(func.count(Notification.id)).where(Notification.user_id == user.id) - + count_query = select(func.count(Notification.id)).where( + Notification.user_id == user.id + ) + # Filter by search space (include null search_space_id for global notifications) if search_space_id is not None: query = query.where( - (Notification.search_space_id == search_space_id) | - (Notification.search_space_id.is_(None)) + (Notification.search_space_id == search_space_id) + | (Notification.search_space_id.is_(None)) ) count_query = count_query.where( - (Notification.search_space_id == search_space_id) | - (Notification.search_space_id.is_(None)) + (Notification.search_space_id == search_space_id) + | (Notification.search_space_id.is_(None)) ) - + # Filter by type if type_filter: query = query.where(Notification.type == type_filter) count_query = count_query.where(Notification.type == type_filter) - + # Filter by date (for efficient pagination of older items) if before_date: try: @@ -110,39 +117,47 @@ async def list_notifications( status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid date format. Use ISO format (e.g., 2024-01-15T00:00:00Z)", ) from None - + # Get total count total_result = await session.execute(count_query) total = total_result.scalar() or 0 - + # Apply ordering and pagination - query = query.order_by(desc(Notification.created_at)).offset(offset).limit(limit + 1) - + query = ( + query.order_by(desc(Notification.created_at)).offset(offset).limit(limit + 1) + ) + # Execute query result = await session.execute(query) notifications = result.scalars().all() - + # Check if there are more items has_more = len(notifications) > limit if has_more: notifications = notifications[:limit] - + # Convert to response format items = [] for notification in notifications: - items.append(NotificationResponse( - id=notification.id, - user_id=str(notification.user_id), - search_space_id=notification.search_space_id, - type=notification.type, - title=notification.title, - message=notification.message, - read=notification.read, - metadata=notification.notification_metadata or {}, - created_at=notification.created_at.isoformat() if notification.created_at else "", - updated_at=notification.updated_at.isoformat() if notification.updated_at else None, - )) - + items.append( + NotificationResponse( + id=notification.id, + user_id=str(notification.user_id), + search_space_id=notification.search_space_id, + type=notification.type, + title=notification.title, + message=notification.message, + read=notification.read, + metadata=notification.notification_metadata or {}, + created_at=notification.created_at.isoformat() + if notification.created_at + else "", + updated_at=notification.updated_at.isoformat() + if notification.updated_at + else None, + ) + ) + return NotificationListResponse( items=items, total=total, diff --git a/surfsense_web/app/dashboard/[search_space_id]/team/page.tsx b/surfsense_web/app/dashboard/[search_space_id]/team/page.tsx index a0bc6be03..b661e9222 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/team/page.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/team/page.tsx @@ -711,12 +711,9 @@ function MembersTab({ ) : ( - - {member.role?.name || "No role"} - + + {member.role?.name || "No role"} + )} diff --git a/surfsense_web/components/chat-comments/comment-sheet/comment-sheet.tsx b/surfsense_web/components/chat-comments/comment-sheet/comment-sheet.tsx index b8e58ad2b..d483ab261 100644 --- a/surfsense_web/components/chat-comments/comment-sheet/comment-sheet.tsx +++ b/surfsense_web/components/chat-comments/comment-sheet/comment-sheet.tsx @@ -1,7 +1,13 @@ "use client"; import { MessageSquare } from "lucide-react"; -import { Drawer, DrawerContent, DrawerHandle, DrawerHeader, DrawerTitle } from "@/components/ui/drawer"; +import { + Drawer, + DrawerContent, + DrawerHandle, + DrawerHeader, + DrawerTitle, +} from "@/components/ui/drawer"; import { Sheet, SheetContent, SheetHeader, SheetTitle } from "@/components/ui/sheet"; import { cn } from "@/lib/utils"; import { CommentPanelContainer } from "../comment-panel-container/comment-panel-container"; diff --git a/surfsense_web/components/layout/providers/LayoutDataProvider.tsx b/surfsense_web/components/layout/providers/LayoutDataProvider.tsx index 16e6da4cc..5f4617b84 100644 --- a/surfsense_web/components/layout/providers/LayoutDataProvider.tsx +++ b/surfsense_web/components/layout/providers/LayoutDataProvider.tsx @@ -87,20 +87,16 @@ export function LayoutDataProvider({ // Inbox hook const userId = user?.id ? String(user.id) : null; - const { - inboxItems, - unreadCount, - loading: inboxLoading, + const { + inboxItems, + unreadCount, + loading: inboxLoading, loadingMore: inboxLoadingMore, hasMore: inboxHasMore, loadMore: inboxLoadMore, - markAsRead, - markAllAsRead - } = useInbox( - userId, - Number(searchSpaceId) || null, - null - ); + markAsRead, + markAllAsRead, + } = useInbox(userId, Number(searchSpaceId) || null, null); // Delete dialogs state const [showDeleteChatDialog, setShowDeleteChatDialog] = useState(false); diff --git a/surfsense_web/components/layout/ui/sidebar/AllPrivateChatsSidebar.tsx b/surfsense_web/components/layout/ui/sidebar/AllPrivateChatsSidebar.tsx index 78bac3371..39f1b95bc 100644 --- a/surfsense_web/components/layout/ui/sidebar/AllPrivateChatsSidebar.tsx +++ b/surfsense_web/components/layout/ui/sidebar/AllPrivateChatsSidebar.tsx @@ -280,7 +280,9 @@ export function AllPrivateChatsSidebar({ Active - {activeCount} + + {activeCount} + Archived - {archivedCount} + + {archivedCount} + diff --git a/surfsense_web/components/layout/ui/sidebar/AllSharedChatsSidebar.tsx b/surfsense_web/components/layout/ui/sidebar/AllSharedChatsSidebar.tsx index e3b6174c3..8dd593945 100644 --- a/surfsense_web/components/layout/ui/sidebar/AllSharedChatsSidebar.tsx +++ b/surfsense_web/components/layout/ui/sidebar/AllSharedChatsSidebar.tsx @@ -280,7 +280,9 @@ export function AllSharedChatsSidebar({ Active - {activeCount} + + {activeCount} + Archived - {archivedCount} + + {archivedCount} + diff --git a/surfsense_web/components/shared/llm-config-form.tsx b/surfsense_web/components/shared/llm-config-form.tsx index e2e45194b..5ffff1ab7 100644 --- a/surfsense_web/components/shared/llm-config-form.tsx +++ b/surfsense_web/components/shared/llm-config-form.tsx @@ -551,7 +551,9 @@ export function LLMConfigForm({ render={({ field }) => (
- Enable Citations + + Enable Citations + Include [citation:id] references to source documents diff --git a/surfsense_web/components/ui/drawer.tsx b/surfsense_web/components/ui/drawer.tsx index 81733487d..015d6ac07 100644 --- a/surfsense_web/components/ui/drawer.tsx +++ b/surfsense_web/components/ui/drawer.tsx @@ -9,12 +9,7 @@ function Drawer({ shouldScaleBackground = true, ...props }: React.ComponentProps) { - return ( - - ); + return ; } Drawer.displayName = "Drawer"; @@ -62,42 +57,20 @@ function DrawerContent({ } DrawerContent.displayName = "DrawerContent"; -function DrawerHeader({ - className, - ...props -}: React.HTMLAttributes) { - return ( -
- ); +function DrawerHeader({ className, ...props }: React.HTMLAttributes) { + return
; } DrawerHeader.displayName = "DrawerHeader"; -function DrawerFooter({ - className, - ...props -}: React.HTMLAttributes) { - return ( -
- ); +function DrawerFooter({ className, ...props }: React.HTMLAttributes) { + return
; } DrawerFooter.displayName = "DrawerFooter"; -function DrawerTitle({ - className, - ...props -}: React.ComponentProps) { +function DrawerTitle({ className, ...props }: React.ComponentProps) { return ( ); @@ -119,7 +92,10 @@ DrawerDescription.displayName = DrawerPrimitive.Description.displayName; function DrawerHandle({ className, ...props }: React.HTMLAttributes) { return ( -
+
); } DrawerHandle.displayName = "DrawerHandle"; @@ -137,4 +113,3 @@ export { DrawerDescription, DrawerHandle, }; - diff --git a/surfsense_web/components/ui/spinner.tsx b/surfsense_web/components/ui/spinner.tsx index eeed30a8a..22d190afa 100644 --- a/surfsense_web/components/ui/spinner.tsx +++ b/surfsense_web/components/ui/spinner.tsx @@ -1,34 +1,33 @@ import { cn } from "@/lib/utils"; interface SpinnerProps { - /** Size of the spinner */ - size?: "xs" | "sm" | "md" | "lg" | "xl"; - /** Whether to hide the track behind the spinner arc */ - hideTrack?: boolean; - /** Additional classes to apply */ - className?: string; + /** Size of the spinner */ + size?: "xs" | "sm" | "md" | "lg" | "xl"; + /** Whether to hide the track behind the spinner arc */ + hideTrack?: boolean; + /** Additional classes to apply */ + className?: string; } const sizeClasses = { - xs: "h-3 w-3 border-[1.5px]", - sm: "h-4 w-4 border-2", - md: "h-6 w-6 border-2", - lg: "h-8 w-8 border-[3px]", - xl: "h-10 w-10 border-4", + xs: "h-3 w-3 border-[1.5px]", + sm: "h-4 w-4 border-2", + md: "h-6 w-6 border-2", + lg: "h-8 w-8 border-[3px]", + xl: "h-10 w-10 border-4", }; export function Spinner({ size = "md", hideTrack = false, className }: SpinnerProps) { - return ( - - ); + return ( + + ); } - diff --git a/surfsense_web/contracts/types/inbox.types.ts b/surfsense_web/contracts/types/inbox.types.ts index 515ba5864..c1627ebee 100644 --- a/surfsense_web/contracts/types/inbox.types.ts +++ b/surfsense_web/contracts/types/inbox.types.ts @@ -146,4 +146,3 @@ export type InboxItem = z.infer; export type ConnectorIndexingInboxItem = z.infer; export type DocumentProcessingInboxItem = z.infer; export type NewMentionInboxItem = z.infer; - diff --git a/surfsense_web/hooks/use-inbox.ts b/surfsense_web/hooks/use-inbox.ts index bd4a6ee35..7ce33ac9a 100644 --- a/surfsense_web/hooks/use-inbox.ts +++ b/surfsense_web/hooks/use-inbox.ts @@ -190,9 +190,7 @@ export function useInbox( ORDER BY created_at DESC LIMIT ${PAGE_SIZE}`; - const params = typeFilter - ? [userId, searchSpaceId, typeFilter] - : [userId, searchSpaceId]; + const params = typeFilter ? [userId, searchSpaceId, typeFilter] : [userId, searchSpaceId]; const db = client.db as any; @@ -310,10 +308,7 @@ export function useInbox( AND read = false AND created_at > '${cutoff}'`; - const result = await client.db.query<{ count: number }>(query, [ - userId, - searchSpaceId, - ]); + const result = await client.db.query<{ count: number }>(query, [userId, searchSpaceId]); if (mounted && result.rows?.[0]) { setTotalUnreadCount(Number(result.rows[0].count) || 0); }