Skip to content

Discard Empty Notes When Navigating Away From the Editor Without Any Content #20

@TheZupZup

Description

@TheZupZup

Overview

Context: NoteEditorScreen (app/lib/screens/note_editor_screen.dart) creates a note in the backend via AppState.createNote() as soon as the user taps the "New note" button — before the user has typed anything. The editor then auto-saves every 2 seconds via a debounce timer.

The problem: If the user taps "New note", immediately presses back without typing anything, a blank note with an empty title is saved to the backend and appears in the notes list. This clutters the list quickly.

What needs to be done

  • In _NoteEditorScreenState.dispose() (or in the back-navigation handler), check whether both the title and the content are still empty (or contain only whitespace)
  • If both are empty and the note was just created (i.e., has never had content), call AppState.deleteNote(noteId) before popping the screen
  • If the auto-save timer is pending when the user navigates back, cancel the timer first, then run the empty check
  • Do not discard a note that previously had content and was then fully cleared — only discard notes that were never given any content after creation
  • In the mobile layout (_MobileLayout in home_screen.dart), ensure the FAB creates the note correctly so the same discard logic applies

Goal

Tapping "New note" and immediately going back leaves zero notes in the list. Only notes with at least a title or a single character of content are persisted.

Where to look

  • app/lib/screens/note_editor_screen.dart:
    • _NoteEditorScreenState_titleController, _contentController, _autoSaveTimer, dispose()
    • Look for WillPopScope or PopScope if present, otherwise add one
  • app/lib/services/app_state.dartdeleteNote(id) already exists

Testing steps

  • Tap "New note", type nothing, press back — verify no new note appears in the list
  • Tap "New note", type a title, press back — verify the note IS saved
  • Tap "New note", type content (no title), press back — verify the note IS saved
  • Create a note with content, delete all text, press back — verify the note is not discarded (it had content before)

Notes

This is a good first issue. The fix lives entirely in note_editor_screen.dart and app_state.dart with no backend changes needed.

Related to: #8, #11

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions