feat: Update category server version handling in createCategory and CategoryDialog
This commit is contained in:
@@ -58,12 +58,20 @@ class NoteRepository {
|
|||||||
Future<void> createCategory(Category category) async {
|
Future<void> createCategory(Category category) async {
|
||||||
debugPrint('createCategory called with: ${category.name}');
|
debugPrint('createCategory called with: ${category.name}');
|
||||||
|
|
||||||
|
final DbCategory? existingCategory = await (
|
||||||
|
_database.select(_database.categories)..where((c) => c.id.equals(category.id))
|
||||||
|
).getSingleOrNull();
|
||||||
|
final int effectiveServerVersion = math.max(
|
||||||
|
category.serverVersion,
|
||||||
|
existingCategory?.serverVersion ?? category.serverVersion,
|
||||||
|
);
|
||||||
|
|
||||||
await _database.upsertCategory(
|
await _database.upsertCategory(
|
||||||
CategoriesCompanion.insert(
|
CategoriesCompanion.insert(
|
||||||
id: category.id,
|
id: category.id,
|
||||||
name: category.name,
|
name: category.name,
|
||||||
updatedAt: category.updatedAt,
|
updatedAt: category.updatedAt,
|
||||||
serverVersion: const Value(0),
|
serverVersion: Value(effectiveServerVersion),
|
||||||
isDeleted: const Value(false),
|
isDeleted: const Value(false),
|
||||||
isDirty: const Value(true),
|
isDirty: const Value(true),
|
||||||
colorValue: Value<int?>(category.colorValue),
|
colorValue: Value<int?>(category.colorValue),
|
||||||
|
|||||||
@@ -884,6 +884,7 @@ class _CategoryDialogState extends State<_CategoryDialog> {
|
|||||||
final Category newCategory = Category(
|
final Category newCategory = Category(
|
||||||
id: widget.category?.id,
|
id: widget.category?.id,
|
||||||
name: name,
|
name: name,
|
||||||
|
serverVersion: widget.category?.serverVersion ?? 0,
|
||||||
updatedAt: DateTime.now(),
|
updatedAt: DateTime.now(),
|
||||||
colorValue: _selectedColor?.toARGB32(),
|
colorValue: _selectedColor?.toARGB32(),
|
||||||
iconCodePoint: _selectedIcon?.codePoint,
|
iconCodePoint: _selectedIcon?.codePoint,
|
||||||
|
|||||||
Reference in New Issue
Block a user