From 95c3e6fc38283f939044cd176f1e60f592663d01 Mon Sep 17 00:00:00 2001 From: Marcos Date: Thu, 21 May 2026 12:01:44 +0200 Subject: [PATCH] feat: Update category deletion logic to reset related notes and track changes --- lib/data/app_database.dart | 6 +++++- lib/data/note_repository.dart | 5 +++++ lib/data/sync_models.dart | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/data/app_database.dart b/lib/data/app_database.dart index ac0ecaf..1c8484c 100644 --- a/lib/data/app_database.dart +++ b/lib/data/app_database.dart @@ -86,7 +86,11 @@ class AppDatabase extends _$AppDatabase { Future deleteCategory(String id) { return (update(categories)..where((c) => c.id.equals(id))).write( - CategoriesCompanion(isDeleted: Value(true)), + CategoriesCompanion( + isDeleted: const Value(true), + updatedAt: Value(DateTime.now()), + isDirty: const Value(true), + ), ); } diff --git a/lib/data/note_repository.dart b/lib/data/note_repository.dart index e6c2226..ef795fa 100644 --- a/lib/data/note_repository.dart +++ b/lib/data/note_repository.dart @@ -87,6 +87,11 @@ class NoteRepository { Future deleteCategory(String id) async { await _database.deleteCategory(id); + + await _database.customStatement( + 'UPDATE notes SET category_id = NULL, is_dirty = 1 WHERE category_id = ?', + [id], + ); } Future createNote(Note note) async { diff --git a/lib/data/sync_models.dart b/lib/data/sync_models.dart index fd10126..a4b9196 100644 --- a/lib/data/sync_models.dart +++ b/lib/data/sync_models.dart @@ -258,6 +258,7 @@ class SyncCategoryResponse { colorValue: colorValue, iconCodePoint: iconCodePoint, updatedAt: updatedAt, + isDirty: false, ); } }