fix: fixed linting for some files

This commit is contained in:
Anish Sarkar 2025-12-16 20:25:50 +05:30
parent 82d8320928
commit e8e393a0d5
4 changed files with 39 additions and 17 deletions

View file

@ -85,7 +85,9 @@ async def get_editor_content(
"title": document.title, "title": document.title,
"document_type": document.document_type.value, "document_type": document.document_type.value,
"blocknote_document": empty_blocknote, "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) # 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 and len(blocknote_document) > 0
): ):
first_block = 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 # Extract text from first block content
# Match the frontend extractTitleFromBlockNote logic exactly
title_parts = [] title_parts = []
for item in first_block["content"]: for item in first_block["content"]:
if isinstance(item, str): if isinstance(item, str):
title_parts.append(item) 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"]) title_parts.append(item["text"])
new_title = "".join(title_parts).strip() new_title = "".join(title_parts).strip()
if new_title: if new_title:
document.title = new_title document.title = new_title
else: else:
# Only set to "Untitled" if content exists but is empty
document.title = "Untitled" document.title = "Untitled"
# Save BlockNote document # Save BlockNote document

View file

@ -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( async def list_notes(
search_space_id: int, search_space_id: int,
skip: int | None = None, skip: int | None = None,
@ -130,10 +133,12 @@ async def list_notes(
# Get total count # Get total count
count_query = select(func.count()).select_from( count_query = select(func.count()).select_from(
select(Document).where( select(Document)
.where(
Document.search_space_id == search_space_id, Document.search_space_id == search_space_id,
Document.document_type == DocumentType.NOTE, Document.document_type == DocumentType.NOTE,
).subquery() )
.subquery()
) )
total_result = await session.execute(count_query) total_result = await session.execute(count_query)
total = total_result.scalar() or 0 total = total_result.scalar() or 0
@ -174,13 +179,17 @@ async def list_notes(
] ]
# Calculate pagination info # 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 has_more = (actual_skip + len(items)) < total if page_size > 0 else False
return PaginatedResponse( return PaginatedResponse(
items=items, items=items,
total=total, 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, page_size=page_size,
has_more=has_more, has_more=has_more,
) )
@ -225,4 +234,3 @@ async def delete_note(
await session.commit() await session.commit()
return {"message": "Note deleted successfully", "note_id": note_id} return {"message": "Note deleted successfully", "note_id": note_id}

View file

@ -1,10 +1,10 @@
"use client"; "use client";
import { useQueryClient } from "@tanstack/react-query";
import { AlertCircle, ArrowLeft, FileText, Loader2, Save } from "lucide-react"; import { AlertCircle, ArrowLeft, FileText, Loader2, Save } from "lucide-react";
import { motion } from "motion/react"; import { motion } from "motion/react";
import { useParams, useRouter } from "next/navigation"; import { useParams, useRouter } from "next/navigation";
import { useEffect, useMemo, useState } from "react"; import { useEffect, useMemo, useState } from "react";
import { useQueryClient } from "@tanstack/react-query";
import { toast } from "sonner"; import { toast } from "sonner";
import { BlockNoteEditor } from "@/components/DynamicBlockNoteEditor"; import { BlockNoteEditor } from "@/components/DynamicBlockNoteEditor";
import { import {
@ -217,11 +217,7 @@ export default function EditorPage() {
}); });
// Update URL to reflect the new document ID without navigation // Update URL to reflect the new document ID without navigation
window.history.replaceState( window.history.replaceState({}, "", `/dashboard/${searchSpaceId}/editor/${note.id}`);
{},
"",
`/dashboard/${searchSpaceId}/editor/${note.id}`
);
// Update document state to reflect the new ID // Update document state to reflect the new ID
setDocument({ setDocument({
document_id: note.id, document_id: note.id,
@ -323,7 +319,11 @@ export default function EditorPage() {
<CardDescription>{error}</CardDescription> <CardDescription>{error}</CardDescription>
</CardHeader> </CardHeader>
<CardContent> <CardContent>
<Button onClick={() => router.push(`/dashboard/${searchSpaceId}/researcher`)} variant="outline" className="gap-2"> <Button
onClick={() => router.push(`/dashboard/${searchSpaceId}/researcher`)}
variant="outline"
className="gap-2"
>
<ArrowLeft className="h-4 w-4" /> <ArrowLeft className="h-4 w-4" />
Back Back
</Button> </Button>