mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-28 21:49:40 +02:00
feat: enhance note creation and editing experience
- Added dynamic title extraction from the first block of BlockNote documents for NOTE type. - Updated editor routes to support new note creation with a BlockNote editor. - Implemented unsaved changes dialog for better user experience when navigating away from the editor. - Refactored BlockNoteEditor to ensure the first block is a heading when creating new notes. - Removed the old note creation page in favor of the new streamlined editor experience.
This commit is contained in:
parent
8eceb7a5cb
commit
e1e813702a
6 changed files with 386 additions and 173 deletions
|
|
@ -59,6 +59,7 @@ async def get_editor_content(
|
|||
return {
|
||||
"document_id": document.id,
|
||||
"title": document.title,
|
||||
"document_type": document.document_type.value,
|
||||
"blocknote_document": document.blocknote_document,
|
||||
"updated_at": document.updated_at.isoformat()
|
||||
if document.updated_at
|
||||
|
|
@ -82,6 +83,7 @@ async def get_editor_content(
|
|||
return {
|
||||
"document_id": document.id,
|
||||
"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,
|
||||
}
|
||||
|
|
@ -123,6 +125,7 @@ async def get_editor_content(
|
|||
return {
|
||||
"document_id": document.id,
|
||||
"title": document.title,
|
||||
"document_type": document.document_type.value,
|
||||
"blocknote_document": blocknote_json,
|
||||
"updated_at": document.updated_at.isoformat() if document.updated_at else None,
|
||||
}
|
||||
|
|
@ -168,6 +171,27 @@ async def save_document(
|
|||
if not blocknote_document:
|
||||
raise HTTPException(status_code=400, detail="blocknote_document is required")
|
||||
|
||||
# For NOTE type documents, extract title from first block (heading)
|
||||
if (
|
||||
document.document_type == DocumentType.NOTE
|
||||
and blocknote_document
|
||||
and len(blocknote_document) > 0
|
||||
):
|
||||
first_block = blocknote_document[0]
|
||||
if first_block and first_block.get("content"):
|
||||
# Extract text from first block content
|
||||
title_parts = []
|
||||
for item in first_block["content"]:
|
||||
if isinstance(item, str):
|
||||
title_parts.append(item)
|
||||
elif isinstance(item, dict) and "text" in item:
|
||||
title_parts.append(item["text"])
|
||||
new_title = "".join(title_parts).strip()
|
||||
if new_title:
|
||||
document.title = new_title
|
||||
else:
|
||||
document.title = "Untitled"
|
||||
|
||||
# Save BlockNote document
|
||||
document.blocknote_document = blocknote_document
|
||||
document.updated_at = datetime.now(UTC)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue