diff --git a/packages/neon/lib/src/apps/notes/blocs/note.dart b/packages/neon/lib/src/apps/notes/blocs/note.dart index 66f680cb..dbc75c41 100644 --- a/packages/neon/lib/src/apps/notes/blocs/note.dart +++ b/packages/neon/lib/src/apps/notes/blocs/note.dart @@ -19,10 +19,6 @@ abstract class NotesNoteBlocEvents { } abstract class NotesNoteBlocStates { - BehaviorSubject get content; - - BehaviorSubject get title; - BehaviorSubject get category; Stream get errors; @@ -67,10 +63,10 @@ class NotesNoteBloc extends $NotesNoteBloc { ); }); - _contentSubject.add(note.content); - _titleSubject.add(note.title); _emitNote(note); id = note.id; + initialContent = note.content; + initialTitle = note.title; } void _emitNote(final NotesNote note) { @@ -96,30 +92,22 @@ class NotesNoteBloc extends $NotesNoteBloc { final _updateQueue = Queue(); late final int id; + late final String initialContent; + late final String initialTitle; late String _etag; - final _contentSubject = BehaviorSubject(); - final _titleSubject = BehaviorSubject(); final _categorySubject = BehaviorSubject(); final _errorsStreamController = StreamController(); @override void dispose() { - unawaited(_contentSubject.close()); - unawaited(_titleSubject.close()); unawaited(_categorySubject.close()); unawaited(_errorsStreamController.close()); super.dispose(); } @override - Stream _mapToErrorsState() => _errorsStreamController.stream.asBroadcastStream(); - - @override - BehaviorSubject _mapToContentState() => _contentSubject; - - @override - BehaviorSubject _mapToTitleState() => _titleSubject; + BehaviorSubject _mapToCategoryState() => _categorySubject; @override - BehaviorSubject _mapToCategoryState() => _categorySubject; + Stream _mapToErrorsState() => _errorsStreamController.stream.asBroadcastStream(); } diff --git a/packages/neon/lib/src/apps/notes/blocs/note.rxb.g.dart b/packages/neon/lib/src/apps/notes/blocs/note.rxb.g.dart index c8cb7bb2..e6997dbb 100644 --- a/packages/neon/lib/src/apps/notes/blocs/note.rxb.g.dart +++ b/packages/neon/lib/src/apps/notes/blocs/note.rxb.g.dart @@ -28,12 +28,6 @@ abstract class $NotesNoteBloc extends RxBlocBase /// Тhe [Subject] where events sink to by calling [updateCategory] final _$updateCategoryEvent = PublishSubject(); - /// The state of [content] implemented in [_mapToContentState] - late final BehaviorSubject _contentState = _mapToContentState(); - - /// The state of [title] implemented in [_mapToTitleState] - late final BehaviorSubject _titleState = _mapToTitleState(); - /// The state of [category] implemented in [_mapToCategoryState] late final BehaviorSubject _categoryState = _mapToCategoryState(); @@ -49,22 +43,12 @@ abstract class $NotesNoteBloc extends RxBlocBase @override void updateCategory(String category) => _$updateCategoryEvent.add(category); - @override - BehaviorSubject get content => _contentState; - - @override - BehaviorSubject get title => _titleState; - @override BehaviorSubject get category => _categoryState; @override Stream get errors => _errorsState; - BehaviorSubject _mapToContentState(); - - BehaviorSubject _mapToTitleState(); - BehaviorSubject _mapToCategoryState(); Stream _mapToErrorsState(); diff --git a/packages/neon/lib/src/apps/notes/pages/note.dart b/packages/neon/lib/src/apps/notes/pages/note.dart index 31e621a5..37665a16 100644 --- a/packages/neon/lib/src/apps/notes/pages/note.dart +++ b/packages/neon/lib/src/apps/notes/pages/note.dart @@ -15,8 +15,8 @@ class NotesNotePage extends StatefulWidget { } class _NotesNotePageState extends State { - late final _contentController = TextEditingController(); - late final _titleController = TextEditingController(); + late final _contentController = TextEditingController()..text = widget.bloc.initialContent; + late final _titleController = TextEditingController()..text = widget.bloc.initialTitle; final _contentFocusNode = FocusNode(); final _titleFocusNode = FocusNode(); bool _showEditor = false; @@ -34,41 +34,15 @@ class _NotesNotePageState extends State { handleNotesException(context, error); }); - widget.bloc.content.listen((final content) { - if (_contentController.text != content) { - final selection = _contentController.selection; - _contentController - ..text = content - ..selection = selection; - } - }); - - widget.bloc.title.listen((final title) { - if (_titleController.text != title) { - final selection = _titleController.selection; - _titleController - ..text = title - ..selection = selection; - } - }); - - _contentController.addListener(() async { - if (await widget.bloc.content.first != _contentController.text) { - widget.bloc.updateContent(_contentController.text); - } - }); - _titleController.addListener(() async { - if (await widget.bloc.title.first != _titleController.text) { - widget.bloc.updateTitle(_titleController.text); - } - }); + _contentController.addListener(() => widget.bloc.updateContent(_contentController.text)); + _titleController.addListener(() => widget.bloc.updateTitle(_titleController.text)); WidgetsBinding.instance.addPostFrameCallback((final _) async { if (Provider.of(context, listen: false).canUseWakelock) { await Wakelock.enable(); } if (widget.bloc.options.defaultNoteViewTypeOption.value == DefaultNoteViewType.edit || - (await widget.bloc.content.first).isEmpty) { + widget.bloc.initialContent.isEmpty) { setState(() { _showEditor = true; }); @@ -171,22 +145,15 @@ class _NotesNotePageState extends State { border: InputBorder.none, ), ) - : RxBlocBuilder( - bloc: widget.bloc, - state: (final bloc) => bloc.content, - builder: (final context, final contentSnapshot, final _) { - final content = contentSnapshot.data ?? ''; - return MarkdownBody( - data: content, - onTapLink: (final text, final href, final title) async { - if (href != null) { - await launchUrlString( - href, - mode: LaunchMode.externalApplication, - ); - } - }, - ); + : MarkdownBody( + data: _contentController.text, + onTapLink: (final text, final href, final title) async { + if (href != null) { + await launchUrlString( + href, + mode: LaunchMode.externalApplication, + ); + } }, ), ),