From e8e393a0d5f20d5e91bae1ad5f17e1cb13ec4523 Mon Sep 17 00:00:00 2001
From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com>
Date: Tue, 16 Dec 2025 20:25:50 +0530
Subject: [PATCH] fix: fixed linting for some files
---
.../48_add_note_to_documenttype_enum.py | 2 +-
surfsense_backend/app/routes/editor_routes.py | 20 ++++++++++++++++---
surfsense_backend/app/routes/notes_routes.py | 20 +++++++++++++------
.../editor/[documentId]/page.tsx | 14 ++++++-------
4 files changed, 39 insertions(+), 17 deletions(-)
diff --git a/surfsense_backend/alembic/versions/48_add_note_to_documenttype_enum.py b/surfsense_backend/alembic/versions/48_add_note_to_documenttype_enum.py
index 353b5b042..7f8254270 100644
--- a/surfsense_backend/alembic/versions/48_add_note_to_documenttype_enum.py
+++ b/surfsense_backend/alembic/versions/48_add_note_to_documenttype_enum.py
@@ -44,4 +44,4 @@ def downgrade() -> None:
Downgrade logic not implemented since PostgreSQL
does not support removing enum values.
"""
- pass
\ No newline at end of file
+ pass
diff --git a/surfsense_backend/app/routes/editor_routes.py b/surfsense_backend/app/routes/editor_routes.py
index 541a7a012..606a52ec5 100644
--- a/surfsense_backend/app/routes/editor_routes.py
+++ b/surfsense_backend/app/routes/editor_routes.py
@@ -85,7 +85,9 @@ async def get_editor_content(
"title": document.title,
"document_type": document.document_type.value,
"blocknote_document": empty_blocknote,
- "updated_at": document.updated_at.isoformat() if document.updated_at else None,
+ "updated_at": document.updated_at.isoformat()
+ if document.updated_at
+ else None,
}
# Lazy migration: Try to generate blocknote_document from chunks (for other document types)
@@ -178,18 +180,30 @@ async def save_document(
and len(blocknote_document) > 0
):
first_block = blocknote_document[0]
- if first_block and first_block.get("content"):
+ if (
+ first_block
+ and first_block.get("content")
+ and isinstance(first_block["content"], list)
+ ):
# Extract text from first block content
+ # Match the frontend extractTitleFromBlockNote logic exactly
title_parts = []
for item in first_block["content"]:
if isinstance(item, str):
title_parts.append(item)
- elif isinstance(item, dict) and "text" in item:
+ elif (
+ isinstance(item, dict)
+ and "text" in item
+ and isinstance(item["text"], str)
+ ):
+ # BlockNote structure: {"type": "text", "text": "...", "styles": {}}
title_parts.append(item["text"])
+
new_title = "".join(title_parts).strip()
if new_title:
document.title = new_title
else:
+ # Only set to "Untitled" if content exists but is empty
document.title = "Untitled"
# Save BlockNote document
diff --git a/surfsense_backend/app/routes/notes_routes.py b/surfsense_backend/app/routes/notes_routes.py
index 1ea8dc345..99a12e803 100644
--- a/surfsense_backend/app/routes/notes_routes.py
+++ b/surfsense_backend/app/routes/notes_routes.py
@@ -97,7 +97,10 @@ async def create_note(
)
-@router.get("/search-spaces/{search_space_id}/notes", response_model=PaginatedResponse[DocumentRead])
+@router.get(
+ "/search-spaces/{search_space_id}/notes",
+ response_model=PaginatedResponse[DocumentRead],
+)
async def list_notes(
search_space_id: int,
skip: int | None = None,
@@ -130,10 +133,12 @@ async def list_notes(
# Get total count
count_query = select(func.count()).select_from(
- select(Document).where(
+ select(Document)
+ .where(
Document.search_space_id == search_space_id,
Document.document_type == DocumentType.NOTE,
- ).subquery()
+ )
+ .subquery()
)
total_result = await session.execute(count_query)
total = total_result.scalar() or 0
@@ -174,13 +179,17 @@ async def list_notes(
]
# Calculate pagination info
- actual_skip = skip if skip is not None else (page * page_size if page is not None else 0)
+ actual_skip = (
+ skip if skip is not None else (page * page_size if page is not None else 0)
+ )
has_more = (actual_skip + len(items)) < total if page_size > 0 else False
return PaginatedResponse(
items=items,
total=total,
- page=page if page is not None else (actual_skip // page_size if page_size > 0 else 0),
+ page=page
+ if page is not None
+ else (actual_skip // page_size if page_size > 0 else 0),
page_size=page_size,
has_more=has_more,
)
@@ -225,4 +234,3 @@ async def delete_note(
await session.commit()
return {"message": "Note deleted successfully", "note_id": note_id}
-
diff --git a/surfsense_web/app/dashboard/[search_space_id]/editor/[documentId]/page.tsx b/surfsense_web/app/dashboard/[search_space_id]/editor/[documentId]/page.tsx
index 3c30cc3ce..b2381694e 100644
--- a/surfsense_web/app/dashboard/[search_space_id]/editor/[documentId]/page.tsx
+++ b/surfsense_web/app/dashboard/[search_space_id]/editor/[documentId]/page.tsx
@@ -1,10 +1,10 @@
"use client";
+import { useQueryClient } from "@tanstack/react-query";
import { AlertCircle, ArrowLeft, FileText, Loader2, Save } from "lucide-react";
import { motion } from "motion/react";
import { useParams, useRouter } from "next/navigation";
import { useEffect, useMemo, useState } from "react";
-import { useQueryClient } from "@tanstack/react-query";
import { toast } from "sonner";
import { BlockNoteEditor } from "@/components/DynamicBlockNoteEditor";
import {
@@ -217,11 +217,7 @@ export default function EditorPage() {
});
// Update URL to reflect the new document ID without navigation
- window.history.replaceState(
- {},
- "",
- `/dashboard/${searchSpaceId}/editor/${note.id}`
- );
+ window.history.replaceState({}, "", `/dashboard/${searchSpaceId}/editor/${note.id}`);
// Update document state to reflect the new ID
setDocument({
document_id: note.id,
@@ -323,7 +319,11 @@ export default function EditorPage() {
{error}
-