don't overwrite note with same name

This commit is contained in:
Alexopus
2025-07-18 17:44:28 +02:00
parent e94314b32b
commit 78c3a65a10
2 changed files with 27 additions and 5 deletions
+12 -3
View File
@@ -16,6 +16,7 @@ This is a ComfyUI extension that adds a server-side notes sidebar for managing m
### Frontend (JavaScript)
- **Extension Module**: `js/extension.js` - ComfyUI extension integration
- **NotesStore Class**: Event-driven state management using EventTarget pattern
- **NotesSidebar Class**: Main UI component managing tabs, content area, and user interactions
- **Styling**: `js/notes-sidebar.css` - Complete UI styling for dark theme integration
@@ -25,10 +26,11 @@ This is a ComfyUI extension that adds a server-side notes sidebar for managing m
2. **File Management**: Notes stored as markdown files with automatic directory creation
3. **UI Architecture**: Tab-based interface with content area and action buttons
4. **Extension Registration**: Properly registers with ComfyUI's extension manager as a sidebar tab
5. **State Management**: Three Maps track content state:
5. **State Management**: Centralized state using NotesStore class with EventTarget pattern:
- `noteContent`: Current content for each note (including unsaved)
- `savedContent`: Last saved content from server
- `unsavedChanges`: Boolean flag for each note's modification state
- Event-driven updates automatically sync UI components
## API Endpoints
@@ -66,6 +68,13 @@ The extension exposes these REST endpoints:
- Save operation clears unsaved state and updates saved content reference
- Delete/rename operations properly clean up tracking maps
### Key Architectural Patterns
- **State Management**: Uses EventTarget pattern for reactive state updates
- **File I/O**: Synchronous file operations in Python with proper error handling
- **API Design**: RESTful endpoints with JSON responses and consistent error handling
- **UI Updates**: Event-driven architecture prevents manual DOM manipulation
- **Extension Integration**: Follows ComfyUI's extension patterns (NODE_CLASS_MAPPINGS, registerExtension)
## Development Commands
### Installation & Setup
@@ -84,8 +93,8 @@ No automated tests defined. Manual testing workflow:
1. Modify Python code in `__init__.py` for backend changes
2. Modify JavaScript in `js/extension.js` for frontend changes
3. Update CSS in `js/notes-sidebar.css` for styling changes
4. Restart ComfyUI to reload the extension (required for Python changes)
5. Refresh browser for JavaScript/CSS changes
4. **Python changes**: Restart ComfyUI completely to reload the extension
5. **JavaScript/CSS changes**: Browser refresh is sufficient
### File Structure
- `notes/` - Storage directory for markdown notes (auto-created)
+15 -2
View File
@@ -434,8 +434,21 @@ class NotesSidebar {
}
async createNewNote() {
const noteName = prompt('Enter note name:');
if (!noteName) return;
let noteName;
// Keep asking for a name until user cancels or enters a unique name
while (true) {
noteName = prompt('Enter note name:');
if (!noteName) return; // User cancelled
// Check if note name already exists
if (this.notes.includes(noteName)) {
alert('A note with this name already exists!');
continue; // Ask again
}
break; // Valid unique name
}
try {
const response = await fetch(`/notes_sidebar/note/${encodeURIComponent(noteName)}`, {