create local file when create view with type doc

This commit is contained in:
appflowy 2021-07-23 16:45:29 +08:00
parent 36e338ddde
commit af1c35de45
24 changed files with 391 additions and 194 deletions

View File

@ -0,0 +1,10 @@
import 'package:flowy_sdk/protobuf/flowy-editor/doc_create.pb.dart';
import 'package:dartz/dartz.dart';
import 'package:flowy_sdk/protobuf/flowy-editor/errors.pb.dart';
abstract class IDoc {
Future<Either<DocDescription, EditorError>> createDoc();
Future<Either<Doc, EditorError>> readDoc();
Future<Either<Unit, EditorError>> updateDoc();
Future<Either<Unit, EditorError>> closeDoc();
}

View File

@ -1,5 +0,0 @@
import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart';
abstract class IPageStack {
void setPageContext(HomeStackView context);
}

View File

@ -1,9 +1,9 @@
import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart';
import 'package:app_flowy/workspace/infrastructure/repos/doc_repo.dart';
import 'package:dartz/dartz.dart'; import 'package:dartz/dartz.dart';
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
import 'package:app_flowy/workspace/domain/i_app.dart'; import 'package:app_flowy/workspace/domain/i_app.dart';
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
export 'package:app_flowy/workspace/domain/i_app.dart'; export 'package:app_flowy/workspace/domain/i_app.dart';
class IAppImpl extends IApp { class IAppImpl extends IApp {
@ -20,7 +20,23 @@ class IAppImpl extends IApp {
@override @override
Future<Either<View, WorkspaceError>> createView( Future<Either<View, WorkspaceError>> createView(
{required String name, String? desc, required ViewType viewType}) { {required String name, String? desc, required ViewType viewType}) {
return repo.createView(name, desc ?? "", viewType); return repo.createView(name, desc ?? "", viewType).then((result) {
return result.fold(
(view) => _createDoc(view),
(r) => right(r),
);
});
}
Future<Either<View, WorkspaceError>> _createDoc(View view) async {
switch (view.viewType) {
case ViewType.Doc:
final docRepo = DocRepository(docId: view.id);
final result = await docRepo.createDoc(name: view.name, desc: "");
return result.fold((l) => left(view), (r) => left(view));
default:
return left(view);
}
} }
} }

View File

@ -0,0 +1,32 @@
import 'package:dartz/dartz.dart';
import 'package:flowy_sdk/dispatch/dispatch.dart';
import 'package:flowy_sdk/protobuf/flowy-editor/doc_create.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-editor/doc_modify.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-editor/doc_query.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-editor/errors.pb.dart';
class DocRepository {
final String docId;
DocRepository({
required this.docId,
});
Future<Either<DocDescription, EditorError>> createDoc(
{required String name, String? desc}) {
final request = CreateDocRequest(id: docId, name: name, desc: desc);
return EditorEventCreateDoc(request).send();
}
Future<Either<Doc, EditorError>> readDoc() {
final request = QueryDocRequest.create()..docId = docId;
return EditorEventReadDoc(request).send();
}
Future<Either<Unit, EditorError>> updateDoc(
{String? name, String? desc, String? text}) {
final request = UpdateDocRequest(id: docId, name: name, text: text);
return EditorEventUpdateDoc(request).send();
}
}

View File

@ -2,6 +2,57 @@
/// Auto gen code from rust ast, do not edit /// Auto gen code from rust ast, do not edit
part of 'dispatch.dart'; part of 'dispatch.dart';
class EditorEventCreateDoc {
CreateDocRequest request;
EditorEventCreateDoc(this.request);
Future<Either<DocDescription, EditorError>> send() {
final request = FFIRequest.create()
..event = EditorEvent.CreateDoc.toString()
..payload = requestToBytes(this.request);
return Dispatch.asyncRequest(request)
.then((bytesResult) => bytesResult.fold(
(okBytes) => left(DocDescription.fromBuffer(okBytes)),
(errBytes) => right(EditorError.fromBuffer(errBytes)),
));
}
}
class EditorEventUpdateDoc {
UpdateDocRequest request;
EditorEventUpdateDoc(this.request);
Future<Either<Unit, EditorError>> send() {
final request = FFIRequest.create()
..event = EditorEvent.UpdateDoc.toString()
..payload = requestToBytes(this.request);
return Dispatch.asyncRequest(request)
.then((bytesResult) => bytesResult.fold(
(bytes) => left(unit),
(errBytes) => right(EditorError.fromBuffer(errBytes)),
));
}
}
class EditorEventReadDoc {
QueryDocRequest request;
EditorEventReadDoc(this.request);
Future<Either<Doc, EditorError>> send() {
final request = FFIRequest.create()
..event = EditorEvent.ReadDoc.toString()
..payload = requestToBytes(this.request);
return Dispatch.asyncRequest(request)
.then((bytesResult) => bytesResult.fold(
(okBytes) => left(Doc.fromBuffer(okBytes)),
(errBytes) => right(EditorError.fromBuffer(errBytes)),
));
}
}
class WorkspaceEventCreateWorkspace { class WorkspaceEventCreateWorkspace {
CreateWorkspaceRequest request; CreateWorkspaceRequest request;
WorkspaceEventCreateWorkspace(this.request); WorkspaceEventCreateWorkspace(this.request);
@ -13,8 +64,8 @@ class WorkspaceEventCreateWorkspace {
return Dispatch.asyncRequest(request) return Dispatch.asyncRequest(request)
.then((bytesResult) => bytesResult.fold( .then((bytesResult) => bytesResult.fold(
(okBytes) => left(Workspace.fromBuffer(okBytes)), (okBytes) => left(Workspace.fromBuffer(okBytes)),
(errBytes) => right(WorkspaceError.fromBuffer(errBytes)), (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),
)); ));
} }
} }
@ -44,8 +95,8 @@ class WorkspaceEventGetWorkspace {
return Dispatch.asyncRequest(request) return Dispatch.asyncRequest(request)
.then((bytesResult) => bytesResult.fold( .then((bytesResult) => bytesResult.fold(
(okBytes) => left(Workspace.fromBuffer(okBytes)), (okBytes) => left(Workspace.fromBuffer(okBytes)),
(errBytes) => right(WorkspaceError.fromBuffer(errBytes)), (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),
)); ));
} }
} }
@ -61,8 +112,8 @@ class WorkspaceEventCreateApp {
return Dispatch.asyncRequest(request) return Dispatch.asyncRequest(request)
.then((bytesResult) => bytesResult.fold( .then((bytesResult) => bytesResult.fold(
(okBytes) => left(App.fromBuffer(okBytes)), (okBytes) => left(App.fromBuffer(okBytes)),
(errBytes) => right(WorkspaceError.fromBuffer(errBytes)), (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),
)); ));
} }
} }
@ -78,8 +129,8 @@ class WorkspaceEventGetApp {
return Dispatch.asyncRequest(request) return Dispatch.asyncRequest(request)
.then((bytesResult) => bytesResult.fold( .then((bytesResult) => bytesResult.fold(
(okBytes) => left(App.fromBuffer(okBytes)), (okBytes) => left(App.fromBuffer(okBytes)),
(errBytes) => right(WorkspaceError.fromBuffer(errBytes)), (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),
)); ));
} }
} }
@ -95,8 +146,8 @@ class WorkspaceEventCreateView {
return Dispatch.asyncRequest(request) return Dispatch.asyncRequest(request)
.then((bytesResult) => bytesResult.fold( .then((bytesResult) => bytesResult.fold(
(okBytes) => left(View.fromBuffer(okBytes)), (okBytes) => left(View.fromBuffer(okBytes)),
(errBytes) => right(WorkspaceError.fromBuffer(errBytes)), (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),
)); ));
} }
} }
@ -126,8 +177,8 @@ class UserEventSignIn {
return Dispatch.asyncRequest(request) return Dispatch.asyncRequest(request)
.then((bytesResult) => bytesResult.fold( .then((bytesResult) => bytesResult.fold(
(okBytes) => left(UserDetail.fromBuffer(okBytes)), (okBytes) => left(UserDetail.fromBuffer(okBytes)),
(errBytes) => right(UserError.fromBuffer(errBytes)), (errBytes) => right(UserError.fromBuffer(errBytes)),
)); ));
} }
} }
@ -143,8 +194,8 @@ class UserEventSignUp {
return Dispatch.asyncRequest(request) return Dispatch.asyncRequest(request)
.then((bytesResult) => bytesResult.fold( .then((bytesResult) => bytesResult.fold(
(okBytes) => left(UserDetail.fromBuffer(okBytes)), (okBytes) => left(UserDetail.fromBuffer(okBytes)),
(errBytes) => right(UserError.fromBuffer(errBytes)), (errBytes) => right(UserError.fromBuffer(errBytes)),
)); ));
} }
} }
@ -174,8 +225,8 @@ class UserEventUpdateUser {
return Dispatch.asyncRequest(request) return Dispatch.asyncRequest(request)
.then((bytesResult) => bytesResult.fold( .then((bytesResult) => bytesResult.fold(
(okBytes) => left(UserDetail.fromBuffer(okBytes)), (okBytes) => left(UserDetail.fromBuffer(okBytes)),
(errBytes) => right(UserError.fromBuffer(errBytes)), (errBytes) => right(UserError.fromBuffer(errBytes)),
)); ));
} }
} }

View File

@ -13,6 +13,7 @@ import 'package:flowy_sdk/ffi.dart' as ffi;
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart'; import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart';
import 'package:flowy_sdk/protobuf/dart-ffi/protobuf.dart'; import 'package:flowy_sdk/protobuf/dart-ffi/protobuf.dart';
import 'package:flowy_sdk/protobuf/flowy-workspace/protobuf.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/protobuf.dart';
import 'package:flowy_sdk/protobuf/flowy-editor/protobuf.dart';
// ignore: unused_import // ignore: unused_import
import 'package:flowy_sdk/protobuf/flowy-infra/protobuf.dart'; import 'package:flowy_sdk/protobuf/flowy-infra/protobuf.dart';
import 'package:protobuf/protobuf.dart'; import 'package:protobuf/protobuf.dart';

View File

@ -14,6 +14,7 @@ class CreateDocRequest extends $pb.GeneratedMessage {
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id') ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id')
..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name')
..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc') ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc')
..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'text')
..hasRequiredFields = false ..hasRequiredFields = false
; ;
@ -22,6 +23,7 @@ class CreateDocRequest extends $pb.GeneratedMessage {
$core.String? id, $core.String? id,
$core.String? name, $core.String? name,
$core.String? desc, $core.String? desc,
$core.String? text,
}) { }) {
final _result = create(); final _result = create();
if (id != null) { if (id != null) {
@ -33,6 +35,9 @@ class CreateDocRequest extends $pb.GeneratedMessage {
if (desc != null) { if (desc != null) {
_result.desc = desc; _result.desc = desc;
} }
if (text != null) {
_result.text = text;
}
return _result; return _result;
} }
factory CreateDocRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); factory CreateDocRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
@ -82,6 +87,15 @@ class CreateDocRequest extends $pb.GeneratedMessage {
$core.bool hasDesc() => $_has(2); $core.bool hasDesc() => $_has(2);
@$pb.TagNumber(3) @$pb.TagNumber(3)
void clearDesc() => clearField(3); void clearDesc() => clearField(3);
@$pb.TagNumber(4)
$core.String get text => $_getSZ(3);
@$pb.TagNumber(4)
set text($core.String v) { $_setString(3, v); }
@$pb.TagNumber(4)
$core.bool hasText() => $_has(3);
@$pb.TagNumber(4)
void clearText() => clearField(4);
} }
class DocDescription extends $pb.GeneratedMessage { class DocDescription extends $pb.GeneratedMessage {
@ -176,21 +190,21 @@ class DocDescription extends $pb.GeneratedMessage {
class Doc extends $pb.GeneratedMessage { class Doc extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'Doc', createEmptyInstance: create) static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'Doc', createEmptyInstance: create)
..aOM<DocDescription>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc', subBuilder: DocDescription.create) ..aOM<DocDescription>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc', subBuilder: DocDescription.create)
..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'content') ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'text')
..hasRequiredFields = false ..hasRequiredFields = false
; ;
Doc._() : super(); Doc._() : super();
factory Doc({ factory Doc({
DocDescription? desc, DocDescription? desc,
$core.String? content, $core.String? text,
}) { }) {
final _result = create(); final _result = create();
if (desc != null) { if (desc != null) {
_result.desc = desc; _result.desc = desc;
} }
if (content != null) { if (text != null) {
_result.content = content; _result.text = text;
} }
return _result; return _result;
} }
@ -227,12 +241,12 @@ class Doc extends $pb.GeneratedMessage {
DocDescription ensureDesc() => $_ensure(0); DocDescription ensureDesc() => $_ensure(0);
@$pb.TagNumber(2) @$pb.TagNumber(2)
$core.String get content => $_getSZ(1); $core.String get text => $_getSZ(1);
@$pb.TagNumber(2) @$pb.TagNumber(2)
set content($core.String v) { $_setString(1, v); } set text($core.String v) { $_setString(1, v); }
@$pb.TagNumber(2) @$pb.TagNumber(2)
$core.bool hasContent() => $_has(1); $core.bool hasText() => $_has(1);
@$pb.TagNumber(2) @$pb.TagNumber(2)
void clearContent() => clearField(2); void clearText() => clearField(2);
} }

View File

@ -15,11 +15,12 @@ const CreateDocRequest$json = const {
const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'}, const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'},
const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'}, const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'},
const {'1': 'desc', '3': 3, '4': 1, '5': 9, '10': 'desc'}, const {'1': 'desc', '3': 3, '4': 1, '5': 9, '10': 'desc'},
const {'1': 'text', '3': 4, '4': 1, '5': 9, '10': 'text'},
], ],
}; };
/// Descriptor for `CreateDocRequest`. Decode as a `google.protobuf.DescriptorProto`. /// Descriptor for `CreateDocRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List createDocRequestDescriptor = $convert.base64Decode('ChBDcmVhdGVEb2NSZXF1ZXN0Eg4KAmlkGAEgASgJUgJpZBISCgRuYW1lGAIgASgJUgRuYW1lEhIKBGRlc2MYAyABKAlSBGRlc2M='); final $typed_data.Uint8List createDocRequestDescriptor = $convert.base64Decode('ChBDcmVhdGVEb2NSZXF1ZXN0Eg4KAmlkGAEgASgJUgJpZBISCgRuYW1lGAIgASgJUgRuYW1lEhIKBGRlc2MYAyABKAlSBGRlc2MSEgoEdGV4dBgEIAEoCVIEdGV4dA==');
@$core.Deprecated('Use docDescriptionDescriptor instead') @$core.Deprecated('Use docDescriptionDescriptor instead')
const DocDescription$json = const { const DocDescription$json = const {
'1': 'DocDescription', '1': 'DocDescription',
@ -38,9 +39,9 @@ const Doc$json = const {
'1': 'Doc', '1': 'Doc',
'2': const [ '2': const [
const {'1': 'desc', '3': 1, '4': 1, '5': 11, '6': '.DocDescription', '10': 'desc'}, const {'1': 'desc', '3': 1, '4': 1, '5': 11, '6': '.DocDescription', '10': 'desc'},
const {'1': 'content', '3': 2, '4': 1, '5': 9, '10': 'content'}, const {'1': 'text', '3': 2, '4': 1, '5': 9, '10': 'text'},
], ],
}; };
/// Descriptor for `Doc`. Decode as a `google.protobuf.DescriptorProto`. /// Descriptor for `Doc`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List docDescriptor = $convert.base64Decode('CgNEb2MSIwoEZGVzYxgBIAEoCzIPLkRvY0Rlc2NyaXB0aW9uUgRkZXNjEhgKB2NvbnRlbnQYAiABKAlSB2NvbnRlbnQ='); final $typed_data.Uint8List docDescriptor = $convert.base64Decode('CgNEb2MSIwoEZGVzYxgBIAEoCzIPLkRvY0Rlc2NyaXB0aW9uUgRkZXNjEhIKBHRleHQYAiABKAlSBHRleHQ=');

View File

@ -19,8 +19,8 @@ enum UpdateDocRequest_OneOfDesc {
notSet notSet
} }
enum UpdateDocRequest_OneOfContent { enum UpdateDocRequest_OneOfText {
content, text,
notSet notSet
} }
@ -33,9 +33,9 @@ class UpdateDocRequest extends $pb.GeneratedMessage {
3 : UpdateDocRequest_OneOfDesc.desc, 3 : UpdateDocRequest_OneOfDesc.desc,
0 : UpdateDocRequest_OneOfDesc.notSet 0 : UpdateDocRequest_OneOfDesc.notSet
}; };
static const $core.Map<$core.int, UpdateDocRequest_OneOfContent> _UpdateDocRequest_OneOfContentByTag = { static const $core.Map<$core.int, UpdateDocRequest_OneOfText> _UpdateDocRequest_OneOfTextByTag = {
4 : UpdateDocRequest_OneOfContent.content, 4 : UpdateDocRequest_OneOfText.text,
0 : UpdateDocRequest_OneOfContent.notSet 0 : UpdateDocRequest_OneOfText.notSet
}; };
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UpdateDocRequest', createEmptyInstance: create) static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UpdateDocRequest', createEmptyInstance: create)
..oo(0, [2]) ..oo(0, [2])
@ -44,7 +44,7 @@ class UpdateDocRequest extends $pb.GeneratedMessage {
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id') ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id')
..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name')
..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc') ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc')
..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'content') ..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'text')
..hasRequiredFields = false ..hasRequiredFields = false
; ;
@ -53,7 +53,7 @@ class UpdateDocRequest extends $pb.GeneratedMessage {
$core.String? id, $core.String? id,
$core.String? name, $core.String? name,
$core.String? desc, $core.String? desc,
$core.String? content, $core.String? text,
}) { }) {
final _result = create(); final _result = create();
if (id != null) { if (id != null) {
@ -65,8 +65,8 @@ class UpdateDocRequest extends $pb.GeneratedMessage {
if (desc != null) { if (desc != null) {
_result.desc = desc; _result.desc = desc;
} }
if (content != null) { if (text != null) {
_result.content = content; _result.text = text;
} }
return _result; return _result;
} }
@ -97,8 +97,8 @@ class UpdateDocRequest extends $pb.GeneratedMessage {
UpdateDocRequest_OneOfDesc whichOneOfDesc() => _UpdateDocRequest_OneOfDescByTag[$_whichOneof(1)]!; UpdateDocRequest_OneOfDesc whichOneOfDesc() => _UpdateDocRequest_OneOfDescByTag[$_whichOneof(1)]!;
void clearOneOfDesc() => clearField($_whichOneof(1)); void clearOneOfDesc() => clearField($_whichOneof(1));
UpdateDocRequest_OneOfContent whichOneOfContent() => _UpdateDocRequest_OneOfContentByTag[$_whichOneof(2)]!; UpdateDocRequest_OneOfText whichOneOfText() => _UpdateDocRequest_OneOfTextByTag[$_whichOneof(2)]!;
void clearOneOfContent() => clearField($_whichOneof(2)); void clearOneOfText() => clearField($_whichOneof(2));
@$pb.TagNumber(1) @$pb.TagNumber(1)
$core.String get id => $_getSZ(0); $core.String get id => $_getSZ(0);
@ -128,12 +128,12 @@ class UpdateDocRequest extends $pb.GeneratedMessage {
void clearDesc() => clearField(3); void clearDesc() => clearField(3);
@$pb.TagNumber(4) @$pb.TagNumber(4)
$core.String get content => $_getSZ(3); $core.String get text => $_getSZ(3);
@$pb.TagNumber(4) @$pb.TagNumber(4)
set content($core.String v) { $_setString(3, v); } set text($core.String v) { $_setString(3, v); }
@$pb.TagNumber(4) @$pb.TagNumber(4)
$core.bool hasContent() => $_has(3); $core.bool hasText() => $_has(3);
@$pb.TagNumber(4) @$pb.TagNumber(4)
void clearContent() => clearField(4); void clearText() => clearField(4);
} }

View File

@ -15,14 +15,14 @@ const UpdateDocRequest$json = const {
const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'}, const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'},
const {'1': 'name', '3': 2, '4': 1, '5': 9, '9': 0, '10': 'name'}, const {'1': 'name', '3': 2, '4': 1, '5': 9, '9': 0, '10': 'name'},
const {'1': 'desc', '3': 3, '4': 1, '5': 9, '9': 1, '10': 'desc'}, const {'1': 'desc', '3': 3, '4': 1, '5': 9, '9': 1, '10': 'desc'},
const {'1': 'content', '3': 4, '4': 1, '5': 9, '9': 2, '10': 'content'}, const {'1': 'text', '3': 4, '4': 1, '5': 9, '9': 2, '10': 'text'},
], ],
'8': const [ '8': const [
const {'1': 'one_of_name'}, const {'1': 'one_of_name'},
const {'1': 'one_of_desc'}, const {'1': 'one_of_desc'},
const {'1': 'one_of_content'}, const {'1': 'one_of_text'},
], ],
}; };
/// Descriptor for `UpdateDocRequest`. Decode as a `google.protobuf.DescriptorProto`. /// Descriptor for `UpdateDocRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List updateDocRequestDescriptor = $convert.base64Decode('ChBVcGRhdGVEb2NSZXF1ZXN0Eg4KAmlkGAEgASgJUgJpZBIUCgRuYW1lGAIgASgJSABSBG5hbWUSFAoEZGVzYxgDIAEoCUgBUgRkZXNjEhoKB2NvbnRlbnQYBCABKAlIAlIHY29udGVudEINCgtvbmVfb2ZfbmFtZUINCgtvbmVfb2ZfZGVzY0IQCg5vbmVfb2ZfY29udGVudA=='); final $typed_data.Uint8List updateDocRequestDescriptor = $convert.base64Decode('ChBVcGRhdGVEb2NSZXF1ZXN0Eg4KAmlkGAEgASgJUgJpZBIUCgRuYW1lGAIgASgJSABSBG5hbWUSFAoEZGVzYxgDIAEoCUgBUgRkZXNjEhQKBHRleHQYBCABKAlIAlIEdGV4dEINCgtvbmVfb2ZfbmFtZUINCgtvbmVfb2ZfZGVzY0INCgtvbmVfb2ZfdGV4dA==');

View File

@ -19,6 +19,7 @@ unicode-segmentation = "1.7.1"
lazy_static = "1.4.0" lazy_static = "1.4.0"
log = "0.4.14" log = "0.4.14"
tokio = {version = "1.6.0", features = ["sync"]} tokio = {version = "1.6.0", features = ["sync"]}
tracing = { version = "0.1", features = ["log"] }
[dev-dependencies] [dev-dependencies]
flowy-test = { path = "../flowy-test" } flowy-test = { path = "../flowy-test" }

View File

@ -15,12 +15,16 @@ pub struct CreateDocRequest {
#[pb(index = 3)] #[pb(index = 3)]
pub desc: String, pub desc: String,
#[pb(index = 4)]
pub text: String,
} }
pub struct CreateDocParams { pub struct CreateDocParams {
pub id: String, pub id: String,
pub name: String, pub name: String,
pub desc: String, pub desc: String,
pub text: String,
} }
impl TryInto<CreateDocParams> for CreateDocRequest { impl TryInto<CreateDocParams> for CreateDocRequest {
@ -47,6 +51,7 @@ impl TryInto<CreateDocParams> for CreateDocRequest {
id, id,
name, name,
desc: self.desc, desc: self.desc,
text: self.text,
}) })
} }
} }
@ -72,5 +77,5 @@ pub struct Doc {
pub desc: DocDescription, pub desc: DocDescription,
#[pb(index = 2)] #[pb(index = 2)]
pub content: String, pub text: String,
} }

View File

@ -14,14 +14,14 @@ pub struct UpdateDocRequest {
pub desc: Option<String>, pub desc: Option<String>,
#[pb(index = 4, one_of)] #[pb(index = 4, one_of)]
pub content: Option<String>, pub text: Option<String>,
} }
pub(crate) struct UpdateDocParams { pub(crate) struct UpdateDocParams {
pub(crate) id: String, pub(crate) id: String,
pub(crate) name: Option<String>, pub(crate) name: Option<String>,
pub(crate) desc: Option<String>, pub(crate) desc: Option<String>,
pub(crate) content: Option<String>, pub(crate) text: Option<String>,
} }
impl TryInto<UpdateDocParams> for UpdateDocRequest { impl TryInto<UpdateDocParams> for UpdateDocRequest {
@ -66,7 +66,7 @@ impl TryInto<UpdateDocParams> for UpdateDocRequest {
id, id,
name, name,
desc, desc,
content: self.content, text: self.text,
}) })
} }
} }

View File

@ -7,19 +7,21 @@ use flowy_dispatch::prelude::*;
use std::{convert::TryInto, path::Path, sync::Arc}; use std::{convert::TryInto, path::Path, sync::Arc};
use tokio::sync::RwLock; use tokio::sync::RwLock;
#[tracing::instrument(name = "create_doc", skip(data, controller, manager))]
pub async fn create_doc( pub async fn create_doc(
data: Data<CreateDocRequest>, data: Data<CreateDocRequest>,
controller: Unit<DocController>, controller: Unit<DocController>,
manager: Unit<RwLock<FileManager>>, manager: Unit<RwLock<FileManager>>,
) -> ResponseResult<DocDescription, EditorError> { ) -> ResponseResult<DocDescription, EditorError> {
let params: CreateDocParams = data.into_inner().try_into()?; let params: CreateDocParams = data.into_inner().try_into()?;
let path = manager.read().await.make_file_path(&params.id); let path = manager.write().await.create_file(&params.id, &params.text);
let doc_desc = controller let doc_desc = controller
.create_doc(params, path.to_str().unwrap()) .create_doc(params, path.to_str().unwrap())
.await?; .await?;
response_ok(doc_desc) response_ok(doc_desc)
} }
#[tracing::instrument(name = "read_doc", skip(data, controller, manager))]
pub async fn read_doc( pub async fn read_doc(
data: Data<QueryDocRequest>, data: Data<QueryDocRequest>,
controller: Unit<DocController>, controller: Unit<DocController>,
@ -27,14 +29,15 @@ pub async fn read_doc(
) -> ResponseResult<Doc, EditorError> { ) -> ResponseResult<Doc, EditorError> {
let params: QueryDocParams = data.into_inner().try_into()?; let params: QueryDocParams = data.into_inner().try_into()?;
let desc = controller.read_doc(&params.doc_id).await?; let desc = controller.read_doc(&params.doc_id).await?;
let content = manager let content = manager
.write() .write()
.await .await
.open(Path::new(&desc.path), desc.id.clone())?; .open(Path::new(&desc.path), desc.id.clone())?;
let doc = Doc { desc, content }; response_ok(Doc {
response_ok(doc) desc,
text: content,
})
} }
pub async fn update_doc( pub async fn update_doc(
@ -43,15 +46,13 @@ pub async fn update_doc(
manager: Unit<RwLock<FileManager>>, manager: Unit<RwLock<FileManager>>,
) -> Result<(), EditorError> { ) -> Result<(), EditorError> {
let mut params: UpdateDocParams = data.into_inner().try_into()?; let mut params: UpdateDocParams = data.into_inner().try_into()?;
match params.content.take() {
None => {}, if let Some(s) = params.text.take() {
Some(s) => { let doc_desc = controller.read_doc(&params.id).await?;
let doc_desc = controller.read_doc(&params.id).await?; manager
manager .write()
.write() .await
.await .save(Path::new(&doc_desc.path), &s, params.id.clone());
.save(Path::new(&doc_desc.path), &s, params.id.clone());
},
} }
if params.name.is_some() || params.desc.is_some() { if params.name.is_some() || params.desc.is_some() {

View File

@ -29,6 +29,7 @@ pub struct CreateDocRequest {
pub id: ::std::string::String, pub id: ::std::string::String,
pub name: ::std::string::String, pub name: ::std::string::String,
pub desc: ::std::string::String, pub desc: ::std::string::String,
pub text: ::std::string::String,
// special fields // special fields
pub unknown_fields: ::protobuf::UnknownFields, pub unknown_fields: ::protobuf::UnknownFields,
pub cached_size: ::protobuf::CachedSize, pub cached_size: ::protobuf::CachedSize,
@ -122,6 +123,32 @@ impl CreateDocRequest {
pub fn take_desc(&mut self) -> ::std::string::String { pub fn take_desc(&mut self) -> ::std::string::String {
::std::mem::replace(&mut self.desc, ::std::string::String::new()) ::std::mem::replace(&mut self.desc, ::std::string::String::new())
} }
// string text = 4;
pub fn get_text(&self) -> &str {
&self.text
}
pub fn clear_text(&mut self) {
self.text.clear();
}
// Param is passed by value, moved
pub fn set_text(&mut self, v: ::std::string::String) {
self.text = v;
}
// Mutable pointer to the field.
// If field is not initialized, it is initialized with default value first.
pub fn mut_text(&mut self) -> &mut ::std::string::String {
&mut self.text
}
// Take field
pub fn take_text(&mut self) -> ::std::string::String {
::std::mem::replace(&mut self.text, ::std::string::String::new())
}
} }
impl ::protobuf::Message for CreateDocRequest { impl ::protobuf::Message for CreateDocRequest {
@ -142,6 +169,9 @@ impl ::protobuf::Message for CreateDocRequest {
3 => { 3 => {
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.desc)?; ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.desc)?;
}, },
4 => {
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.text)?;
},
_ => { _ => {
::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
}, },
@ -163,6 +193,9 @@ impl ::protobuf::Message for CreateDocRequest {
if !self.desc.is_empty() { if !self.desc.is_empty() {
my_size += ::protobuf::rt::string_size(3, &self.desc); my_size += ::protobuf::rt::string_size(3, &self.desc);
} }
if !self.text.is_empty() {
my_size += ::protobuf::rt::string_size(4, &self.text);
}
my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
self.cached_size.set(my_size); self.cached_size.set(my_size);
my_size my_size
@ -178,6 +211,9 @@ impl ::protobuf::Message for CreateDocRequest {
if !self.desc.is_empty() { if !self.desc.is_empty() {
os.write_string(3, &self.desc)?; os.write_string(3, &self.desc)?;
} }
if !self.text.is_empty() {
os.write_string(4, &self.text)?;
}
os.write_unknown_fields(self.get_unknown_fields())?; os.write_unknown_fields(self.get_unknown_fields())?;
::std::result::Result::Ok(()) ::std::result::Result::Ok(())
} }
@ -231,6 +267,11 @@ impl ::protobuf::Message for CreateDocRequest {
|m: &CreateDocRequest| { &m.desc }, |m: &CreateDocRequest| { &m.desc },
|m: &mut CreateDocRequest| { &mut m.desc }, |m: &mut CreateDocRequest| { &mut m.desc },
)); ));
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
"text",
|m: &CreateDocRequest| { &m.text },
|m: &mut CreateDocRequest| { &mut m.text },
));
::protobuf::reflect::MessageDescriptor::new_pb_name::<CreateDocRequest>( ::protobuf::reflect::MessageDescriptor::new_pb_name::<CreateDocRequest>(
"CreateDocRequest", "CreateDocRequest",
fields, fields,
@ -250,6 +291,7 @@ impl ::protobuf::Clear for CreateDocRequest {
self.id.clear(); self.id.clear();
self.name.clear(); self.name.clear();
self.desc.clear(); self.desc.clear();
self.text.clear();
self.unknown_fields.clear(); self.unknown_fields.clear();
} }
} }
@ -555,7 +597,7 @@ impl ::protobuf::reflect::ProtobufValue for DocDescription {
pub struct Doc { pub struct Doc {
// message fields // message fields
pub desc: ::protobuf::SingularPtrField<DocDescription>, pub desc: ::protobuf::SingularPtrField<DocDescription>,
pub content: ::std::string::String, pub text: ::std::string::String,
// special fields // special fields
pub unknown_fields: ::protobuf::UnknownFields, pub unknown_fields: ::protobuf::UnknownFields,
pub cached_size: ::protobuf::CachedSize, pub cached_size: ::protobuf::CachedSize,
@ -605,30 +647,30 @@ impl Doc {
self.desc.take().unwrap_or_else(|| DocDescription::new()) self.desc.take().unwrap_or_else(|| DocDescription::new())
} }
// string content = 2; // string text = 2;
pub fn get_content(&self) -> &str { pub fn get_text(&self) -> &str {
&self.content &self.text
} }
pub fn clear_content(&mut self) { pub fn clear_text(&mut self) {
self.content.clear(); self.text.clear();
} }
// Param is passed by value, moved // Param is passed by value, moved
pub fn set_content(&mut self, v: ::std::string::String) { pub fn set_text(&mut self, v: ::std::string::String) {
self.content = v; self.text = v;
} }
// Mutable pointer to the field. // Mutable pointer to the field.
// If field is not initialized, it is initialized with default value first. // If field is not initialized, it is initialized with default value first.
pub fn mut_content(&mut self) -> &mut ::std::string::String { pub fn mut_text(&mut self) -> &mut ::std::string::String {
&mut self.content &mut self.text
} }
// Take field // Take field
pub fn take_content(&mut self) -> ::std::string::String { pub fn take_text(&mut self) -> ::std::string::String {
::std::mem::replace(&mut self.content, ::std::string::String::new()) ::std::mem::replace(&mut self.text, ::std::string::String::new())
} }
} }
@ -650,7 +692,7 @@ impl ::protobuf::Message for Doc {
::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.desc)?; ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.desc)?;
}, },
2 => { 2 => {
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.content)?; ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.text)?;
}, },
_ => { _ => {
::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
@ -668,8 +710,8 @@ impl ::protobuf::Message for Doc {
let len = v.compute_size(); let len = v.compute_size();
my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len;
} }
if !self.content.is_empty() { if !self.text.is_empty() {
my_size += ::protobuf::rt::string_size(2, &self.content); my_size += ::protobuf::rt::string_size(2, &self.text);
} }
my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
self.cached_size.set(my_size); self.cached_size.set(my_size);
@ -682,8 +724,8 @@ impl ::protobuf::Message for Doc {
os.write_raw_varint32(v.get_cached_size())?; os.write_raw_varint32(v.get_cached_size())?;
v.write_to_with_cached_sizes(os)?; v.write_to_with_cached_sizes(os)?;
} }
if !self.content.is_empty() { if !self.text.is_empty() {
os.write_string(2, &self.content)?; os.write_string(2, &self.text)?;
} }
os.write_unknown_fields(self.get_unknown_fields())?; os.write_unknown_fields(self.get_unknown_fields())?;
::std::result::Result::Ok(()) ::std::result::Result::Ok(())
@ -729,9 +771,9 @@ impl ::protobuf::Message for Doc {
|m: &mut Doc| { &mut m.desc }, |m: &mut Doc| { &mut m.desc },
)); ));
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
"content", "text",
|m: &Doc| { &m.content }, |m: &Doc| { &m.text },
|m: &mut Doc| { &mut m.content }, |m: &mut Doc| { &mut m.text },
)); ));
::protobuf::reflect::MessageDescriptor::new_pb_name::<Doc>( ::protobuf::reflect::MessageDescriptor::new_pb_name::<Doc>(
"Doc", "Doc",
@ -750,7 +792,7 @@ impl ::protobuf::Message for Doc {
impl ::protobuf::Clear for Doc { impl ::protobuf::Clear for Doc {
fn clear(&mut self) { fn clear(&mut self) {
self.desc.clear(); self.desc.clear();
self.content.clear(); self.text.clear();
self.unknown_fields.clear(); self.unknown_fields.clear();
} }
} }
@ -768,43 +810,46 @@ impl ::protobuf::reflect::ProtobufValue for Doc {
} }
static file_descriptor_proto_data: &'static [u8] = b"\ static file_descriptor_proto_data: &'static [u8] = b"\
\n\x10doc_create.proto\"J\n\x10CreateDocRequest\x12\x0e\n\x02id\x18\x01\ \n\x10doc_create.proto\"^\n\x10CreateDocRequest\x12\x0e\n\x02id\x18\x01\
\x20\x01(\tR\x02id\x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\x12\ \x20\x01(\tR\x02id\x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\x12\
\n\x04desc\x18\x03\x20\x01(\tR\x04desc\"\\\n\x0eDocDescription\x12\x0e\n\ \n\x04desc\x18\x03\x20\x01(\tR\x04desc\x12\x12\n\x04text\x18\x04\x20\x01\
\x02id\x18\x01\x20\x01(\tR\x02id\x12\x12\n\x04name\x18\x02\x20\x01(\tR\ (\tR\x04text\"\\\n\x0eDocDescription\x12\x0e\n\x02id\x18\x01\x20\x01(\tR\
\x04name\x12\x12\n\x04desc\x18\x03\x20\x01(\tR\x04desc\x12\x12\n\x04path\ \x02id\x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\x12\n\x04desc\
\x18\x04\x20\x01(\tR\x04path\"D\n\x03Doc\x12#\n\x04desc\x18\x01\x20\x01(\ \x18\x03\x20\x01(\tR\x04desc\x12\x12\n\x04path\x18\x04\x20\x01(\tR\x04pa\
\x0b2\x0f.DocDescriptionR\x04desc\x12\x18\n\x07content\x18\x02\x20\x01(\ th\">\n\x03Doc\x12#\n\x04desc\x18\x01\x20\x01(\x0b2\x0f.DocDescriptionR\
\tR\x07contentJ\xc9\x04\n\x06\x12\x04\0\0\x10\x01\n\x08\n\x01\x0c\x12\ \x04desc\x12\x12\n\x04text\x18\x02\x20\x01(\tR\x04textJ\x80\x05\n\x06\
\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x06\x01\n\n\n\x03\x04\0\x01\ \x12\x04\0\0\x11\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\
\x12\x03\x02\x08\x18\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x12\n\x0c\n\ \x04\x02\0\x07\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x18\n\x0b\n\x04\
\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\ \x04\0\x02\0\x12\x03\x03\x04\x12\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\
\x03\x03\x0b\r\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x10\x11\n\x0b\n\ \x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\r\n\x0c\n\x05\x04\0\
\x04\x04\0\x02\x01\x12\x03\x04\x04\x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\ \x02\0\x03\x12\x03\x03\x10\x11\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\
\x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0f\n\x0c\n\ \x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\
\x05\x04\0\x02\x01\x03\x12\x03\x04\x12\x13\n\x0b\n\x04\x04\0\x02\x02\x12\ \x02\x01\x01\x12\x03\x04\x0b\x0f\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\
\x03\x05\x04\x14\n\x0c\n\x05\x04\0\x02\x02\x05\x12\x03\x05\x04\n\n\x0c\n\ \x04\x12\x13\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x04\x14\n\x0c\n\x05\
\x05\x04\0\x02\x02\x01\x12\x03\x05\x0b\x0f\n\x0c\n\x05\x04\0\x02\x02\x03\ \x04\0\x02\x02\x05\x12\x03\x05\x04\n\n\x0c\n\x05\x04\0\x02\x02\x01\x12\
\x12\x03\x05\x12\x13\n\n\n\x02\x04\x01\x12\x04\x07\0\x0c\x01\n\n\n\x03\ \x03\x05\x0b\x0f\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x12\x13\n\x0b\
\x04\x01\x01\x12\x03\x07\x08\x16\n\x0b\n\x04\x04\x01\x02\0\x12\x03\x08\ \n\x04\x04\0\x02\x03\x12\x03\x06\x04\x14\n\x0c\n\x05\x04\0\x02\x03\x05\
\x04\x12\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\x08\x04\n\n\x0c\n\x05\x04\ \x12\x03\x06\x04\n\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x06\x0b\x0f\n\
\x01\x02\0\x01\x12\x03\x08\x0b\r\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\ \x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x06\x12\x13\n\n\n\x02\x04\x01\x12\
\x08\x10\x11\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\t\x04\x14\n\x0c\n\x05\ \x04\x08\0\r\x01\n\n\n\x03\x04\x01\x01\x12\x03\x08\x08\x16\n\x0b\n\x04\
\x04\x01\x02\x01\x05\x12\x03\t\x04\n\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\ \x04\x01\x02\0\x12\x03\t\x04\x12\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\t\
\x03\t\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\t\x12\x13\n\x0b\n\ \x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\t\x0b\r\n\x0c\n\x05\x04\x01\
\x04\x04\x01\x02\x02\x12\x03\n\x04\x14\n\x0c\n\x05\x04\x01\x02\x02\x05\ \x02\0\x03\x12\x03\t\x10\x11\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\n\x04\
\x12\x03\n\x04\n\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\n\x0b\x0f\n\x0c\ \x14\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\n\x04\n\n\x0c\n\x05\x04\x01\
\n\x05\x04\x01\x02\x02\x03\x12\x03\n\x12\x13\n\x0b\n\x04\x04\x01\x02\x03\ \x02\x01\x01\x12\x03\n\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\n\
\x12\x03\x0b\x04\x14\n\x0c\n\x05\x04\x01\x02\x03\x05\x12\x03\x0b\x04\n\n\ \x12\x13\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\x0b\x04\x14\n\x0c\n\x05\x04\
\x0c\n\x05\x04\x01\x02\x03\x01\x12\x03\x0b\x0b\x0f\n\x0c\n\x05\x04\x01\ \x01\x02\x02\x05\x12\x03\x0b\x04\n\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\
\x02\x03\x03\x12\x03\x0b\x12\x13\n\n\n\x02\x04\x02\x12\x04\r\0\x10\x01\n\ \x03\x0b\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\x0b\x12\x13\n\
\n\n\x03\x04\x02\x01\x12\x03\r\x08\x0b\n\x0b\n\x04\x04\x02\x02\0\x12\x03\ \x0b\n\x04\x04\x01\x02\x03\x12\x03\x0c\x04\x14\n\x0c\n\x05\x04\x01\x02\
\x0e\x04\x1c\n\x0c\n\x05\x04\x02\x02\0\x06\x12\x03\x0e\x04\x12\n\x0c\n\ \x03\x05\x12\x03\x0c\x04\n\n\x0c\n\x05\x04\x01\x02\x03\x01\x12\x03\x0c\
\x05\x04\x02\x02\0\x01\x12\x03\x0e\x13\x17\n\x0c\n\x05\x04\x02\x02\0\x03\ \x0b\x0f\n\x0c\n\x05\x04\x01\x02\x03\x03\x12\x03\x0c\x12\x13\n\n\n\x02\
\x12\x03\x0e\x1a\x1b\n\x0b\n\x04\x04\x02\x02\x01\x12\x03\x0f\x04\x17\n\ \x04\x02\x12\x04\x0e\0\x11\x01\n\n\n\x03\x04\x02\x01\x12\x03\x0e\x08\x0b\
\x0c\n\x05\x04\x02\x02\x01\x05\x12\x03\x0f\x04\n\n\x0c\n\x05\x04\x02\x02\ \n\x0b\n\x04\x04\x02\x02\0\x12\x03\x0f\x04\x1c\n\x0c\n\x05\x04\x02\x02\0\
\x01\x01\x12\x03\x0f\x0b\x12\n\x0c\n\x05\x04\x02\x02\x01\x03\x12\x03\x0f\ \x06\x12\x03\x0f\x04\x12\n\x0c\n\x05\x04\x02\x02\0\x01\x12\x03\x0f\x13\
\x15\x16b\x06proto3\ \x17\n\x0c\n\x05\x04\x02\x02\0\x03\x12\x03\x0f\x1a\x1b\n\x0b\n\x04\x04\
\x02\x02\x01\x12\x03\x10\x04\x14\n\x0c\n\x05\x04\x02\x02\x01\x05\x12\x03\
\x10\x04\n\n\x0c\n\x05\x04\x02\x02\x01\x01\x12\x03\x10\x0b\x0f\n\x0c\n\
\x05\x04\x02\x02\x01\x03\x12\x03\x10\x12\x13b\x06proto3\
"; ";
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

View File

@ -30,7 +30,7 @@ pub struct UpdateDocRequest {
// message oneof groups // message oneof groups
pub one_of_name: ::std::option::Option<UpdateDocRequest_oneof_one_of_name>, pub one_of_name: ::std::option::Option<UpdateDocRequest_oneof_one_of_name>,
pub one_of_desc: ::std::option::Option<UpdateDocRequest_oneof_one_of_desc>, pub one_of_desc: ::std::option::Option<UpdateDocRequest_oneof_one_of_desc>,
pub one_of_content: ::std::option::Option<UpdateDocRequest_oneof_one_of_content>, pub one_of_text: ::std::option::Option<UpdateDocRequest_oneof_one_of_text>,
// special fields // special fields
pub unknown_fields: ::protobuf::UnknownFields, pub unknown_fields: ::protobuf::UnknownFields,
pub cached_size: ::protobuf::CachedSize, pub cached_size: ::protobuf::CachedSize,
@ -53,8 +53,8 @@ pub enum UpdateDocRequest_oneof_one_of_desc {
} }
#[derive(Clone,PartialEq,Debug)] #[derive(Clone,PartialEq,Debug)]
pub enum UpdateDocRequest_oneof_one_of_content { pub enum UpdateDocRequest_oneof_one_of_text {
content(::std::string::String), text(::std::string::String),
} }
impl UpdateDocRequest { impl UpdateDocRequest {
@ -186,48 +186,48 @@ impl UpdateDocRequest {
} }
} }
// string content = 4; // string text = 4;
pub fn get_content(&self) -> &str { pub fn get_text(&self) -> &str {
match self.one_of_content { match self.one_of_text {
::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(ref v)) => v, ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(ref v)) => v,
_ => "", _ => "",
} }
} }
pub fn clear_content(&mut self) { pub fn clear_text(&mut self) {
self.one_of_content = ::std::option::Option::None; self.one_of_text = ::std::option::Option::None;
} }
pub fn has_content(&self) -> bool { pub fn has_text(&self) -> bool {
match self.one_of_content { match self.one_of_text {
::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(..)) => true, ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(..)) => true,
_ => false, _ => false,
} }
} }
// Param is passed by value, moved // Param is passed by value, moved
pub fn set_content(&mut self, v: ::std::string::String) { pub fn set_text(&mut self, v: ::std::string::String) {
self.one_of_content = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(v)) self.one_of_text = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(v))
} }
// Mutable pointer to the field. // Mutable pointer to the field.
pub fn mut_content(&mut self) -> &mut ::std::string::String { pub fn mut_text(&mut self) -> &mut ::std::string::String {
if let ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(_)) = self.one_of_content { if let ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(_)) = self.one_of_text {
} else { } else {
self.one_of_content = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(::std::string::String::new())); self.one_of_text = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(::std::string::String::new()));
} }
match self.one_of_content { match self.one_of_text {
::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(ref mut v)) => v, ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(ref mut v)) => v,
_ => panic!(), _ => panic!(),
} }
} }
// Take field // Take field
pub fn take_content(&mut self) -> ::std::string::String { pub fn take_text(&mut self) -> ::std::string::String {
if self.has_content() { if self.has_text() {
match self.one_of_content.take() { match self.one_of_text.take() {
::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(v)) => v, ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(v)) => v,
_ => panic!(), _ => panic!(),
} }
} else { } else {
@ -264,7 +264,7 @@ impl ::protobuf::Message for UpdateDocRequest {
if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited {
return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));
} }
self.one_of_content = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(is.read_string()?)); self.one_of_text = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(is.read_string()?));
}, },
_ => { _ => {
::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
@ -295,9 +295,9 @@ impl ::protobuf::Message for UpdateDocRequest {
}, },
}; };
} }
if let ::std::option::Option::Some(ref v) = self.one_of_content { if let ::std::option::Option::Some(ref v) = self.one_of_text {
match v { match v {
&UpdateDocRequest_oneof_one_of_content::content(ref v) => { &UpdateDocRequest_oneof_one_of_text::text(ref v) => {
my_size += ::protobuf::rt::string_size(4, &v); my_size += ::protobuf::rt::string_size(4, &v);
}, },
}; };
@ -325,9 +325,9 @@ impl ::protobuf::Message for UpdateDocRequest {
}, },
}; };
} }
if let ::std::option::Option::Some(ref v) = self.one_of_content { if let ::std::option::Option::Some(ref v) = self.one_of_text {
match v { match v {
&UpdateDocRequest_oneof_one_of_content::content(ref v) => { &UpdateDocRequest_oneof_one_of_text::text(ref v) => {
os.write_string(4, v)?; os.write_string(4, v)?;
}, },
}; };
@ -386,9 +386,9 @@ impl ::protobuf::Message for UpdateDocRequest {
UpdateDocRequest::get_desc, UpdateDocRequest::get_desc,
)); ));
fields.push(::protobuf::reflect::accessor::make_singular_string_accessor::<_>( fields.push(::protobuf::reflect::accessor::make_singular_string_accessor::<_>(
"content", "text",
UpdateDocRequest::has_content, UpdateDocRequest::has_text,
UpdateDocRequest::get_content, UpdateDocRequest::get_text,
)); ));
::protobuf::reflect::MessageDescriptor::new_pb_name::<UpdateDocRequest>( ::protobuf::reflect::MessageDescriptor::new_pb_name::<UpdateDocRequest>(
"UpdateDocRequest", "UpdateDocRequest",
@ -409,7 +409,7 @@ impl ::protobuf::Clear for UpdateDocRequest {
self.id.clear(); self.id.clear();
self.one_of_name = ::std::option::Option::None; self.one_of_name = ::std::option::Option::None;
self.one_of_desc = ::std::option::Option::None; self.one_of_desc = ::std::option::Option::None;
self.one_of_content = ::std::option::Option::None; self.one_of_text = ::std::option::Option::None;
self.unknown_fields.clear(); self.unknown_fields.clear();
} }
} }
@ -427,27 +427,27 @@ impl ::protobuf::reflect::ProtobufValue for UpdateDocRequest {
} }
static file_descriptor_proto_data: &'static [u8] = b"\ static file_descriptor_proto_data: &'static [u8] = b"\
\n\x10doc_modify.proto\"\x9a\x01\n\x10UpdateDocRequest\x12\x0e\n\x02id\ \n\x10doc_modify.proto\"\x91\x01\n\x10UpdateDocRequest\x12\x0e\n\x02id\
\x18\x01\x20\x01(\tR\x02id\x12\x14\n\x04name\x18\x02\x20\x01(\tH\0R\x04n\ \x18\x01\x20\x01(\tR\x02id\x12\x14\n\x04name\x18\x02\x20\x01(\tH\0R\x04n\
ame\x12\x14\n\x04desc\x18\x03\x20\x01(\tH\x01R\x04desc\x12\x1a\n\x07cont\ ame\x12\x14\n\x04desc\x18\x03\x20\x01(\tH\x01R\x04desc\x12\x14\n\x04text\
ent\x18\x04\x20\x01(\tH\x02R\x07contentB\r\n\x0bone_of_nameB\r\n\x0bone_\ \x18\x04\x20\x01(\tH\x02R\x04textB\r\n\x0bone_of_nameB\r\n\x0bone_of_des\
of_descB\x10\n\x0eone_of_contentJ\xd7\x02\n\x06\x12\x04\0\0\x07\x01\n\ cB\r\n\x0bone_of_textJ\xd7\x02\n\x06\x12\x04\0\0\x07\x01\n\x08\n\x01\x0c\
\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x07\x01\n\n\ \x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x07\x01\n\n\n\x03\x04\0\
\n\x03\x04\0\x01\x12\x03\x02\x08\x18\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\ \x01\x12\x03\x02\x08\x18\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x12\n\
\x04\x12\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\ \x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\
\x02\0\x01\x12\x03\x03\x0b\r\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x10\ \x12\x03\x03\x0b\r\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x10\x11\n\x0b\
\x11\n\x0b\n\x04\x04\0\x08\0\x12\x03\x04\x04*\n\x0c\n\x05\x04\0\x08\0\ \n\x04\x04\0\x08\0\x12\x03\x04\x04*\n\x0c\n\x05\x04\0\x08\0\x01\x12\x03\
\x01\x12\x03\x04\n\x15\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x18(\n\x0c\ \x04\n\x15\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x18(\n\x0c\n\x05\x04\0\
\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x18\x1e\n\x0c\n\x05\x04\0\x02\x01\ \x02\x01\x05\x12\x03\x04\x18\x1e\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\
\x01\x12\x03\x04\x1f#\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04&'\n\x0b\ \x04\x1f#\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04&'\n\x0b\n\x04\x04\0\
\n\x04\x04\0\x08\x01\x12\x03\x05\x04*\n\x0c\n\x05\x04\0\x08\x01\x01\x12\ \x08\x01\x12\x03\x05\x04*\n\x0c\n\x05\x04\0\x08\x01\x01\x12\x03\x05\n\
\x03\x05\n\x15\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x18(\n\x0c\n\x05\ \x15\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x18(\n\x0c\n\x05\x04\0\x02\
\x04\0\x02\x02\x05\x12\x03\x05\x18\x1e\n\x0c\n\x05\x04\0\x02\x02\x01\x12\ \x02\x05\x12\x03\x05\x18\x1e\n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x05\
\x03\x05\x1f#\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05&'\n\x0b\n\x04\ \x1f#\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05&'\n\x0b\n\x04\x04\0\x08\
\x04\0\x08\x02\x12\x03\x06\x040\n\x0c\n\x05\x04\0\x08\x02\x01\x12\x03\ \x02\x12\x03\x06\x04*\n\x0c\n\x05\x04\0\x08\x02\x01\x12\x03\x06\n\x15\n\
\x06\n\x18\n\x0b\n\x04\x04\0\x02\x03\x12\x03\x06\x1b.\n\x0c\n\x05\x04\0\ \x0b\n\x04\x04\0\x02\x03\x12\x03\x06\x18(\n\x0c\n\x05\x04\0\x02\x03\x05\
\x02\x03\x05\x12\x03\x06\x1b!\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x06\ \x12\x03\x06\x18\x1e\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x06\x1f#\n\
\")\n\x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x06,-b\x06proto3\ \x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x06&'b\x06proto3\
"; ";
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

View File

@ -4,6 +4,7 @@ message CreateDocRequest {
string id = 1; string id = 1;
string name = 2; string name = 2;
string desc = 3; string desc = 3;
string text = 4;
} }
message DocDescription { message DocDescription {
string id = 1; string id = 1;
@ -13,5 +14,5 @@ message DocDescription {
} }
message Doc { message Doc {
DocDescription desc = 1; DocDescription desc = 1;
string content = 2; string text = 2;
} }

View File

@ -4,5 +4,5 @@ message UpdateDocRequest {
string id = 1; string id = 1;
oneof one_of_name { string name = 2; }; oneof one_of_name { string name = 2; };
oneof one_of_desc { string desc = 3; }; oneof one_of_desc { string desc = 3; };
oneof one_of_content { string content = 4; }; oneof one_of_text { string text = 4; };
} }

View File

@ -70,8 +70,12 @@ impl FileManager {
} }
} }
pub(crate) fn make_file_path(&self, id: &str) -> PathBuf { pub(crate) fn create_file(&mut self, id: &str, text: &str) -> PathBuf {
PathBuf::from(format!("{}/{}", self.config.doc_dir, id)) let path = PathBuf::from(format!("{}/{}", self.config.doc_dir, id));
let file_id: FileId = id.to_owned().into();
log::info!("Create doc at: {:?}", path);
self.save_new(&path, text, &file_id);
path
} }
pub(crate) fn get_info(&self, id: &FileId) -> Option<&FileInfo> { self.file_info.get(id) } pub(crate) fn get_info(&self, id: &FileId) -> Option<&FileInfo> { self.file_info.get(id) }
@ -91,7 +95,7 @@ impl FileManager {
false false
} }
fn save_new(&mut self, path: &Path, text: &String, id: &FileId) -> Result<(), FileError> { fn save_new(&mut self, path: &Path, text: &str, id: &FileId) -> Result<(), FileError> {
try_save(path, text, CharacterEncoding::Utf8, self.get_info(id)) try_save(path, text, CharacterEncoding::Utf8, self.get_info(id))
.map_err(|e| FileError::Io(e, path.to_owned()))?; .map_err(|e| FileError::Io(e, path.to_owned()))?;
let info = FileInfo { let info = FileInfo {

View File

@ -2,17 +2,21 @@ use crate::helper::*;
#[test] #[test]
fn file_create_test() { fn file_create_test() {
let doc_desc = create_doc("hello world", "flutter ❤️ rust"); let doc_desc = create_doc("hello world", "flutter ❤️ rust", "123");
dbg!(&doc_desc); dbg!(&doc_desc);
let doc = read_doc(&doc_desc.id);
assert_eq!(doc.text, "123".to_owned());
} }
#[test] #[test]
fn file_save_test() { fn file_update_text_test() {
let content = "😁😁😁😁😁😁😁😁😁😁".to_owned(); let doc_desc = create_doc("hello world", "flutter ❤️ rust", "");
let doc_desc = create_doc("hello world", "flutter ❤️ rust");
dbg!(&doc_desc); dbg!(&doc_desc);
let content = "😁😁😁😁😁😁😁😁😁😁".to_owned();
save_doc(&doc_desc, &content); save_doc(&doc_desc, &content);
let doc = read_doc(&doc_desc.id); let doc = read_doc(&doc_desc.id);
assert_eq!(doc.content, content); assert_eq!(doc.text, content);
} }

View File

@ -3,11 +3,12 @@ use flowy_test::builder::SingleUserTestBuilder;
use flowy_editor::{entities::doc::*, event::EditorEvent::*}; use flowy_editor::{entities::doc::*, event::EditorEvent::*};
use flowy_infra::uuid; use flowy_infra::uuid;
pub fn create_doc(name: &str, desc: &str) -> DocDescription { pub fn create_doc(name: &str, desc: &str, text: &str) -> DocDescription {
let request = CreateDocRequest { let request = CreateDocRequest {
id: uuid(), id: uuid(),
name: name.to_owned(), name: name.to_owned(),
desc: desc.to_owned(), desc: desc.to_owned(),
text: text.to_owned(),
}; };
let doc_desc = SingleUserTestBuilder::new() let doc_desc = SingleUserTestBuilder::new()
@ -24,7 +25,7 @@ pub fn save_doc(desc: &DocDescription, content: &str) {
id: desc.id.clone(), id: desc.id.clone(),
name: Some(desc.name.clone()), name: Some(desc.name.clone()),
desc: Some(desc.desc.clone()), desc: Some(desc.desc.clone()),
content: Some(content.to_owned()), text: Some(content.to_owned()),
}; };
let _ = SingleUserTestBuilder::new() let _ = SingleUserTestBuilder::new()

View File

@ -114,6 +114,10 @@ pub fn ast_to_event_render_ctx(ast: &Vec<EventASTContext>) -> Vec<EventRenderCon
Some(ref event_output) => Some(event_output.get_ident().unwrap().to_string()), Some(ref event_output) => Some(event_output.get_ident().unwrap().to_string()),
None => None, None => None,
}; };
// eprintln!(
// "😁 {:?} / {:?}",
// event_ast.event_input, event_ast.event_output
// );
return EventRenderContext { return EventRenderContext {
input_deserializer, input_deserializer,

View File

@ -44,8 +44,14 @@ impl EventTemplate {
Some(ref input) => self.tera_context.insert("input_deserializer", input), Some(ref input) => self.tera_context.insert("input_deserializer", input),
} }
self.tera_context // eprintln!(
.insert("has_output", &ctx.output_deserializer.is_some()); // "😁 {:?} / {:?}",
// &ctx.input_deserializer, &ctx.output_deserializer
// );
let has_output = ctx.output_deserializer.is_some();
self.tera_context.insert("has_output", &has_output);
match ctx.output_deserializer { match ctx.output_deserializer {
None => self.tera_context.insert("output_deserializer", "Unit"), None => self.tera_context.insert("output_deserializer", "Unit"),
Some(ref output) => self.tera_context.insert("output_deserializer", output), Some(ref output) => self.tera_context.insert("output_deserializer", output),

View File

@ -19,8 +19,13 @@ class {{ event_class }} {
return Dispatch.asyncRequest(request) return Dispatch.asyncRequest(request)
.then((bytesResult) => bytesResult.fold( .then((bytesResult) => bytesResult.fold(
(okBytes) => left({{ output_deserializer }}.fromBuffer(okBytes)),
(errBytes) => right({{ error_deserializer }}.fromBuffer(errBytes)), {%- if has_output %}
(okBytes) => left({{ output_deserializer }}.fromBuffer(okBytes)),
{%- else %}
(bytes) => left(unit),
{%- endif %}
(errBytes) => right({{ error_deserializer }}.fromBuffer(errBytes)),
)); ));
{%- else %} {%- else %}