Enable deleting notes by deleting all their content

This commit is contained in:
2025-04-23 20:56:01 +02:00
parent 6c8340d768
commit e8b9f0ba49
2 changed files with 91 additions and 20 deletions

View File

@@ -30,16 +30,26 @@ Future<Note?> getLatestNote() async {
}
Future<void> createNote(String content) async {
if (content.isEmpty) {
// Trim the content to avoid saving just whitespace
final trimmedContent = content.trim();
if (trimmedContent.isEmpty) {
return;
}
await DB.db.insert('notes', {'content': content});
await DB.db.insert('notes', {'content': trimmedContent});
}
Future<void> updateNote(Note note) async {
// Trim the content to avoid saving just whitespace
final trimmedContent = note.content.trim();
if (trimmedContent.isEmpty) {
// Delete the note if content is empty
await DB.db.delete('notes', where: 'date = ?', whereArgs: [note.date]);
return;
}
await DB.db.update(
'notes',
{'content': note.content},
{'content': trimmedContent},
where: 'date = ?',
whereArgs: [note.date],
);
@@ -61,7 +71,9 @@ Future<Scratch?> getLatestScratch() async {
}
Future<void> createScratch(String content) async {
await DB.db.insert('scratches', {'content': content});
// Trim content but allow empty scratch notes (they might be intentionally cleared)
final trimmedContent = content.trim();
await DB.db.insert('scratches', {'content': trimmedContent});
}
// Get the note immediately older than the given date
@@ -103,6 +115,17 @@ Future<Note?> getNextNote(String currentDate) async {
return getLatestNote();
}
/// Delete a note by its date
Future<bool> deleteNote(String date) async {
final result = await DB.db.delete(
'notes',
where: 'date = ?',
whereArgs: [date],
);
return result > 0; // Return true if a note was deleted
}
// Search notes using full-text search
Future<List<Note>> searchNotes(String query) async {
if (query.isEmpty) {