mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-07-19 15:06:53 +00:00

* chore: remove update attributes * chore: format code * chore: extension for transaction * refactor: add document editor trait * chore: add appflowy_document editor * chore: add document serde * chore: add new document editor * chore: add tests * chore: add more test * chore: add test Co-authored-by: nathan <nathan@appflowy.io>
34 lines
1.1 KiB
Dart
34 lines
1.1 KiB
Dart
import 'package:dartz/dartz.dart';
|
|
import 'package:flowy_sdk/dispatch/dispatch.dart';
|
|
|
|
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
|
|
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
|
import 'package:flowy_sdk/protobuf/flowy-sync/document.pb.dart';
|
|
import 'package:flowy_sdk/protobuf/flowy-document/entities.pb.dart';
|
|
|
|
class DocumentService {
|
|
Future<Either<DocumentSnapshotPB, FlowyError>> openDocument({
|
|
required String docId,
|
|
}) async {
|
|
await FolderEventSetLatestView(ViewIdPB(value: docId)).send();
|
|
|
|
final payload = DocumentIdPB(value: docId);
|
|
return DocumentEventGetDocument(payload).send();
|
|
}
|
|
|
|
Future<Either<Unit, FlowyError>> applyEdit({
|
|
required String docId,
|
|
required String operations,
|
|
}) {
|
|
final payload = EditPayloadPB.create()
|
|
..docId = docId
|
|
..operations = operations;
|
|
return DocumentEventApplyEdit(payload).send();
|
|
}
|
|
|
|
Future<Either<Unit, FlowyError>> closeDocument({required String docId}) {
|
|
final request = ViewIdPB(value: docId);
|
|
return FolderEventCloseView(request).send();
|
|
}
|
|
}
|