Browse Source

neon: Fix updating note

pull/34/head
jld3103 2 years ago
parent
commit
7182fe65bc
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 14
      packages/neon/lib/src/apps/notes/blocs/notes.dart
  2. 16
      packages/neon/lib/src/apps/notes/blocs/notes.rxb.g.dart
  3. 4
      packages/neon/lib/src/apps/notes/pages/note.dart
  4. 4
      packages/neon/lib/src/apps/notes/widgets/notes_view.dart

14
packages/neon/lib/src/apps/notes/blocs/notes.dart

@ -12,11 +12,7 @@ abstract class NotesBlocEvents {
void createNote(final NotesNote note); void createNote(final NotesNote note);
void updateNote( void updateNote(final NotesNote note);
final int id,
final String etag,
final NotesNote note,
);
void deleteNote(final NotesNote note); void deleteNote(final NotesNote note);
} }
@ -42,13 +38,13 @@ class NotesBloc extends $NotesBloc {
_wrapAction(() async => client.notes.createNote(note)); _wrapAction(() async => client.notes.createNote(note));
}); });
_$updateNoteEvent.listen((final event) { _$updateNoteEvent.listen((final note) {
_wrapAction( _wrapAction(
() async => _noteUpdateController.add( () async => _noteUpdateController.add(
(await client.notes.updateNote( (await client.notes.updateNote(
event.id, note.id!,
event.note, note,
ifMatch: '"${event.etag}"', ifMatch: '"${note.etag}"',
))!, ))!,
), ),
); );

16
packages/neon/lib/src/apps/notes/blocs/notes.rxb.g.dart

@ -25,7 +25,7 @@ abstract class $NotesBloc extends RxBlocBase implements NotesBlocEvents, NotesBl
final _$createNoteEvent = PublishSubject<NotesNote>(); final _$createNoteEvent = PublishSubject<NotesNote>();
/// Тhe [Subject] where events sink to by calling [updateNote] /// Тhe [Subject] where events sink to by calling [updateNote]
final _$updateNoteEvent = PublishSubject<_UpdateNoteEventArgs>(); final _$updateNoteEvent = PublishSubject<NotesNote>();
/// Тhe [Subject] where events sink to by calling [deleteNote] /// Тhe [Subject] where events sink to by calling [deleteNote]
final _$deleteNoteEvent = PublishSubject<NotesNote>(); final _$deleteNoteEvent = PublishSubject<NotesNote>();
@ -46,7 +46,7 @@ abstract class $NotesBloc extends RxBlocBase implements NotesBlocEvents, NotesBl
void createNote(NotesNote note) => _$createNoteEvent.add(note); void createNote(NotesNote note) => _$createNoteEvent.add(note);
@override @override
void updateNote(int id, String etag, NotesNote note) => _$updateNoteEvent.add(_UpdateNoteEventArgs(id, etag, note)); void updateNote(NotesNote note) => _$updateNoteEvent.add(note);
@override @override
void deleteNote(NotesNote note) => _$deleteNoteEvent.add(note); void deleteNote(NotesNote note) => _$deleteNoteEvent.add(note);
@ -82,15 +82,3 @@ abstract class $NotesBloc extends RxBlocBase implements NotesBlocEvents, NotesBl
super.dispose(); super.dispose();
} }
} }
/// Helps providing the arguments in the [Subject.add] for
/// [NotesBlocEvents.updateNote] event
class _UpdateNoteEventArgs {
const _UpdateNoteEventArgs(this.id, this.etag, this.note);
final int id;
final String etag;
final NotesNote note;
}

4
packages/neon/lib/src/apps/notes/pages/note.dart

@ -36,9 +36,9 @@ class _NotesNotePageState extends State<NotesNotePage> {
if (updatedTitle != null || updatedCategory != null || updatedContent != null) { if (updatedTitle != null || updatedCategory != null || updatedContent != null) {
widget.bloc.updateNote( widget.bloc.updateNote(
_note.id!,
_note.etag!,
NotesNote( NotesNote(
id: _note.id!,
etag: _note.etag!,
title: updatedTitle, title: updatedTitle,
category: updatedCategory, category: updatedCategory,
content: updatedContent, content: updatedContent,

4
packages/neon/lib/src/apps/notes/widgets/notes_view.dart

@ -132,9 +132,9 @@ class NotesView extends StatelessWidget {
), ),
onPressed: () { onPressed: () {
bloc.updateNote( bloc.updateNote(
note.id!,
note.etag!,
NotesNote( NotesNote(
id: note.id!,
etag: note.etag!,
favorite: !note.favorite!, favorite: !note.favorite!,
), ),
); );

Loading…
Cancel
Save