feat: Implement note positioning logic and tests for position conversion
This commit is contained in:
@@ -6,6 +6,7 @@ import 'dart:io' show Platform;
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:notas/data/app_database.dart';
|
||||
import 'package:notas/data/api_client.dart';
|
||||
import 'package:notas/data/note_positioning.dart';
|
||||
import 'package:notas/data/sync_models.dart';
|
||||
import 'package:notas/models/note.dart';
|
||||
import 'package:notas/models/category.dart';
|
||||
@@ -91,7 +92,7 @@ class NoteRepository {
|
||||
}
|
||||
|
||||
Future<Note> createNote(Note note) async {
|
||||
await _database.insertNoteAtTop(
|
||||
final int storedPosition = await _database.insertNoteAtTop(
|
||||
NotesCompanion.insert(
|
||||
id: note.id,
|
||||
title: note.title,
|
||||
@@ -106,7 +107,10 @@ class NoteRepository {
|
||||
),
|
||||
);
|
||||
|
||||
return note.copyWith(position: 0, isDirty: true);
|
||||
return note.copyWith(
|
||||
position: fromStoredNotePosition(storedPosition),
|
||||
isDirty: true,
|
||||
);
|
||||
}
|
||||
|
||||
Future<Note> updateNote(Note note) async {
|
||||
@@ -137,7 +141,7 @@ class NoteRepository {
|
||||
isDeleted: false,
|
||||
isPermanentlyDeleted: false,
|
||||
isDirty: true,
|
||||
position: row.sortIndex.toDouble(),
|
||||
position: fromStoredNotePosition(row.sortIndex),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -364,7 +368,7 @@ class NoteRepository {
|
||||
body: isPermanentlyDeleted ? '' : decryptedBody,
|
||||
createdAt: existingNote.createdAt,
|
||||
updatedAt: noteResponse.updatedAt,
|
||||
sortIndex: noteResponse.position.round(),
|
||||
sortIndex: toStoredNotePosition(noteResponse.position),
|
||||
serverVersion: noteResponse.serverVersion,
|
||||
isDeleted: noteResponse.isDeleted,
|
||||
categoryId: isPermanentlyDeleted ? null : noteResponse.categoryId,
|
||||
@@ -382,7 +386,7 @@ class NoteRepository {
|
||||
body: Value(isPermanentlyDeleted ? '' : decryptedBody),
|
||||
createdAt: Value(noteResponse.updatedAt),
|
||||
updatedAt: Value(noteResponse.updatedAt),
|
||||
sortIndex: Value(noteResponse.position.round()),
|
||||
sortIndex: Value(toStoredNotePosition(noteResponse.position)),
|
||||
serverVersion: Value(noteResponse.serverVersion),
|
||||
isDeleted: Value(noteResponse.isDeleted),
|
||||
categoryId: Value(
|
||||
@@ -412,7 +416,7 @@ class NoteRepository {
|
||||
body: row.body,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
position: row.sortIndex.toDouble(),
|
||||
position: fromStoredNotePosition(row.sortIndex),
|
||||
serverVersion: row.serverVersion,
|
||||
isDeleted: row.isDeleted,
|
||||
isPermanentlyDeleted: _isPermanentlyDeleted(row),
|
||||
@@ -585,7 +589,7 @@ Map<String, Object?> _dbNoteToEncryptionInput(DbNote row, int index) {
|
||||
'updatedAt': row.updatedAt.toIso8601String(),
|
||||
'categoryId': row.categoryId,
|
||||
'serverVersion': row.serverVersion,
|
||||
'position': row.sortIndex,
|
||||
'position': fromStoredNotePosition(row.sortIndex),
|
||||
'isDeleted': row.isDeleted,
|
||||
'isPermanentlyDeleted': isPermanentlyDeleted,
|
||||
};
|
||||
@@ -635,7 +639,7 @@ Future<List<Map<String, Object?>>> _encryptNoteBatch(
|
||||
'encryptedTitle': encryptedTitle,
|
||||
'encryptedBody': encryptedBody,
|
||||
'serverVersion': note['serverVersion']! as int,
|
||||
'position': note['position']! as int,
|
||||
'position': (note['position'] as num).toDouble(),
|
||||
'isDeleted': note['isDeleted']! as bool,
|
||||
'isPermanentlyDeleted': isPermanentlyDeleted,
|
||||
'updatedAt': note['updatedAt']! as String,
|
||||
|
||||
Reference in New Issue
Block a user